Board index » delphi » Record Cloning or Insert New Record using data from currently selected record

Record Cloning or Insert New Record using data from currently selected record

I am trying to add a clone record function to my dbNavigator that will
Insert and new record using the data from currently selected record
within the same table.

Does anyone have any code or an Idea how to proceed?

Brooks Vaughn

 

Re:Record Cloning or Insert New Record using data from currently selected record


On Mon, 13 Sep 1999 18:10:41 -0400, Brooks Vaughn <bvau...@ftc.gov>
wrote:

Quote
>I am trying to add a clone record function to my dbNavigator that will
>Insert and new record using the data from currently selected record
>within the same table.

>Does anyone have any code or an Idea how to proceed?

>Brooks Vaughn

Here's some code posted by a fellow TeamB member a while ago:

function CopyRecord(Table:TTable):boolean;
var
  buf:PChar;
begin
  GetMem(buf,Table.TRecordSize);
  try
    Table.GetCurrentRecord(buf);
    Result := DBIInsertRecord(Table.DBHandle,dbNoLock, Buf);
 finally
   FreeMem(buf);
 end;

end;

Steve F (Team B)

Re:Record Cloning or Insert New Record using data from currently selected record


Are you sure it correctly handles BLOBs?

--
Paul Motyer
SoftStuff
PO Box 637, Croydon, VIC, Australia, 3136

Steve Fischkoff (TeamB) <fischk...@compuserve.com> wrote in message

Quote
> >I am trying to add a clone record function to my dbNavigator that will
> >Insert and new record using the data from currently selected record
> >within the same table.
> Here's some code posted by a fellow TeamB member a while ago:

> function CopyRecord(Table:TTable):boolean;
> var
>   buf:PChar;
> begin
>   GetMem(buf,Table.TRecordSize);
>   try
>     Table.GetCurrentRecord(buf);
>     Result := DBIInsertRecord(Table.DBHandle,dbNoLock, Buf);
>  finally
>    FreeMem(buf);
>  end;

> end;

Re:Record Cloning or Insert New Record using data from currently selected record


Quote
>Are you sure it correctly handles BLOBs?

For copying blob fields to try something like this

procedure CopyRecord(tbl: TTable);
  var
    I: Integer;
    tblTmp: TTable;
  begin
    blTmp := TTable.Create(nil);
    try
      tblTmp.DatabaseName := tbl.DatabaseName;
      tblTmp.TableName := tbl.TableName;
      tblTmp.Open;
      ttblTmp.GotoCursor(Src);
      tbl.Insert;
      try
        for I := 0 to T.FieldCount-1 do
          tbl.Fields[I].Assign(tblTmp.Fields[I] );
      except
        tbl.Cancel;
        raise;
      end;
    finally
      tblTmp.Free;
    end;
  end;

--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Other Threads