Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2007-06

Assigning a result of a method reference

5 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Joao Morais

Hello,

Taking the following code:

{$mode objfpc}{$h+}
class function tfoo.classmetadata: string;
var
   vmetadatamethod: function: string of object;
begin
   vmetadatamethod := @internalmetadatastr;
   // more code
   Result := vmetadatamethod;
end;

the last assignment doesn't compile, the compiler complains that:

Error: Incompatible types: got "<procedure variable type of function:AnsiString of object;Register>" expected "AnsiString"

Current 2.2 fixes branch.

If I remove the at operator, this code compiles under $mode delphi.

What can I do to make it work under objfpc?

Thanks.

Joao Morais

Reply by email

Michael Van Canneyt
to Joao Morais
Joao Morais wrote 19 lines
Hello, Taking the following code: {$mode objfpc}{$h+} class function tfoo.classmetadata: string; var vmetadatamethod: function: string of object; begin vmetadatamethod := @internalmetadatastr; // more code Result := vmetadatamethod; end; the last assignment doesn't compile, the compiler complains that: Error: Incompatible types: got "<procedure variable type of function:AnsiString of object;Register>" expected "AnsiString"
Try
  Result := vmetadatamethod();

Strange code you have, Your code does not even compile under Delphi...

Michael.

Reply by email

Joao Morais
to Michael Van Canneyt
Michael Van Canneyt wrote 25 lines
On Sat, 23 Jun 2007, Joao Morais wrote: > Hello, > > Taking the following code: > > {$mode objfpc}{$h+} > class function tfoo.classmetadata: string; > var > vmetadatamethod: function: string of object; > begin > vmetadatamethod := @internalmetadatastr; > // more code > Result := vmetadatamethod; > end; > > the last assignment doesn't compile, the compiler complains that: > > Error: Incompatible types: got "<procedure variable type of > function:AnsiString of object;Register>" expected "AnsiString" Try Result := vmetadatamethod();

Nice idea, now it works. =) Thanks.

Strange code you have,

An useful abstraction to ensure that an specific class implements an specific virtual method. If it doesn't implement, I need an empty string instead of the inherited value.

Your code does not even compile under Delphi...

It compiles and works since (at least) D5 and under fpc's $mode delphi. In this case, the need of the brackets under objfpc can be considered a bug? Should I file a bug report?

Joao Morais

Reply by email

Michael Van Canneyt
to Joao Morais
Joao Morais wrote 40 lines
Michael Van Canneyt wrote: > > On Sat, 23 Jun 2007, Joao Morais wrote: > > > Hello, > > > > Taking the following code: > > > > {$mode objfpc}{$h+} > > class function tfoo.classmetadata: string; > > var > > vmetadatamethod: function: string of object; > > begin > > vmetadatamethod := @internalmetadatastr; > > // more code > > Result := vmetadatamethod; > > end; > > > > the last assignment doesn't compile, the compiler complains that: > > > > Error: Incompatible types: got "<procedure variable type of > > function:AnsiString of object;Register>" expected "AnsiString" > > Try > > Result := vmetadatamethod(); Nice idea, now it works. =) Thanks. > Strange code you have, An useful abstraction to ensure that an specific class implements an specific virtual method. If it doesn't implement, I need an empty string instead of the inherited value. > Your code does not even compile under Delphi... It compiles and works since (at least) D5 and under fpc's $mode delphi. In this case, the need of the brackets under objfpc can be considered a bug? Should I file a bug report?

No, it is normal in objfpc mode.

Michael.

Reply by email

Joao Morais
to Michael Van Canneyt
Michael Van Canneyt wrote 22 lines
On Sat, 23 Jun 2007, Joao Morais wrote: > Michael Van Canneyt wrote: >> On Sat, 23 Jun 2007, Joao Morais wrote: >> >>> Result := vmetadatamethod; >>> end; >>> >>> the last assignment doesn't compile, the compiler complains that: >>> >>> Error: Incompatible types: got "<procedure variable type of >>> function:AnsiString of object;Register>" expected "AnsiString" >> Try >> >> Result := vmetadatamethod(); >> Your code does not even compile under Delphi... > It compiles and works since (at least) D5 and under fpc's $mode delphi. In > this case, the need of the brackets under objfpc can be considered a bug? > Should I file a bug report? No, it is normal in objfpc mode.

Don't get me wrong but... sure? Afaics the compiler doesn't need to see the brackets to understand what I mean, so this one sounds a C convention to me.

Thanks.

Joao Morais

Reply by email