On 01/05/2024 16:28, Adriaan van Os via fpc-pascal wrote:
Suppose I have a
var myClass: TClass
and (for example) a
class function TWindow.CreateNewWindow( ....)
Now I want to call CreateNewWindow for var myClass. Of course,
depending on the class, CreateNewWindow will behave different.
Type-casting myClass to TWindow crashes (in my setup). And even if it
worked, wouldn't it loose the class information ?
Silly question, but did you assign the value to the variable?
myClass := TWindow;
TWindow(myClass).CreateNewWindow;
The cast is not always needed.
If you have
var myClass: TMyClass;
with
TMyClass = class
class procedure CreateNewWindow; virtual
end;
And any inherited class correctly overrides this, then you don't need
the typecast.
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal