Recent

Author Topic: Object method bug  (Read 2557 times)

lennit

  • Jr. Member
  • **
  • Posts: 63
  • Aquila non capit muscas.
Object method bug
« on: July 29, 2015, 05:39:07 pm »
Hello,

I'm using objects in my project to perform some specific tasks needed. I have several of them, declared in a similar way with no visible mistakes at least for me. But at 3 of those objects I get an error while compiling:
unit1.pas(2895,21) Error: overloaded identifier "chkrelaypv" isn't a function
unit1.pas(2895,21) Error: function header doesn't match any method of this class  freshairs.chkrelaypv$2895(var LongInt);"



Code: [Select]

heatingup=object
    openIP,openOID,closeIP,closeOID:string;
    openhe:procedure(var heati:integer);
    closehe:procedure(var heati:integer);
    chkrelayhe:procedure(var heati:integer);
  end;   

  heater:array[1..11] of heatingup;
  heatcount:array[1..11] of integer;
  heatres:array[1..11] of string;   

procedure heatingup.openhe(var heati:integer);
begin
 if SNMPGet(heater[heati].closeOID, 'public', heater[heati].closeIP, heatres[heati]) then
    if heatres[heati] = '1' then
    begin
      if SNMPSet(heater[heati].closeOID, 'private', heater[heati].closeIP, '0', 2) then
         heatled[heati,2].color:=clGreen else heatled[heati,2].color:=clLime;
      end;
 if SNMPGet(heater[heati].openOID, 'public', heater[heati].openIP, heatres[heati]) then
    if heatres[heati] = '0' then
    begin
      if SNMPSet(heater[heati].openOID, 'private', heater[heati].openIP, '0', 2) then
         heatled[heati,1].color:=clLime else heatled[heati,1].color:=clGreen;
      end;
end;

procedure heatingup.closehe(var heati:integer);
begin
 if SNMPGet(heater[heati].openOID, 'public', heater[heati].openIP, heatres[heati]) then
    if heatres[heati] = '1' then
    begin
      if SNMPSet(heater[heati].openOID, 'private', heater[heati].openIP, '0', 2) then
         heatled[heati,1].color:=clGreen else heatled[heati,1].color:=clLIme;
      end;
 if SNMPGet(heater[heati].closeOID, 'public', heater[heati].closeIP, heatres[heati]) then
    if heatres[heati] = '0' then
    begin
      if SNMPSet(heater[heati].closeOID, 'private', heater[heati].closeIP, '0', 2) then
         heatled[heati,2].color:=clLime else heatled[heati,2].color:=clGreen;
      end;
end;

procedure heatingup.chkrelayhe(var heati:integer);
begin
 if SNMPGet(heater[heati].openOID, 'public', heater[heati].openIP, heatres[heati]) then
    if heatres[heati] = '1' then heatled[heati,1].color:=clLime else heatled[heati,1].color:=clGreen;

 if SNMPGet(heater[heati].closeOID, 'public', heater[heati].closeIP, heatres[heati]) then
    if heatres[heati] = '1' then heatled[heati,2].color:=clLime else heatled[heati,2].color:=clGreen;

end;
                     

I get the error on the line with the procedure header. I have checked for variables with the same name as one of the procedures but there is nothing present at the moment. There was one in an older version of the project and the project has got "cleansed" many times after that. Is there a mistake in my code or what am I supposed to do to make it work?



This is more or
Win 7 32/64
Win 10 64bit
Lazarus 1.4.4
Firebird 2.5.3 (x64)

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Object method bug
« Reply #1 on: July 29, 2015, 05:52:42 pm »
Code: [Select]
  heatingup=object
    openIP, openOID, closeIP, closeOID : string;
    procedure openhe      (var heati:integer);//<--| var why? I would use const instead to be able to pass a property as well as any value.
    procedure closehe      (var heati:integer);
    procedure chkrelayhe (var heati:integer);
  end;   
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

yamer

  • Jr. Member
  • **
  • Posts: 87
Re: Object method bug
« Reply #2 on: July 29, 2015, 06:05:18 pm »
I think your object declaration is wrong.

Try this:
Code: [Select]
heatingup=object
    openIP,openOID,closeIP,closeOID:string;
    procedure openhe(var heati:integer);
    procedure closehe(var heati:integer);
    procedure chkrelayhe(var heati:integer);
end;   

lennit

  • Jr. Member
  • **
  • Posts: 63
  • Aquila non capit muscas.
Re: Object method bug
« Reply #3 on: July 30, 2015, 07:51:45 am »
Thank you so much! I can't imagine how blind (or dead tired) I must have been not to see that the procedures in the "working" and "not working" objects are declared in a different way  :-[
Win 7 32/64
Win 10 64bit
Lazarus 1.4.4
Firebird 2.5.3 (x64)

 

TinyPortal © 2005-2018