Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to copy field/records from DBgrid to Clipboard?

Posted on 2000-03-03
9
240 Views
Last Modified: 2010-04-04
How does one copy complete records(text only) into clip board programatically (iewith out using ctrl-C key combination)
Thanks venks
0
Comment
Question by:venks
  • 5
  • 4
9 Comments
 
LVL 10

Expert Comment

by:Lischke
ID: 2579637
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
 
LVL 1

Author Comment

by:venks
ID: 2579648
I know that.But can you give me the code
(to use it with any table)
thanks
venks
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2579697
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 
LVL 10

Expert Comment

by:Lischke
ID: 2579706
Btw. you may want to strip out the last tabulator character with:

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

Ciao, Mike
0
 
LVL 1

Author Comment

by:venks
ID: 2580294
Dear lishke
Thanks
What happens if there is a memo field?
venks
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2580340
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
 
LVL 1

Author Comment

by:venks
ID: 2580570
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
 
LVL 10

Accepted Solution

by:
Lischke earned 50 total points
ID: 2580603
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
 
LVL 1

Author Comment

by:venks
ID: 2582209
Thanks
venks
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question