Board index » cppbuilder » property is not read from dfm? Please help

property is not read from dfm? Please help


2005-10-27 01:48:02 AM
cppbuilder59
Hello,
I'm trying my hand a bit at component writing but no matter what I try, it
seems values set in the object inspector are written into the .dfm file
but do not show up in the code.
I made below an example as simple as possible. What is wrong with this
code? No matter what I set in the object inspector for 'Max', the
messagebox always says it's 15.
The .dfm file contains the value set in the object inspector though.
Thank you.
header file
//---------------------------------------------------------------------------
class PACKAGE TMru : public TComponent
{
private:
int FMax;
protected:
public:
__fastcall TMru(TComponent* Owner);
__published:
__property int Max = {read=FMax,write=FMax};
}
cpp file, only contains generated stuff and a bit in the constructor
//---------------------------------------------------------------------------
__fastcall TMru::TMru(TComponent* Owner) : TComponent(Owner)
{
FMax = 15;
if (!ComponentState.Contains(csDesigning))
{
String S = IntToStr(FMax);
MessageBox(NULL, "fmax", S.c_str(), MB_OK);
}
}
--
Using Opera's revolutionary e-mail client: www.opera.com/mail/
 
 

Re:property is not read from dfm? Please help

Jean wrote:
Quote
I'm trying my hand a bit at component writing but no matter what I
try, it seems values set in the object inspector are written into the
.dfm file but do not show up in the code.
I made below an example as simple as possible. What is wrong with this
code?
Change this line:
__property int Max = {read=FMax,write=FMax};
to:
__property int Max = {read=FMax,write=FMax,default=15};
HTH
Jonathan
 

Re:property is not read from dfm? Please help

"Jean" < XXXX@XXXXX.COM >wrote in message
Quote
What is wrong with this code? No matter what I set in the object
inspector for 'Max', the messagebox always says it's 15.
The DFM has not been streamed yet while the constructor is running. The DFM
is not streamed into the component until after the constructor has exited.
When the streaming is finished, the component's Loaded() method is called,
ie:
__fastcall TMru::TMru(TComponent* Owner)
: TComponent(Owner)
{
FMax = 15;
}
void __fastcall TMru::Loaded()
{
TComponent::Loaded();
if( !ComponentState.Contains(csDesigning) )
MessageBox(NULL, AnsiString(FMax).c_str(), "fmax", MB_OK);
}
Quote
__property int Max = {read=FMax,write=FMax};
Since you are setting a non-zero default value in the constructor, you
should specify that same value in the property declaration as well:
__property int Max = {read=FMax, write=FMax, default=15};
Gambit
 

{smallsort}

Re:property is not read from dfm? Please help

On Wed, 26 Oct 2005 11:41:13 -0700, "Remy Lebeau \(TeamB\)"
< XXXX@XXXXX.COM >wrote:
It's working now.. Thank you!
These newsgroups are still a pleasure. A working answer within an
hour. I used to come here often some years ago. I still remember your
name from then. :)
Thanks again :)
Quote
The DFM has not been streamed yet while the constructor is running. The DFM
is not streamed into the component until after the constructor has exited.
When the streaming is finished, the component's Loaded() method is called,
ie:
 

Re:property is not read from dfm? Please help

< XXXX@XXXXX.COM >wrote in message
Quote
These newsgroups are still a pleasure. A working answer within
an hour.
Sometimes even within minutes ;-)
Quote
I used to come here often some years ago. I still remember your
name from then. :)
Yes, I've been here for a long time (7 years, 2 months, 10 days to be
exact).
Gambit
 

Re:property is not read from dfm? Please help

Quote

These newsgroups are still a pleasure. A working answer within an
hour.
wait till you encounter bugs that goes straight to QC -- then you'll wait
have to wait for eons before you'll get it fixed in your current version...