[fpc-pascal] Type-casting a class variable

Sven Barth pascaldragon at googlemail.com
Thu May 2 07:56:19 CEST 2024


Adriaan van Os via fpc-pascal <fpc-pascal at lists.freepascal.org> schrieb am
Mi., 1. Mai 2024, 17:07:

> 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 ?
>

In addition to what Martin said: as long as you have a non-static class
method the value of the variable you call the class method on (e.g. myClass
in your example) will be passed as Self parameter. So no need for extra
parameters.

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20240502/8b36fb15/attachment.htm>


More information about the fpc-pascal mailing list