[fpc-devel] reference/pointer to class function/constructor ?

Nikolai Zhubr n-a-zhubr at yandex.ru
Fri Feb 21 13:31:54 CET 2020


Hi,
20.02.2020 10:21, Harald Houppermans via fpc-devel:
[...]
> Now I need a type to the initialize function which is a class function,
> I simply tried:
>
> type
> Tinitializer = class function; // this don't work in Delphi
>
> I also tried:
>
> Tinitializer = ^class function; // this don't work in Delphi.

I'd guess your initializer function in fact does not need to be a class 
member. Actually, a class function is a rather "weak" memeber already. 
So then you just declare a regular function type and some few regular 
functions as initializers. Now, from within such regular function, you 
may call some class functions if you need so. Not very elegant but 
supposedly should work.

HTH

Regards,
Nikolai

> Since writing TsomeObject.Initializer is weird might initialize thought
> was to use a constructor which is a little bit more strange/inefficient
> maybe but keeps code consistent in case class functions or turned into
> method functions.
>
> Tinitializer = constructor;
>
> Tinitializer = ^constructor;
>
> Tinitializer = class constructor;
>
> Tinitializer = ^class constructor;
>
> None of this seems possible ?!?
>
> So it seems that my fair that I require some language feature that is
> not available might be true.
>
> If so try and understand it and try and create a plugin system for
> units, to automatically initialize via arrays and plugin tables and
> constructors and such in an object orientated way where inheritance and
> order also plays a roll to some degree. If you can prove to me that this
> can be done with new language features that would be great !
>
> Otherwise "Houston we have a problem" and we need more powerfull
> language extensions/features.
>
> In case you agree with this then my hope is that if Free Pascal
> implements it maybe Delphi will some day too ! ;) =D
>
> Bye for now,
> Skybuck =D
>
>
> *** Shorter version / less explanation ***:
> (Alternative shorter version):
>
> I want/have the need to do the following, I want one unit as follows:
>
> UnitVersion:
>
> type
> TVersion =
> (
> v1,
> v2,
> v3
> )
>
> I want to create some kind of pluggeable/plugin array to c;ass functions
> like so:
>
> (class functions can be called without creating an object like so
> TSomeObject.ClassFunction;)
>
> TInitializer = class function;
>
> // could also be a constructor maybe
> TInitialize = class constructor;
>
> TInitializerArray = array[TVersion] of TIntializer;
>
> var
> InitializerArray : TInitializerArray;
>
> Then the user can add certain units to the project yes or no... certain
> versions.
> For example version v1 and v2, but not v3.
>
> Version1 and Version2 should "plug themselfes into this array" like so:
>
> unit version 1
>
> type
> Tversion1 = class
> class function Initialize;
> end;
>
> initialization
>
> UnitVersion.InitializerArray[v1] := TVersion1.Initializer;
>
> unit version 2
>
> type
> Tversion2 = class
> class function Initialize;
> end;
>
> initialization
>
> UnitVersion.InitializerArray[v2] := TVersion2.Initializer;
>
>
> The idea is then that user code can use
>
> UnitVersion.pas and include only version 1 and version 2.
>
> And other code can then automate the initialization without breaking code.
>
> If version 3 were added it would break code, cause version3.pas might
> not be present or included in project.
>
> So automation code should work even if a certain unit is not present.
>
> Currently initialization is done with class functions.
>
> Not sure if it's possible to make pointers to class functions.
>
> With method pointers this would be easy/doable.
>
> But now I am not sure if this is possible.
>
> It's getting late... tomorrow I will do more re-search into this.
>
> But perhaps somebody already knows how to solve this.
>
> Bye for now,
> Skybuck.
> _______________________________________________
> fpc-devel maillist - fpc-devel at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel



More information about the fpc-devel mailing list