Mark wrote:

> Hiya, is there anyone to find out the contents of the previous/next record
> in a dataset without doing a next/prev?  I want to provide the ability to
> 'copy' the previous records field contents to the current record.
>
> Paradox and Database Desktop do this via ctrl-d but delphi's dbgrid
> doesn't and my boss keeps nagging me about the possibility of building
> this in?

Here's the code we added to our own custom TnDatasets to support this.

procedure TnDataSet.DuplicateRecord(DataSet: TDataSet);
{
var
  I: Integer;
}
begin
  Move(TempBuffer^, ActiveBuffer^, RecordSize);
{
  for I := 0 to Fields.Count -1 do
    if Fields[I].FieldKind = fkData then
      DataEvent(deFieldChange, Integer(Fields[I]));
}
  if Assigned(FOnDuplicateRecord) then
    FOnDuplicateRecord(Self);
end;

procedure TnDataSet.Duplicate;
var
  SaveNewRecord: TDataSetNotifyEvent;
begin
  CheckBrowseMode;
  if GetRecord(TempBuffer, gmCurrent, True) = grOK then
    begin
      SaveNewRecord := OnNewRecord;
      OnNewRecord := DuplicateRecord;
      try
        Insert;
      finally
        OnNewRecord := SaveNewRecord;
      end;
    end;
end;

We then added a duplicate button to our TnGridNavigator which calls
Table.Duplicate and we use the OnDuplicateRecord event we added to clear any
fields we don't want coming through.

YMMV,
  Paul.


---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"

Reply via email to