Creating Frames dynamically

Top  Previous  Next

DFM-Translator > Creating Frames dynamically

As already mentioned for the creation of forms, these must not be created with the usual constructor (with only one parameter) if there is no longer an associated DFM file, as this constructor always tries to read this file. But while with forms you can simply use the other constructor (with the additional dummy parameter) in this case, this is not possible with frames because there is no such second constructor there. The only way out in this case is to derive frames to be created dynamically at runtime not from TFrame, but from a newly created class that contains the required constructor. TCustomDynFrame consists of the code of the TCustomFrame class translated into C++, whereby its constructor is replaced by the required constructor.



For example the class TFancyFrame from the Embarcadero frames demo then becomes to:


class TFancyFrame : public TCustomDynFrame




  TDBMemo* DBMemo1;

  TDBImage* DBImage1;

  TSplitter* Splitter1;


    /* Private declarations */


    /* Public declarations */

  typedef TCustomDynFrame inherited;  

  __fastcall TFancyFrame(TComponent* AOwner, int Dummy);



In the constructor of TDataFrame, which is part of the same demo, a TFancyFrame will be constructed with:


  FancyFrame1 = new TFancyFrame(this, 0);

This page belongs to the Delphi2Cpp Documentation

Delphi2Cpp home  Content