Need brakets to call a function without parameters? lazarus / 9-Editor ---------------------------------------------------------------------- DimProfi · 2006-12-14 23:37 I found a new funny thing in syntax. if i write something like this: " TXObject=class    function execute:boolean    procedure action1; end; ... procedure TXObject.action1; begin   execute; end;  ... " It doesn't call a method "execute". It works only if i write "execute()" is it new or a bug? It's no a good idea cause of compatibility to pascal. ---------------------------------------------------------------------- felipemdc · 2006-12-15 00:35 > It works only if i write "execute()" is it new or a bug? That´s because Free Pascal supports 6 different pascal dialects. The default one is called objfpc and is more strict then delphi dialect, so it demands (). It´s not a bug, but a rule from the dialect. If you want the more loose delphi dialect, just add: {$mode delphi} to the beginning of your unit. Just to note, the other dialects are: turbo pascal, macintosh pascal, and I think there are still some others I don´t remember. ---------------------------------------------------------------------- felipemdc · 2006-12-15 00:36 PS: I removed the duplicated thread. No reason to cross-post. ---------------------------------------------------------------------- Vincent Snijders · 2006-12-15 09:20 That must a very local funny thing. The following code compiles without error.  So there must be another reason, why the compilation fails (another identifier named execute?). Code: [Select] program Project1; {$mode objfpc}{$H+} uses   Classes, SysUtils   { add your units here }; type { TXObject } TXObject=class function execute:boolean; procedure action1; end; { TXObject } function TXObject.execute: boolean; begin   writeln('Test');   readln; end; procedure TXObject.action1; begin   Execute; end; begin   TXObject.Create.Action1; end. ---------------------------------------------------------------------- DimProfi · 2006-12-15 15:20 if i write "execute;" I DON'T get a compiler-error! Just in the running programm this line doesn't works like calling function. It happens nothing! Compiler interprets "execute" like just Variable without operations. Compiler interprets "execute()" like a call of function "execute". My problem is the wrong interpretation of my code "execute". ---------------------------------------------------------------------- Vincent Snijders · 2006-12-15 15:23 My program stopped at the readln, so it did actually go to the execute method. ---------------------------------------------------------------------- DimProfi · 2006-12-15 15:23 I forgot to say that the "execute" method is in parent a class. May is something wrong in interpreting of calling of inherrited methods? ---------------------------------------------------------------------- Vincent Snijders · 2006-12-15 15:24 It could be that you are overlooking something and we don't see it because you don't post enough code. ---------------------------------------------------------------------- DimProfi · 2006-12-15 15:27 I will make the whole Test-Code and if it works in the same funny way i will post it. Thanks for your fast feedback. The people of lazarus-project are making a greate job. Thanks to all developers. ---------------------------------------------------------------------- DimProfi · 2006-12-15 15:54 I have constructed a new code and it works with the same bug! Check this out! See a line "// Bug??" - if u write "execute" it doesn't call Protoobj1.execute ------------------------------------------- unit Unit1; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs,   protoobj2, Buttons; type   { TForm1 }   TForm1 = class(TForm)     Button1: TButton;     procedure Button1Click(Sender: TObject);   private     { private declarations }   public     lt:TProtoObj2;     { public declarations }   end; var   Form1: TForm1; implementation { TForm1 } procedure TForm1.Button1Click(Sender: TObject); begin   lt:=TProtoObj2.Create('c:\xp.x');   showmessage('Form1:'+lt.execute('xp'));   lt.free; end; initialization   {$I unit1.lrs} end. --------------------------------------- unit protoobj2; {$mode objfpc}{$H+} interface uses   Classes, SysUtils,dialogs; type   TProtoObj1=class     public       constructor Create(filename:string);       destructor Free;       function execute:string;   end;   TProtoObj2=class(TProtoObj1)     function execute(objtype:string):string; overload;   end;     implementation constructor TProtoObj1.Create(filename:string); begin end; destructor TProtoObj1.Free; begin end; function TProtoObj1.execute:string; begin   result:='result1'; end; function TProtoObj2.execute(objtype:string):string; begin   // Bug???   Result:=execute();   //Result:=execute;   showmessage('Protoobj2:'+result); end; end. ------------------------------------------- ---------------------------------------------------------------------- Vincent Snijders · 2006-12-15 20:51 Thanks for the code example. It could reproduce the behavior and thought about a compiler bug first too. But it is not. If you use Code: [Select] Result:=execute(); you are calling the execute method (as you expect). If you use Code: [Select] Result:=execute; execute is not calling the execute method, but accessing the result variable, which has the same name as the function name. So you are doing there effectively Code: [Select]Result := Result;. ---------------------------------------------------------------------- Vincent Snijders · 2006-12-15 20:55 I think this doesn't happen if you compile your code with {$mode delphi}. ---------------------------------------------------------------------- DimProfi · 2006-12-15 21:50 You are right Code: [Select] {$mode delphi} helps! Thanks one more time.