Duplicating records D4 & Paradox 
Author Message
 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



Wed, 18 Jun 1902 08:00:00 GMT  
 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:
> 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




Wed, 18 Jun 1902 08:00:00 GMT  
 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



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Duplicating a record in a Paradox table

2. Paradox indexed fields with duplicate records?

3. duplicate records in join

4. Duplicate Error on insert record

5. Handling Duplicate records

6. Using SQL to delete duplicate records

7. Duplicate records

8. Tracking duplicate records?

9. Duplicate records in Interbase

10. Duplicating Records

11. D4 - Access97 & linked tables

12. D4 & ACCESS

 

 
Powered by phpBB® Forum Software