Board index » delphi » Duplicating records D4 & Paradox

Duplicating records D4 & Paradox

I have a Delphi 4 app that uses Paradox files,  about 10 tables, each
having quite a few fields.  I want to have a "Duplicate Record"
function which will simply append a record into each table that will
be a copy of the current record (all 10 tables being open).  Is there
an easy way to do this?  Can I somehow pass AppendRecord or
InsertRecord a fieldvalue array?  New fields may be added/deleted in
future releases and I want to change as little as possible at that
time, so I don't want to name the fields.

Thanks
Clare
Clar...@usa.net

 

Re:Duplicating records D4 & Paradox


There was a thread in this NG dealing with this subject on Jul 20 - Best way
to copy table record. Several solutions are described. If you can't find the
thread using your newsreader, try dejanews.com.

Quote
Clare <Clar...@usa.net> wrote in message

news:37a738fb.7160114@news.interpac.net...
Quote
> I have a Delphi 4 app that uses Paradox files,  about 10 tables, each
> having quite a few fields.  I want to have a "Duplicate Record"
> function which will simply append a record into each table that will
> be a copy of the current record (all 10 tables being open).  Is there
> an easy way to do this?  Can I somehow pass AppendRecord or
> InsertRecord a fieldvalue array?  New fields may be added/deleted in
> future releases and I want to change as little as possible at that
> time, so I don't want to name the fields.

> Thanks
> Clare
> Clar...@usa.net

Re:Duplicating records D4 & Paradox


Quote
>I want to have a "Duplicate Record" function

I solved this by making a TQuery (qryDupe) which will stay put on the record
which I want to duplicate, then I use qryDupe.Fields[i].FieldName to get the
field an copy. Very simple!

procedure TTemplate.btnDuplicateClick(Sender: TObject);
var i, oldid, newid: integer;
     sql: string;
begin

oldid := Edittable.FieldByName(keyfield).value;
newid := DM.CreateNewID(EditTable, KeyField);{ of autoincrement }

//make new cursor with tQuery qryDupe:
try
qryDupe.Close;
qryDupe.SQL.Clear;
sql := 'select * from ' +   Edittable.Tablename + ' where ' + keyfield + '='
+ InttoStr(oldID);
qryDupe.SQL.Add(sql);
qryDupe.Open;

{ set new record }
EditTable.Insert;
EditTable.FieldByName(KeyField).value := newid;

for i := 0 to qryDupe.FieldCount - 1 do
    if UpperCase(qryDupe.Fields[i].FieldName) <> UpperCase(KeyField) then
       EditTable.Fields[i].value := qryDupe.Fields[i].value;

except
qryDupe.Close;
EditTable.Cancel;
end;

qryDupe.Close;
end;
---------------------
Hope this helps
CU
WS

Other Threads