Board index » cppbuilder » Re: Why did I satrt to develop a component?
Paul
![]() CBuilder Developer |
Paul
![]() CBuilder Developer |
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? |
Paul
![]() CBuilder Developer |
2007-11-20 08:19:25 PM
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 |
Pete Fraser
![]() CBuilder Developer |
2007-11-20 08:48:30 PM
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 QuoteSorry the reason i ask if I am missing something is that I {smallsort} |
Asger Joergensen
![]() CBuilder Developer |
2007-11-20 09:15:58 PM
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 |
Paul
![]() CBuilder Developer |
2007-11-20 09:38:12 PM
Re:Re: Why did I satrt to develop a component?
Thanks again all,
Now working correctly - onwards to the next problem :) |
Remy Lebeau (TeamB)
![]() CBuilder Developer |
2007-11-21 01:54:08 AM
Re:Re: Why did I satrt to develop a component?
"Paul" < XXXX@XXXXX.COM >wrote in message
Quote__int64 __fastcall GetBlockSize(){return BlockSize;}; 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. Quotevoid __fastcall SetBlockSize(__int64 bs){if(BlockSize != bs) 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); Quoteany ideas how I can get CodeGear to load? Gambit |