How can I create an Delphi object from a class reference and ensure constructor execution? -


How can I create an example of an object using the cell reference and can ensure that the constructor is executed?

In this code example, the creator of TMyClass will not be asked:

  type TMyClass = class (TObject) MyStrings: TStrings; Build Creator; Virtual; End; Manufacturer TMyClass.Create; Start MyStrings: = TStringList.Create; End; Process testing; War Clauses: Teclas; Example: tobjject; Start the Clause: = TMyClass; Example: = Clause. Create; End;  

Use this:

  type TMyClass = Class (toobject) mestring: teetering; Build Creator; Virtual; End; TMyClassClass = Class of TMyClass; // & lt; - Add this definition constructor TMyClass.Create; Start MyStrings: = TStringList.Create; End; Process testing; War Clauses: TMyClassClass; // & lt; - Change T-Class to TMyClassClass instance: Tubact; Start the Clause: = TMyClass; // & lt; - You can use classes of TMyClass or any of its children Example: = Clause Create; // & lt; - The end of the virtual producer will be used;  

Alternatively, you can use a Type-Cost using TMyClass (instead of "Class of TMyClass").


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -