Sign in Join

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

Mailing lists / fpc-pascal / 2012-07

Variable of class method type of function

9 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

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

CA Gorski

How to declare a variable of class method type of function?

...
var

     MyVar: function(AParam: string): boolean of class;

...
gives an error using FPC 2.6.1 (Win64).

Reply by email

Jonas Maebe
to CA Gorski
CA Gorski wrote 7 lines
How to declare a variable of class method type of function? ... var MyVar: function(AParam: string): boolean of class; ... gives an error using FPC 2.6.1 (Win64).

You have to use "of object", just like for a regular method.

Jonas

Reply by email

CA Gorski
to Jonas Maebe

But then I get the following error trying to use the variable:

Error: Incompatible types: got "<class method type of function(AnsiString):Boolean of object;Register>" expected "<procedure variable type of function(AnsiString):Boolean of object;Register>"

Jonas Maebe wrote 17 lines
On 15 Jul 2012, at 14:05, CA Gorski wrote: > How to declare a variable of class method type of function? > > ... > var > MyVar: function(AParam: string): boolean of class; > ... > gives an error using FPC 2.6.1 (Win64). You have to use "of object", just like for a regular method. Jonas _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Jonas Maebe
to CA Gorski
CA Gorski wrote
But then I get the following error trying to use the variable: Error: Incompatible types: got "<class method type of function(AnsiString):Boolean of object;Register>" expected "<procedure variable type of function(AnsiString):Boolean of object;Register>"

That seems to be a bug in ObjFPC mode procvar support. It works in Delphi mode. Please always include a complete test program in the future, so that people wanting to help you don't have to write multiple test programs themselves to figure out what the code you were using might look like.

Jonas

Reply by email

CA Gorski
to Jonas Maebe
Jonas Maebe wrote
That seems to be a bug in ObjFPC mode procvar support. It works in Delphi mode. Please always include a complete test program in the future, so that people wanting to help you don't have to write multiple test programs themselves to figure out what the code you were using might look like.

Ok! Anything to do for me now, like reporting the bug somewhere? Or might it be already solved in 2.7 so that updating would help? Thanks for your effort!

Reply by email

Jonas Maebe
to CA Gorski
CA Gorski wrote 5 lines
On 15.07.2012 15:35, Jonas Maebe wrote: > That seems to be a bug in ObjFPC mode procvar support. It works in Delphi mode. Please always include a complete test program in the future, so that people wanting to help you don't have to write multiple test programs themselves to figure out what the code you were using might look like. Ok! Anything to do for me now, like reporting the bug somewhere?

Yes, you can report a bug at http://bugs.freepascal.org (with a complete program).

Or might it be already solved in 2.7 so that updating would help?

It's not yet fixed in 2.7

Jonas

Reply by email

waldo kitty
to Jonas Maebe: You have to use "of object", just like for a regular method. Jonas
Jonas Maebe wrote 11 lines
On 15 Jul 2012, at 14:05, CA Gorski wrote: > How to declare a variable of class method type of function? > > ... > var > MyVar: function(AParam: string): boolean of class; > ... > gives an error using FPC 2.6.1 (Win64). You have to use "of object", just like for a regular method.

pardon my intrusion but i'm looking for clarification...

in the beginning we had objects... then classes came along and they were the "new object" as objects should have been written to start with (parroting)... so now we need to remember to use "of object" when we are working with nothing but classes?

i hope that is sufficiently "bikini style"* ;)

[* "bikini style: short and to the point]

Reply by email

Sven Barth
to waldo kitty
"waldo kitty" wrote 20 lines
On 7/15/2012 08:13, Jonas Maebe wrote: > > On 15 Jul 2012, at 14:05, CA Gorski wrote: > >> How to declare a variable of class method type of function? >> >> ... >> var >> MyVar: function(AParam: string): boolean of class; >> ... >> gives an error using FPC 2.6.1 (Win64). > > > You have to use "of object", just like for a regular method. pardon my intrusion but i'm looking for clarification... in the beginning we had objects... then classes came along and they were

the "new object" as objects should have been written to start with (parroting)... so now we need to remember to use "of object" when we are working with nothing but classes?

Ask Borland why they decided to use "of object" instead of "of class". It's nevertheless now part of Pascal's heritage.

Regards,
Sven

Reply by email

Bernd K.
to waldo kitty: pardon my intrusion but i'm looking for clarification... in the beginning we had…
waldo kitty wrote
now we need to remember to use "of object" when we are working with nothing but classes?

Imagine for a moment (in a parallel universe) there exists no keyword "object" and never has. All there has ever been was the keyword "class".

now you have

type
  TFoo = class
  end;
var
  Foo : TFoo;
  Bar : TFoo;
begin
  Foo := TFoo.Create;
  Bar := TFoo.Create;

TFoo is a class
Foo and Bar are objects

They are objects in the original OOP sense of the word without having to worry about any other conflicting meaning of the word "object" and then it makes perfect sense.

IMHO it was the old keyword "object" that was confusing and misplaced from the beginning on, it should have never existed. If there are two categories: "data" and "structure of data" then "object" belongs into "data" (the var section) and "class" belongs into "structure of data" (the type section).

But "object" in the TurboPascal sense of the word is confusing, a badly chosen name for something else. Actually it is a type, it describes structure of data, type of data and not what one would intuitively expect the data itself, they shouldn't have called it "object".

When mixing the OOP terminology and TurboPascal terminology you can end up having an object whose type is "object". This is the source of your confusion. It is best to completely ignore the existence of the old object keyword while pondering about OOP problems and when you need to use it then pretend to yourself that the keyword "object" does not mean what it says at all, that its just a badly chosen type name but it doesn't matter because you know what it really is.

"procedure of object" on the other hand refers to the real (oop) meaning of "object" (instance of a class) and It would not hurt to also have its counterpart "procedure of class" to achieve the perfect symmetry as far as I'm concerned.

Reply by email