Page 1 of 1
Any possible shortcuts
Posted: Wed 24 Apr 2013 08:47
by oz8hp
I need to take a record from a table, change the value of one field and write the data back as a new record.
For now the table has 47 fields so I am very interested if there are any shortcuts here. Else it will be a very long code to do the task

Re: Any possible shortcuts
Posted: Wed 24 Apr 2013 13:00
by AndreyZ
You can use the code like the following:
Code: Select all
var
Values: array of variant;
i: integer;
begin
UniQuery1.SQL.Text := 'select * from tablename';
UniQuery1.Open;
SetLength(Values, UniQuery1.FieldCount);
for i := 0 to UniQuery1.FieldCount - 1 do
Values[i] := UniQuery1.Fields[i].Value;
UniQuery1.Append;
for i := 0 to UniQuery1.FieldCount - 1 do
UniQuery1.Fields[i].Value := Values[i];
UniQuery1.FieldByName('ID').AsInteger := New_PK_Value; // the new value for the Primary Key field
// other modifications
UniQuery1.Post;
end;
Re: Any possible shortcuts
Posted: Fri 26 Apr 2013 10:21
by oz8hp
Looks like a plan - I will try to work with that
Thanks
Re: Any possible shortcuts
Posted: Sat 27 Apr 2013 07:44
by AndreyZ
I am glad to help. If any other questions come up, please contact us.