Here, you can find an example for a general-purpose function to copy data from a TDataSet descendant component into a TRtcDataSet structure for use with RTC Remote Functions. Please note that you might have to update the RTC_DB2FIELD_TYPE declaration depending on the Delphi version you are using, or chance the way you are mapping Delphi database field types to RTC database field types ...
uses
DB, rtcInfo;
{$include rtcDefs.inc}
const
RTC_DB2FIELD_TYPE: array[TFieldType] of TRtcFieldTypes =
( ft_Unknown, ft_String, ft_Smallint, ft_Integer, ft_Word,
ft_Boolean, ft_Float, ft_Currency, ft_BCD, ft_Date, ft_Time, ft_DateTime,
ft_Bytes, ft_VarBytes, ft_AutoInc, ft_Blob, ft_Memo, ft_Graphic, ft_FmtMemo,
ft_ParadoxOle, ft_DBaseOle, ft_TypedBinary, ft_Cursor, ft_FixedChar, ft_WideString,
ft_Largeint, ft_ADT, ft_Array, ft_Reference, ft_DataSet
{$IFNDEF IDE_0}
,ft_OraBlob, ft_OraClob, ft_Variant,
ft_Interface, ft_IDispatch,ft_Guid
{$IFNDEF IDE_1}
, ft_TimeStamp, ft_FMTBcd
{$IFDEF IDE_2006up}
, ft_WideString, ft_WideString, ft_TimeStamp, ft_Variant
{$ENDIF}
{$ENDIF}
{$ENDIF} );
procedure DelphiDataSetToRtc(DelphiDS:TDataSet; rtcDS:TRtcDataSet; ClearFieldDefs:boolean=True);
var
fdef:TFieldDef;
flds:integer;
fldname:string;
field:TField;
begin
if ClearFieldDefs then
begin
rtcDS.Clear;
for flds:=0 to DelphiDS.FieldCount-1 do
begin
fdef:=DelphiDS.FieldDefs.Items[flds];
fldname:=fdef.Name;
rtcDS.SetField(fldname,
RTC_DB2FIELD_TYPE[fdef.DataType],
fdef.Size,
fdef.Required);
end;
end;
DelphiDS.First;
while not delphiDS.EOF do
begin
rtcDS.Append;
for flds:=0 to rtcDS.FieldCount-1 do
begin
fldname:=rtcDS.FieldName[flds];
field:=delphiDS.FindField(fldname);
if assigned(field) then
rtcDS.Value[fldname]:=field.Value;
end;
delphiDS.Next;
end;
end;
DISCLAIMER:
Even though the function shown 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 extract your data from a TDataSet descendant component and copy that data to a TRtcDataSet component, you should use the code example provided above, give it a different name and modify your version to correctly copy all DB Field types you are using with Database Access components of your choice.
Best Regards,
Danijel Tkalcec