BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Persisting a TStrings property value

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Thirdparty Tools (General)
View previous topic :: View next topic  
Author Message
Jonathan Neve[Microtec]
Guest





PostPosted: Thu Sep 21, 2006 4:05 am    Post subject: Persisting a TStrings property value Reply with quote



Hi,

I'm having trouble getting a TStrings property value to read correctly
when loading my component from the DFM. The value is present in the
DFM, but when I load the form, it simply doesn't even call the property
setter...

property SQL: TStrings read GetSQL write SetSQL;

....

function TCcDataSet.GetSQL: TStrings;
begin
tmpStrings.Text := FSelectQuery.SQL;
Result := tmpStrings;
end;

....

procedure TCcDataSet.SetSQL(const Value: TStrings);
begin
Close;
FSelectQuery.SQL := Value.Text;
end;

Any idea what I'm doing wrong?

--
Best regards,
Jonathan Neve
_______________
CopyTiger - advanced database replicator for Interbase/Firebird!
Web : http://www.microtec.fr/copycat/ct
_______________________________________
CopyCat - database replication components for Delphi/C++Builder!
Web : http://www.microtec.fr/copycat/cc
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Thu Sep 21, 2006 4:19 am    Post subject: Re: Persisting a TStrings property value Reply with quote



"Jonathan Neve[Microtec]" <jonathan (AT) microtec (DOT) fr> wrote in message
news:xn0ergz1p1230uy000jmn_microtec (AT) forums (DOT) borland.com...

Quote:
The value is present in the DFM, but when I load the form,
it simply doesn't even call the property setter...

It is not supposed to call the setter in the first place. Object-based
properties call the getter instead of the setter, and then the data for that
property is streamed into the object that was returned by the getter. The
setter will also not be called when you change the value of the property's
content programmably in your code, either

Use this code instead:

TCcDataSet = class(TWhatever)
private
FSQL: TStrings;
procedure SetSQL(AValue: TStrings);
procedure SQLChanged(Sender: TObject);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property SQL: TStrings read FSQL write SetSQL;
end;

constructor TCcDataSet.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FSQL := TStringList.Create;
TStringList(FSQL).OnChange := SQLChanged;
end;

destructor TCcDataSet.Destroy;
begin
FSQL.Free;
inherited Destroy;
end;

procedure TCcDataSet.SetSQL(AValue: TStrings);
begin
FSQL.Assign(AValue);
end;

procedure TCcDataSet.SQLChanged(Sender: TObject);
begin
Close;
FSelectQuery.SQL := FSQL.Text
end;


Gambit
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Thirdparty Tools (General) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.