<div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Harald Houppermans via fpc-devel <<a href="mailto:fpc-devel@lists.freepascal.org">fpc-devel@lists.freepascal.org</a>> schrieb am Fr., 21. Feb. 2020, 12:37:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">*** Shorter version / less explanation ***:<br>
(Alternative shorter version):<br>
<br>
I want/have the need to do the following, I want one unit as follows:<br>
<br>
UnitVersion:<br>
<br>
type<br>
TVersion =<br>
(<br>
v1,<br>
v2,<br>
v3<br>
)<br>
<br>
I want to create some kind of pluggeable/plugin array to c;ass functions <br>
like so:<br>
<br>
(class functions can be called without creating an object like so<br>
TSomeObject.ClassFunction;)<br>
<br>
TInitializer = class function;<br>
<br>
// could also be a constructor maybe<br>
TInitialize = class constructor;<br>
<br>
TInitializerArray = array[TVersion] of TIntializer;<br>
<br>
var<br>
InitializerArray : TInitializerArray;<br>
<br>
Then the user can add certain units to the project yes or no... certain <br>
versions.<br>
For example version v1 and v2, but not v3.<br>
<br>
Version1 and Version2 should "plug themselfes into this array" like so:<br>
<br>
unit version 1<br>
<br>
type<br>
Tversion1 = class<br>
class function Initialize;<br>
end;<br>
<br>
initialization<br>
<br>
UnitVersion.InitializerArray[v1] := TVersion1.Initializer;<br>
<br>
unit version 2<br>
<br>
type<br>
Tversion2 = class<br>
class function Initialize;<br>
end;<br>
<br>
initialization<br>
<br>
UnitVersion.InitializerArray[v2] := TVersion2.Initializer;<br>
<br>
<br>
The idea is then that user code can use<br>
<br>
UnitVersion.pas and include only version 1 and version 2.<br>
<br>
And other code can then automate the initialization without breaking code.<br>
<br>
If version 3 were added it would break code, cause version3.pas might not be <br>
present or included in project.<br>
<br>
So automation code should work even if a certain unit is not present.<br>
<br>
Currently initialization is done with class functions.<br>
<br>
Not sure if it's possible to make pointers to class functions.<br>
<br>
With method pointers this would be easy/doable.<br>
<br>
But now I am not sure if this is possible.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">If you don't need the initializers to be virtual or have access to the class type using Self you can declare them as static (class procedure Initialize; static;), then you can assign them to normal procedure variables (TInitializer = procedure;). </div><div dir="auto"><br></div><div dir="auto">Regards, </div><div dir="auto">Sven </div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote></div></div></div>