 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Emmanuel Guest
|
Posted: Wed Jan 03, 2007 8:58 am Post subject: cannot fond the object when ComponentState is csDesigning,cs |
|
|
I have write a component,say C1.
one of the property,say p1, is link to a TComponent,say C2, which is owner
by other TForm ,say FormA,
I find that when the ComponentState is csDesigning, and the FormA have not
open, the C1->p1 will set to be NULL
eventhough C1->p1=FormA->C2 in the dfm file.
How can I solve it?
__published:
__property
TERPRemoteServer*RemoteServerLink={read=FRemoteServerLink,write=SetLinkRemoteServer};
void __fastcall
TERPRemoteServer::SetLinkRemoteServer(TERPRemoteServer*Value)
{if(Value==this)
{return;
}
//for test only
Application->MessageBox(((AnsiString)(int)Value).c_str(),"FRemoteServerLink",MB_OK); if(Value!=NULL) {Application->MessageBox(Value->Name.c_str(),"FRemoteServerLink->Name",MB_OK); }....}it will Claim Value = NULLApplication->MessageBox("0","FRemoteServerLink",MB_OK);in fact, it is not NULL in dfm fileHow can I solve it? |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Wed Jan 03, 2007 9:11 am Post subject: Re: cannot fond the object when ComponentState is csDesignin |
|
|
"Emmanuel" <emmanuel (AT) erphk (DOT) com> wrote in message
news:459b1b27 (AT) newsgroups (DOT) borland.com...
| Quote: | I have write a component,say C1.
one of the property,say p1, is link to a TComponent,say C2, which is
owner
by other TForm ,say FormA,
I find that when the ComponentState is csDesigning, and the FormA
have not
open, the C1->p1 will set to be NULL
eventhough C1->p1=FormA->C2 in the dfm file.
|
As it should be, as FormA has not been loaded yet, and the reference
to C2 has not been resolved yet..
| Quote: | How can I solve it?
|
There is nothing to solve. The streaming is doing exactly what it is
supposed to be doing. You are simply trying to access the external
component too soon. The SetLinkRemoteServer() method will be
triggered immediately when the DFM is streamed. But if FormA hasn't
been loaded yet, it cannot pass a valid component pointer to
SetLinkRemoteServer(), so you get NULL. You have to wait until your
component's Loaded() method has been called before the reference will
be valid. For example:
private:
TERPRemoteServer* FRemoteServerLink;
protected:
virtual void __fastcall Loaded();
__published:
__property TERPRemoteServer* RemoteServerLink =
{read=FRemoteServerLink, write=SetLinkRemoteServer};
void __fastcall TERPRemoteServer::Loaded()
{
YourBaseComponent::Loaded();
Application->MessageBox(IntToStr(Value).c_str(), "Loaded:
FRemoteServerLink", MB_OK);
if( FRemoteServerLink )
Application->MessageBox(FRemoteServerLink->Name.c_str(),
"Loaded: FRemoteServerLink->Name", MB_OK);
}
void __fastcall
TERPRemoteServer::SetLinkRemoteServer(TERPRemoteServer*Value)
{
if( FRemoteServerLink != Value )
{
FRemoteServerLink = Value;
Application->MessageBox(IntToStr(Value).c_str(), "Set:
FRemoteServerLink", MB_OK);
if( FRemoteServerLink )
Application->MessageBox(FRemoteServerLink->Name.c_str(), "Set:
FRemoteServerLink->Name", MB_OK);
}
}
The DFM streaming code maintains a list of cross references that it
has to resolve after all components have been created. So
SetLinkRemoteServer() may get called more than once during the
streaming of your component.
Gambit |
|
| Back to top |
|
 |
Emmanuel Guest
|
Posted: Mon Jan 08, 2007 9:43 pm Post subject: Re: cannot fond the object when ComponentState is csDesignin |
|
|
No Solution? |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Wed Jan 10, 2007 2:00 am Post subject: Re: cannot fond the object when ComponentState is csDesignin |
|
|
"Emmanuel" <emmanuel (AT) erphk (DOT) com> wrote in message
news:45a265e1 (AT) newsgroups (DOT) borland.com...
I already gave you an answer a week ago.
Gambit |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|