[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CppBuilderModifyingTForm
There are two ways to modify TForm1:
I'll describe the following basic topics below
The IDE has automatically changed the class declaration of TForm1 to contain the Button: in the __published section you can now read:
Note the comment! It is managed by the IDE, so you do not need to call new or delete for this Button.
Go to the Properties tab. Now you can easily change any Property you like.
Between the accolades you can put your code, e.g.:
Note that in the class definition, you can find:
As this code is managed by the IDE, do NOT remove it yourself. Remove the code between the accolades, then upon compiling the IDE will remove the empty Events itself.
I'll describe the following basic topics below
Now initialize it in the class's constructor. Go to the class definition, and modify the constructor to:
You could test this by making an OnClick Event calling it:
Go to the class declaration (in the header file. To the private section, add the lower line:
Now initialize it in the class's constructor. Go to the class definition, and modify the constructor to:
You could test this by making an OnClick Event calling it:
Now add the following lines of code in your class definition, preferable somewhere below the constructor:
You could test this by making an OnClick Event calling it:
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
CppBuilderModifyingTForm
(C++ Builder) Modifying your TForm
The C++ Builder IDE supplies you the TForm1 class. It is like any normal class, except of the __published part of it.There are two ways to modify TForm1:
- 1) Using the IDE. Easy for adding Components
- 2) Using the code editor. Easy for adding class member variables.
1) Modify the TForm using the IDE
This is easy for any beginner programmer.I'll describe the following basic topics below
1.1) Adding a Component
Select a Component from the Component Palette by clicking on it (e.g. a TButton). Then click on the Form.The IDE has automatically changed the class declaration of TForm1 to contain the Button: in the __published section you can now read:
__published: // IDE-managed Components TButton *Button1;
Note the comment! It is managed by the IDE, so you do not need to call new or delete for this Button.
1.2) Changing a Component's Property
Select any C++ Builder Component, e.g. your TForm1. You should now see the name in the Object Inspector. This same Object Inspector has two tabs: Properties and Events.Go to the Properties tab. Now you can easily change any Property you like.
1.3) Adding an Event to a Component
Select any C++ Builder Component, e.g. your TForm1. You should now see the name in the Object Inspector. This same Object Inspector has two tabs: Properties and Events. Go to the Events tab. Now double-click in the white square to the right of the Event you want, e.g. the OnClick Event. You will be taken to the code editor:
void __fastcall TForm1::FormClick(TObject *Sender)
{
}
Between the accolades you can put your code, e.g.:
void __fastcall TForm1::FormClick(TObject *Sender)
{
ShowMessage("Hello world");
}
Note that in the class definition, you can find:
__published: // IDE-managed Components void __fastcall FormClick(TObject *Sender);
As this code is managed by the IDE, do NOT remove it yourself. Remove the code between the accolades, then upon compiling the IDE will remove the empty Events itself.
2) Modify the TForm using the code editor
This takes slightly more knowledge of C++ then using the IDE. But all you need to know, is about classes, as the TForm1 is a class like any other, except of the __published part of it. But the public and private sections are yours!I'll describe the following basic topics below
2.1) Adding a member variable
Go to the class declaration (in the header file. To the private section, add the lower line:private: // User declarations String mString;
Now initialize it in the class's constructor. Go to the class definition, and modify the constructor to:
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
mString = "Hello World";
}
You could test this by making an OnClick Event calling it:
void __fastcall TForm1::FormClick(TObject *Sender)
{
ShowMessage(mString);
}
2.2) Adding a const member variable
Nearly the same as above:Go to the class declaration (in the header file. To the private section, add the lower line:
private: // User declarations const String mString;
Now initialize it in the class's constructor. Go to the class definition, and modify the constructor to:
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner),
mString("Hello World")
{
}
You could test this by making an OnClick Event calling it:
void __fastcall TForm1::FormClick(TObject *Sender)
{
ShowMessage(mString);
}
2.3) Adding a method
Go to the class declaration (in the header file. To the private section, add the lower line:private: // User declarations void sayHello() const;
Now add the following lines of code in your class definition, preferable somewhere below the constructor:
void TForm1::sayHello() const
{
ShowMessage("Hello World");
}
You could test this by making an OnClick Event calling it:
void __fastcall TForm1::FormClick(TObject *Sender)
{
sayHello();
}
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
