0

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

manlio
  • 18,345
  • 14
  • 76
  • 126
user1739825
  • 820
  • 4
  • 10
  • 27

1 Answers1

2

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;
}
//---------------------------------------------------------------------------
Rodrigo Gómez
  • 1,079
  • 8
  • 24
  • Hi Thanks. Refering to "TMyFrameType *MyFrameInstance;". I created a frame outside the form, meaning that I now have 2 cpp files that are for form and frame. How do I make a reference to frame from form and vice versa? Use "UseForm"? As for construction and destruction for frame? I had a hard time sourcing for codes, to help me to learn. It's very frustrating and distressing for me, especially using window applications. Wish there are books and sites online for me to learn using. – user1739825 Jun 04 '15 at 02:49
  • @user1739825 Hello. You need to #include the frame unit (the header) in your form unit. You can do this on the header itself, in case you want to create a variable of your frame there. For using the form from your frame, you can modify the constructor of your frame to pass a reference of your form. I can modify the answer to include some of this, but I'll do it later - tomorrow. Doing so on the phone keyboard is no fun :) – Rodrigo Gómez Jun 04 '15 at 05:10
  • @user1739825 I've modified the provided example. It should be enough to provide you a guide to implement what you need. If you have more questions you should ask a new question. That's the correct way to do it here in SO, and the way that maximizes your changes of them being answered. – Rodrigo Gómez Jun 04 '15 at 17:14