Any possible shortcuts

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
oz8hp
Posts: 151
Joined: Mon 18 Feb 2008 13:28
Location: Denmark
Contact:

Any possible shortcuts

Post by oz8hp » Wed 24 Apr 2013 08:47

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 :)

AndreyZ

Re: Any possible shortcuts

Post by AndreyZ » Wed 24 Apr 2013 13:00

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;

oz8hp
Posts: 151
Joined: Mon 18 Feb 2008 13:28
Location: Denmark
Contact:

Re: Any possible shortcuts

Post by oz8hp » Fri 26 Apr 2013 10:21

Looks like a plan - I will try to work with that

Thanks

AndreyZ

Re: Any possible shortcuts

Post by AndreyZ » Sat 27 Apr 2013 07:44

I am glad to help. If any other questions come up, please contact us.

Post Reply