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).

Mailing lists / fpc-pascal / 2012-07
9 messages · 5 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
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
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>"
CA Gorski wroteBut 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
Jonas Maebe wroteThat 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!
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
You have to use "of object", just like for a regular method. Jonas
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]
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
pardon my intrusion but i'm looking for clarification... in the beginning we had…
waldo kitty wrotenow 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.