Form is not updating

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 could be causing this problem?

Edited: Thanks everyone for your answers. I found a bug. The project file was created two times:

Application->CreateForm(__classid(TForm1), &Form1);
Application->CreateForm(__classid(TForm1), &Form1);

      

+1


source to share


5 answers


Thanks everyone for your answers. I found a bug. The project file was created two times:



Application->CreateForm(__classid(TForm1), &Form1);
Application->CreateForm(__classid(TForm1), &Form1);

      

+1


source


Are you sure "this" is actually Form1?

if (this != Form1)
    ShowMessage("Whoops. Didn't expect that...");

      

How is your form created? Is it listed if the form "auto-create" in the project options, or are you manually instantiating it?



Assuming Form1 is your main form, it is usually generated by code in the main project.cpp file in the WinMain () function.

Application->CreateForm(__classid(TForm1), &Form1);

      

This should be written for you automatically using C ++ Builder, so be careful about manually modifying it.

+4


source


Try

Self.Caption

if it works then Form1 is not an instance of TForm1

Or debug it to see the type

+2


source


Are you sure the form of the TForm1 class you are working with is instantiated as Form1?

+1


source


I don't think TForm1 knows what you called

TForm1 * Form1=new TForm1(...); 

      

somewere. Is this your first try at CBuilder? The TForm1 * Form1 you see generated at the top of the file is just a declaration. you have to create it as well. Why don't you like the first solution that works? There is no need to use Form1 inside the class. Or if you really should use

this->Caption="...";

      

0


source







All Articles