Friday, November 23, 2007

Clone Record (Delphi)

procedure CloneRecord(Dataset: TDataSet);
var
aField : Variant;
i : Integer;
begin

// Create a variant Array
aField := VarArrayCreate([0,DataSet.Fieldcount-1],VarVariant);

// read values into the array
for i := 0 to (DataSet.Fieldcount-1) do
aField[i] := DataSet.fields[i].Value ;

DataSet.Append ;

// Put array values into new the record
for i := 0 to (DataSet.Fieldcount-1) do
DataSet.fields[i].Value := aField[i] ;

end;

3 comments:

evilripper said...

thanks for info!! :-D

Unknown said...

Hi,

I recently came across your blog and have been reading along. I thought I would leave my first comment. I don't know what to say except that I have enjoyed reading.

Nice blog. I will keep visiting this blog very often.

-
Delphi development

Yash said...

i think assign data field into variant type is not good..

The Variant type is used for variables that can change type at run time. Variants offer greater flexibility, but consume more memory than regular variables

so, must specified data type and assign them in same data type variabels, CMIIW