const
FIELD_DELIMITER = #9;
RECORD_DELIMITER = #10;
procedure CopyDBGridToClipboard( Grid : TDBGrid );
var
BM : String;
S : String;
S1: String;
I : Integer;
begin
with Grid do begin
if Assigned( DataSource ) and
Assigned( DataSource.DataSet ) and
DataSource.DataSet.Active then
with DataSource.DataSet do begin
S := '';
DisableControls;
BM := BookMark;
for I := 0 to Pred( Columns.Count ) do begin
if Assigned(Columns.Items[I].Field) then
S := S + Columns.Items[I].Title.Caption + FIELD_DELIMITER;
end;
S[ Length( S ) ] := RECORD_DELIMITER;
First;
while not Eof do begin
S1 := '';
for I := 0 to Pred( Columns.Count ) do begin
if Assigned(Columns.Items[I].Field) then
S1 := S1 + FieldByName( Columns[I].FieldName ).AsString +
FIELD_DELIMITER;
end;
S1[ Length( S1 ) ] := RECORD_DELIMITER;
S := S + S1;
Next;
end;
BookMark := BM;
EnableControls;
// Clipboard.SetTextBuf( PChar( S ) );
SendToClipboard( S );
end;
end;
end;
|