Recent

Author Topic: How to copy TDataSet record with ftMemo fields?  (Read 2524 times)

vladvons

  • Jr. Member
  • **
  • Posts: 65
How to copy TDataSet record with ftMemo fields?
« on: October 20, 2013, 02:26:54 pm »
I want to save and paste all fields in DataSet record, so i use 'array of variant' as backup storage.

No problem reading DataSet fields into an array, but after writing values back from array into a DataSet all fields with ftMemo type remains empty.

Code: [Select]
procedure TDmRefItem.CloneRecord(aDataSet: TDataSet);
var
  i: Integer;
  ArrBackUp: array of Variant;
begin
  SetLength(ArrBackUp, aDataSet.FieldCount);
  for i := 0 to aDataSet.FieldCount - 1 do
     ArrBackUp[i] := aDataSet.Fields[i].Value 

  aDataSet.Append();

  for i := 0 to aDataSet.FieldCount - 1 do
  begin
    if (aDataSet.Fields[i].DataType = ftMemo) then
      aDataSet.Fields[i].Value :=  ArrBackUp[i]
      //aDataSet.Fields[i].AsString :=  ArrBackUp[i];
      //aDataSet.Fields[i].Text :=  ArrBackUp[i];
    else
      aDataSet.Fields[i].Value :=  ArrBackUp[i]
  end;
end;
 
« Last Edit: October 20, 2013, 05:13:47 pm by vladvons »
Windows 7, Ubuntu 12.04, Lazarus 1.2.2, FPC 2.6.4, PostgreSQL 9.2

vladvons

  • Jr. Member
  • **
  • Posts: 65
Re: How to copy TDataSet record with ftMemo fields?
« Reply #1 on: October 21, 2013, 02:19:32 pm »
Even simle assignment string variable to memo field does nothing.
Lets assume that aDataSet.FieldByName('Descr').DataType is ftMemo, then following code doest work properly
Code: [Select]
aDataSet.FieldByName('Descr').Value := 'My string';
String1 := aDataSet.FieldByName('Descr').Value;
// String1 is 'Null' now
 
« Last Edit: October 21, 2013, 02:21:45 pm by vladvons »
Windows 7, Ubuntu 12.04, Lazarus 1.2.2, FPC 2.6.4, PostgreSQL 9.2

LacaK

  • Hero Member
  • *****
  • Posts: 605
Re: How to copy TDataSet record with ftMemo fields?
« Reply #2 on: October 21, 2013, 02:39:34 pm »
Can you please post here same simple application, which will show error ? (f.e. using TBufDataSet)

 

TinyPortal © 2005-2018