RTC Forums

Dashboard => Quick Start => Topic started by: D.Tkalcec (RTC) on September 03, 2011, 12:19:34 PM

Title: How to copy data from a TRtcDataSet object into a TDataSet component?
Post by: D.Tkalcec (RTC) on September 03, 2011, 12:19:34 PM
Below, you will find an example for a general-purpose function to copy data from a TRtcDataSet structure into a TDataSet descendant component. Please note that you might have to update the RTC_FIELD2DB_TYPE declaration depending on the Delphi version you are using, or change the way you are mapping RTC database field types to Delphi database field types to make it more Delphi version independent ...

  DB, DBClient, rtcInfo;

{$include rtcDefs.inc}

  RTC_FIELD2DB_TYPE: array[TRtcFieldTypes] of TFieldType =
    ( ftUnknown, ftString, ftSmallint, ftInteger, ftWord,
      ftBoolean, ftFloat, ftCurrency, ftBCD, ftDate, ftTime, ftDateTime,
      ftBytes, ftVarBytes, ftAutoInc, ftBlob, ftMemo, ftGraphic, ftFmtMemo,
      ftParadoxOle, ftDBaseOle, ftTypedBinary, ftCursor, ftFixedChar,
      {$IFDEF IDE_1}
        ftString, // TDataSet in D4 doesn't really support WideString
      ftLargeint, ftADT, ftArray, ftReference, ftDataSet
      {$IFNDEF IDE_1}
        ,ftOraBlob, ftOraClob, ftVariant, ftInterface,
         ftIDispatch,ftGuid, ftTimeStamp, ftFMTBcd
        ,ftBlob, ftMemo, ftString, ftBlob, ftBlob,
        ftString, ftDateTime, ftBcd

procedure RtcDataSetToDelphi(rtcDS:TRtcDataSet; DelphiDS:TDataSet; ClearFieldDefs:boolean=True);
  if ClearFieldDefs then
    for flds:=0 to rtcDS.FieldCount-1 do
    if DelphiDS is TClientDataSet then

  if not DelphiDS.Active then

  while not rtcDS.EOF do
    for flds:=0 to rtcDS.FieldCount-1 do
      if assigned(field) then


Even though the function provided above should work for most field types, it can NOT automatically recognize and translate all field types provided by all Database Access components. This is especially true for Memo and BLOB fields. To correctly copy your data from a TRtcDataSet object to a TDataSet descendant component, you should use the function provided above as your starting point, give it a different name and modify it to work correctly with all DB Field types you are using with Database Access components of your choice.

Best Regards,
Danijel Tkalcec