Board index » cppbuilder » constant with VCL addresses?

constant with VCL addresses?


2006-02-10 11:50:37 PM
cppbuilder12
Hello,
I want to use a constant array that contains the addresses of VCL
components, like this
extern const my_struct my_array []
= {
{...other values...,(void *)(mainform->Edit1) },
{... more of those...}
}
It compiles without errors but raises an exception when starting the program
before the first line of code I wrote is executed. I assume that it tries to
reach an object that does not yet exist (??).
How can I get the constant array being created later?
Or are there other solutions?
Thanks for any help
Martin
 
 

Re:constant with VCL addresses?

"Martin" < XXXX@XXXXX.COM >wrote in message
Quote
I want to use a constant array that contains the
addresses of VCL components, like this
You won't be able to use const because the component pointers (or even the
form pointer) are not available yet when the array is initialized at program
startup. Remove the const, then you can fill in the missing values in the
form's constructor, ie:
my_struct my_array[] = {
{...other values..., NULL },
{... more of those...}
};
__fastcall TForm1::TForm1(TComponent *Owner)
{
my_array[SomeIndex].SomePtr = Edit1;
//...
}
Quote
It compiles without errors but raises an exception when starting
the program before the first line of code I wrote is executed.
That is because you tried to access the form before it had been created.
Gambit
 

Re:constant with VCL addresses?

Hello Remy,
thank you very much, it works fine like you said.
Martin
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
Quote

"Martin" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>I want to use a constant array that contains the
>addresses of VCL components, like this

You won't be able to use const because the component pointers (or even the
form pointer) are not available yet when the array is initialized at
program
startup. Remove the const, then you can fill in the missing values in the
form's constructor, ie:

my_struct my_array[] = {
{...other values..., NULL },
{... more of those...}
};

__fastcall TForm1::TForm1(TComponent *Owner)
{
my_array[SomeIndex].SomePtr = Edit1;
//...
}

>It compiles without errors but raises an exception when starting
>the program before the first line of code I wrote is executed.

That is because you tried to access the form before it had been created.


Gambit


 

{smallsort}