: If I create a new form using the code : [code]: Form2 = new TForm2(Application);[/code]: : Infact lets say I create 4 forms. : : How do I change for example the captions of all the forms to form 1 : , form 2 , form3, form4 ? : Here's how it could be done: [code] Form2.Caption = 'Form2'; [/code] or you might do something like this: [code] Form.Caption = Form.Name; [/code] If you want to create the forms using a for-loop, this is an option: [code] for (int i = 1; i < 5; i++) { Form = new TForm2(Application); Form.Caption = 'Form'+IntToStr(i); } [/code] Note: I'm not very familiar with C++ so the code examples may contain syntax errors.
: Okay but how do change the caption of the first copy of form2? : The one with the caption Form1 according to your code. : : If I activate your code and then write. : Form2->Caption = "Yalla"; Only the last created form changes Caption. : Check the TApplication class. There should be a property which holds references to all the forms. Notice in the last code how I included the setting of the caption in the for-loop. This should change the caption of each copy of form2.
: It feels so stupid to ask but how do I check it? : In the help files. In the Delphi language you can do something like this: [code] for i := 0 to Application.FormCount-1 do ListBox1.Items.Add(Application.Forms[i].Caption); [/code] to get the captions of the created forms in the application.
: [code]: : for i := 0 to Application.FormCount-1 do : ListBox1.Items.Add(Application.Forms[i].Caption); : [/code]: : to get the captions of the created forms in the application. It seems that in C++ builder hmm .net? Forms is not a member of Application.
: : [code]: : : : for i := 0 to Application.FormCount-1 do : : ListBox1.Items.Add(Application.Forms[i].Caption); : : [/code]: : : : to get the captions of the created forms in the application. : It seems that in C++ builder hmm .net? : Forms is not a member of Application. :
You can always create your own 'form controller' by passing the new form instances to a function that keeps the reference in a container:
then when yo need to change the form captions during runtime:
[code] for (int i = 0; i < lstOpenForms->Count; i++) { //this line will crash if the reference of a closed from was not removed from lstOpenForms ((TForm*)lstOpenForms->Item[i])->Caption += "Runtime Change x";
Comments
: [code]: Form2 = new TForm2(Application);[/code]:
: Infact lets say I create 4 forms.
:
: How do I change for example the captions of all the forms to form 1
: , form 2 , form3, form4 ?
:
Here's how it could be done:
[code]
Form2.Caption = 'Form2';
[/code]
or you might do something like this:
[code]
Form.Caption = Form.Name;
[/code]
If you want to create the forms using a for-loop, this is an option:
[code]
for (int i = 1; i < 5; i++) {
Form = new TForm2(Application);
Form.Caption = 'Form'+IntToStr(i);
}
[/code]
Note: I'm not very familiar with C++ so the code examples may contain syntax errors.
The one with the caption Form1 according to your code.
If I activate your code and then write.
Form2->Caption = "Yalla"; Only the last created form changes Caption.
: The one with the caption Form1 according to your code.
:
: If I activate your code and then write.
: Form2->Caption = "Yalla"; Only the last created form changes Caption.
:
Check the TApplication class. There should be a property which holds references to all the forms. Notice in the last code how I included the setting of the caption in the for-loop. This should change the caption of each copy of form2.
:
In the help files. In the Delphi language you can do something like this:
[code]
for i := 0 to Application.FormCount-1 do
ListBox1.Items.Add(Application.Forms[i].Caption);
[/code]
to get the captions of the created forms in the application.
: for i := 0 to Application.FormCount-1 do
: ListBox1.Items.Add(Application.Forms[i].Caption);
: [/code]:
: to get the captions of the created forms in the application.
It seems that in C++ builder hmm .net?
Forms is not a member of Application.
: : for i := 0 to Application.FormCount-1 do
: : ListBox1.Items.Add(Application.Forms[i].Caption);
: : [/code]: :
: : to get the captions of the created forms in the application.
: It seems that in C++ builder hmm .net?
: Forms is not a member of Application.
:
You can always create your own 'form controller' by passing the new form instances to a function that keeps the reference in a container:
[code]
TList* lstOpenForms;
[/code]
[code]
..
lstOpenForms = new TList();
..
OpenForm(new Form1(this))->Caption = "Form One";
..
[/code]
[code]
TForm* OpenForm(TForm* frm){
frm->Show();
lstOpenForms->Add(frm);
return frm;
}
[/code]
then when yo need to change the form captions during runtime:
[code]
for (int i = 0; i < lstOpenForms->Count; i++)
{
//this line will crash if the reference of a closed from was not removed from lstOpenForms
((TForm*)lstOpenForms->Item[i])->Caption += "Runtime Change x";
}
[/code]