Hello
I’m using a TZReadOnlyQuery to get my data for the DB. but I would like to use a standard VCL TClientDataSet to parse down to my objects. So if the Zeos components change, I’ll only have to change the dbConnection module.
But the problem, what is the best way to transfer/copy the data from the TZReadOnlyQuery to the TClientDataSet?
I tried this way:
for i:=0 to ZReadOnlyQuery1.Fields.Count-1 do
ClientDataSet1.Fields.Add(ZReadOnlyQuery1.Fields.Fields);
But that only copyed the pointes, not the data, sow on a free the program will crash. :s
Any ideas?
.:martin
TZReadOnlyQuery to TClientDataSet
Moderators: gto, cipto_kh, EgonHugeist
Using the way you tried, it will copy if you use something like this:
But, it's a handmade solution and others more "professional" may exist
[]'s!
Code: Select all
for i := 1 to Query.RecordCount do
begin
ClientDS.Open;
Query.Open;
begin
ClientDS.Insert;
ClientDS.FieldByName('DestinyFieldName-1').Value := Query.FieldValues['SourceFieldName-1'];
ClientDS.FieldByName('DestinyFieldName-2').Value := Query.FieldValues['SourceFieldName-2'];
ClientDS.FieldByName('DestinyFieldName-3').Value := Query.FieldValues['SourceFieldName-3'];
(...)
ClientDS.Post;
Query.Next;
end;
ClientDS.Close;
Query.Close;
end;
[]'s!