How to copy field/records from DBgrid to Clipboard?

How does one copy complete records(text only) into clip board programatically (iewith out using ctrl-C key combination)
Thanks venks
LVL 1
venksAsked:
Who is Participating?
 
LischkeConnect With a Mentor Commented:
Actually, a DB memo is the same as a memo with the slight difference that it get its content from a database (and can store it there).

For future answers you can pick the link "accept comment as answer" which is shown on the green bars if nobody has proposed an answern already.

Ciao, Mike
0
 
LischkeCommented:
Well, this is easy. Write a method which collects the text snippets (say separated by tabulators, then you can easily copy them to e.g. Word) and use Clipboard.AsText := CollectedText; to set the clipboard.

Ciao, Mike
0
 
venksAuthor Commented:
I know that.But can you give me the code
(to use it with any table)
thanks
venks
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LischkeCommented:
No problem:

procedure CopyCurrentRecordToClipBoard(Dataset: TDataSet);

var
  I: Integer;
  S: String;

begin
  S := '';
  with Dataset do
  for I := 0 to FieldCount - 1 do
  begin
    if Fields[I].DataType = ftString then S := S + Fields[I].AsString + #9;
  end;
  Clipboard.AsText := S;
end;

Ciao, Mike
0
 
LischkeCommented:
Btw. you may want to strip out the last tabulator character with:

  if S > '' then SetLength(S, Length(S) - 1);

Ciao, Mike
0
 
venksAuthor Commented:
Dear lishke
Thanks
What happens if there is a memo field?
venks
0
 
LischkeCommented:
What memo? Where? As source for the clipboard operation? If yes then it is even simpler:

  Clipboard.AsText := MyMemo.Text;

for all the text or

  Clipboard.AsText := MyMemo.SelText;

just for the selected text.

Ciao, Mike
0
 
venksAuthor Commented:
What i meant was that there could be a DBMemo field.
Thanks for the answer.If you post an answer i will award the points.
thanks
venks
0
 
venksAuthor Commented:
Thanks
venks
0
All Courses

From novice to tech pro — start learning today.