Board index » cppbuilder » Re: Why did I satrt to develop a component?

Re: Why did I satrt to develop a component?


2007-11-20 08:12:42 PM
cppbuilder7
Thanks for all the help so far.
OK this is where I am at the moment
private:
__int64 FBlockSize,
void __fastcall SetBlockSize(__int64 bs){if(FBlockSize != bs)
FBlockSize=bs;};
__published
__property __int64 BlockSize =
{default=512,read=FBlockSize,write=SetBlockSize};
Am I missing something?
 
 

Re:Re: Why did I satrt to develop a component?

Sorry the reason i ask if I am missing something is that I am getting a
divide by zero error.
When traced it turns up in my component when I try and read FBlockSize. Why
is it not defaulting to 512 as specified above - when i check the components
properties in the IDE BlockSize is displayed as 512
 

Re:Re: Why did I satrt to develop a component?

Because the default value just tells the IDE property editor
what the default is.
You also need to set that value in the constructor or it
will be 0 :(
HTH Pete
"Paul" < XXXX@XXXXX.COM >wrote in message
Quote
Sorry the reason i ask if I am missing something is that I
am getting a divide by zero error.

When traced it turns up in my component when I try and
read FBlockSize. Why is it not defaulting to 512 as
specified above - when i check the components properties
in the IDE BlockSize is displayed as 512

 

{smallsort}

Re:Re: Why did I satrt to develop a component?

Sorry Paul
I forgot to mention that,
whenever You want Your property to have a default
thats not 0 You must set it in the initializer list
__fastcall TYourComponent::TYourComponent(TComponent* Owner)
: TCustomControl(Owner)
, FBlockSize(512)
{
}
and when You dont want the value to be zero You should
also check for that in the setter
private:
__int64 FBlockSize,
void __fastcall SetBlockSize(__int64 bs)
{
if(FBlockSize == bs)return;
if(bs < 1)
{
FBlockSize = 1;
//Maybe give an error message, especially in the IDE
//e.g. if component state is designing
}else
FBlockSize = bs;
}
Kind regards
Asger
 

Re:Re: Why did I satrt to develop a component?

Thanks again all,
Now working correctly - onwards to the next problem :)
 

Re:Re: Why did I satrt to develop a component?

"Paul" < XXXX@XXXXX.COM >wrote in message
Quote
__int64 __fastcall GetBlockSize(){return BlockSize;};
That is likely producing a recursive loop. Your property is named
"BlockSize", but your code is accessing "BlockSize" as if it were a variable
instead. Never give your data members the same names as their accessing
properties. It is customary (but not required) to name data members with
the 'F' or 'f' prefix.
Quote
void __fastcall SetBlockSize(__int64 bs){if(BlockSize != bs)
BlockSize=bs;};
Likewise. Also, property setters do not have a return value.
Try this instead:
private:
__int64 FBlockSize;
__int64 __fastcall GetBlockSize() { return FBlockSize; }
void __fastcall SetBlockSize(__int64 Value){ if( FBlockSize !=
Value ) FBlockSize = Value; }
public:
__property __int64 BlockSize = {read=GetBlockSize,
write=SetBlockSize, default=512);
Now, with that said, since your getter is not retreiving the property value
dynamically, and your setter is not acting on changes to the value, there is
no need to use getter/setter methods at all:
private:
__int64 FBlockSize;
public:
__property __int64 BlockSize = {read=FBlockSize, write=FBlockSize,
default=512);
Quote
any ideas how I can get CodeGear to load?
Go into the Registry and manually disable/remove the package so it won't
load anymore.
Gambit