Page 1 of 1

TZReadOnlyQuery to TClientDataSet

Posted: 17.01.2006, 14:09
by gromar
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? :gruebel:




.:martin

Posted: 17.01.2006, 17:17
by gto
Using the way you tried, it will copy if you use something like this:

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;
But, it's a handmade solution and others more "professional" may exist :lol:
[]'s!

Posted: 17.01.2006, 17:39
by tygrys
Look at the ProviderName property of CDS and TDatasetProvider.

Tygrys