c++buildertframe

Place the created frame in the panel in the run time


I know how to create frame in the design time and place it in the panel in the runtime in Delphi. As for C++ Builder, It looked difficult as I am not familiar with C++ scripts. Please advise how to do the right way?

Thanks in advance


Solution

  • The solution is the exact same as in Delphi, you just need to use C++ syntax instead.

    Something like this should work:

    /*
    Assuming your frame is located in a unit called Frame1, and it's 
    called TMyFrameType, this is what you should add your Form unit
    cpp file.
    */
    
    #include "Frame1.h"
    
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
      : TForm(Owner)
    {
      // This assumes you have a panel in this form called "ThePanelWhereIWantIt".
      // You could move the MyFrameInstance to the class definition, if you need to 
      // access it somewhere after in your form code, but this is trivial.
      TMyFrameType *MyFrameInstance;  
      MyFrameInstance         = new TMyFrameType(ThePanelWhereIWantIt);
      MyFrameInstance->Parent = ThePanelWhereIWantIt;
      MyFrameInstance->Align  = alClient;
    }
    //---------------------------------------------------------------------------