TZReadOnlyQuery to TClientDataSet

Forum related to version 6.5.1 (alpha) and 6.6.x (beta) of ZeosLib's DBOs

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
gromar
Fresh Boarder
Fresh Boarder
Posts: 1
Joined: 17.01.2006, 14:04

TZReadOnlyQuery to TClientDataSet

Post 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
gto
Zeos Dev Team
Zeos Dev Team
Posts: 278
Joined: 11.11.2005, 18:35
Location: Porto Alegre / Brasil

Post 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!
Use the FU!!!!!IN Google !

gto's Zeos Quick Start Guide

Te Amo Taís!
tygrys
Junior Boarder
Junior Boarder
Posts: 33
Joined: 09.12.2005, 18:31
Location: Poland

Post by tygrys »

Look at the ProviderName property of CDS and TDatasetProvider.

Tygrys
Post Reply