c++builder - update statusbar's text property in the form by another form's button's click event -


hi unable update status bar's text property in form form's button click. compiled , able run until clicked error got "access violation @ address: xxxxxxxx....."

c++ builder xe7 in win 7 used.

form1:

#include "main.h" #include "minor.h" .... tform1 *form1; tform2 *form2; .... 

form2:

#include "minor.h" #include "main.h" .... tform2 *form2; tform1 *form1; .... __fastcall tform2::tform2(tcomponent* owner) : tform(owner) { tbutton* btntest2 = new tbutton(this); btntest2->height = 50; btntest2->width = 200; btntest2->left = 220; btntest2->top = 50; btntest2->caption = "updated statusbar button"; btntest2->visible = true; btntest2->enabled = true; btntest2->parent = this; btntest2->onclick = &buttonclicked2; // create own event here manually! } //---------------------------------------------------------------------------  void __fastcall tform2::buttonclicked2(tobject *sender) { form1->statusbarmain->panels->items[0]->text = "hello2";   // problem!!! } 

any idea why got problems? please advise.. thanks

your form2 unit declaring own form1 variable separate form1 variable in form1 unit, , second variable not being initialized meaningful. why code crashing - accessing wrong form1 variable.

you need rid of form1 variable in form2 unit , #include form1's header file instead (it should have extern declaration form1's form1 variable). necessary because form2 needs full declaration of tform1 class in order access members, such statusbarmain.

same thing form2 variable declaring in form1 unit. need remove , use #include "form2.hpp" instead (which should have suitable extern declaration).

form1.h:

... class tform1 : public tform { __published:     tstatusbar *statusbarmain;     ... }; extern tform1 *form1; ... 

form1.cpp:

#include "main.h" #include "minor.h" #include "form2.hpp" // <-- add .... tform1 *form1; //tform2 *form2; // <-- rid of .... 

form2.h:

... class tform2 : public tform {     ... }; extern tform2 *form2; ... 

form2.cpp:

#include "minor.h" #include "main.h" #include "form1.hpp" // <-- add .... tform2 *form2; //tform1 *form1; // <-- rid of ... void __fastcall tform2::buttonclicked2(tobject *sender) {     form1->statusbarmain->panels->items[0]->text = "hello2"; } 

Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -