Board index » cppbuilder » Global variables inside VCL components member functions

Global variables inside VCL components member functions

I am using a global variable in a VCL application. When I use the
variable inside the WinMain block, but outside any VCL component's
member function, everything works fine. However, inside such a function,

if I try to assing a value to the variable, read its value or address,
or pass its value or address in parameter, either the instruction is
ignored at runtime, or a wrong value is passed.

I would be very thankful to anyone having a solution and/or an
explanation to this strange problem (Your name could appear in the
"Credits" section of a new Management Integrated System !!!).

Raphael : bu...@qc.aira.com

 

Re:Global variables inside VCL components member functions


Hi Messier --

Quote
> I am using a global variable in a VCL application. When I use the
> variable inside the WinMain block, but outside any VCL component's
> member function, everything works fine. However, inside such a
> function, if I try to assing a value to the variable, read its
> value or address, or pass its value or address in parameter, either
> the instruction is ignored at runtime, or a wrong value is passed.

What type of variable are your trying to store?  I can't seem to
reproduce this...

// in project source...

int MyGlobalVar = 1001;
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
   try
   {
       ShowMessage(MyGlobalVar);
       Application->Initialize();
       Application->CreateForm(__classid(TForm1), &Form1);
       Application->Run();
   }
   catch (Exception &exception)
   {
       Application->ShowException(&exception);
   }
   return 0;

Quote
}

// in Form1 source...

int extern MyGlobalVar;

__fastcall TForm1::TForm1(TComponent* Owner)
   : TForm(Owner)
{
   ShowMessage(MyGlobalVar);

Quote
}

Good luck.

--
Damon Chandler (TeamB - C++Builder)
- http://homepages.go.com/~damonchandler/vcl_faq.zip
- http://bcbcaq.freeservers.com

Other Threads