Form doesn't get updated
-
06-07-2019 - |
Question
In my application (Main form is TTntForm, C++Builder 2006):
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Caption=L"1st caption"; // This works.
Form1->Caption=L"2nd caption"; // But this doesn't work,
// Caption of the form remains "1st caption".
}
What might be the cause of this problem?
Edited: Thank you all for your answers. I found the bug. There was a twice form creation in project file:
Application->CreateForm(__classid(TForm1), &Form1);
Application->CreateForm(__classid(TForm1), &Form1);
Solution 4
Thanks you all for your answers. I found the bug. There was a twice form creation in project file:
Application->CreateForm(__classid(TForm1), &Form1);
Application->CreateForm(__classid(TForm1), &Form1);
OTHER TIPS
Are you sure that "this" is actually Form1?
if (this != Form1)
ShowMessage("Whoops. Didn't expect that...");
How is your form being created? Is it in the list if "autocreate" forms in the project options, or are you manually creating an instance of it?
Assuming Form1 is your main form, it's normally created by code in your main project.cpp file, in function WinMain().
Application->CreateForm(__classid(TForm1), &Form1);
This should get written for you automatically by C++Builder, so be wary of changing it manually.
Try
Self.Caption
if this works then Form1 isn´t a instance of TForm1
Or debug it to see the type
Are you sure the TForm1 class form you are working with is instantiated as Form1?
I don't think that TForm1 knows that you have called
TForm1 * Form1=new TForm1(...);
somewere. Is this your first attempt in CBuilder? TForm1 * Form1 that you see generated in top of the file is just declaration. you must also create it. Why don't you like the first, working, solution? There is no need to use Form1 inside the class. Or if you really must then use
this->Caption="...";