Quote
"Jeff Parr" <jeffp...@agincourt.co.uk> wrote in message
news:3c23de9a_1@dnews...
Quote
> I am trying to build a component with a TriState properties (true, false
and
> Don'tCare). I've already defined the TriState type with all its operators
> etc. and it works.
For the record, this belongs in
borland.public.cppbuilder.vcl.components.writing instead.
Quote
> __published:
> __property TTest Version = { write = FVersion, read = FVersion} ;
In order to publish a class, you should use a pointer instead (and since
__published only applies to the Object Inspector, derive the class from
TPersistent if you want it to be visible in the Object Inspector):
class TTest : TPersistent
{
private
int a;
public:
void __fastcall Assign(TPersistent *Source);
__published:
__property int A = { read = a, write = a };
};
void __fastcall TTest::Assign(TPersistent *Source)
{
TTest *test = dynamic_cast<TTest*>(Source);
if(test)
a = test->A;
else
TPersistent::Assign(Source);
}
class PACKAGE TMode : public TComponent
{
private:
TTest *FVersion
void __fastcall SetVersion(TTest *Value);
public:
__fastcall TMode(TComponent *Owner);
__fastcall ~TMode();
__published:
__property TTest* Version = { read = FVersion, write = SetVersion };
};
__fastcall TMode::TMode(TComponent *Owner)
{
FVersion = new TTest;
}
__fastcall TMode::~TMode()
{
delete FVersion;
}
void __fastcall TMode::SetVersion(TTest *Value)
{
FVersion->Assign(Value);
// do something in response to the change
}
Quote
> __property AnsiString SVersion = { write = FSVersion, read = FSVersion}
;
AnsiString is a special-case class, the VCL knows how to handle it without
needing to use pointers.
To really accomplish what you're trying to do, you could just use an enum
instead of a class, ie:
enum TriSta{*word*249}um {tsTrue, tsFalse, tsDontCare};
class PACKAGE TMode : public TComponent
{
private:
TriSta{*word*249}um FTriState;
void __fastcall SetTriState(TriSta{*word*249}um Value);
__published:
__property TriSta{*word*249}um TriState = { read = FTriState, write =
SetTriState };
};
void __fastcall TMode::SetTriState(TriSta{*word*249}um Value)
{
if(FTriState != Value)
{
FTriState = Value;
// do something in response to the change
}
}
Gambit