?
Solved

How to: From StringGrid to Clipboard (newbie Question)

Posted on 2003-03-06
2
Medium Priority
?
749 Views
Last Modified: 2010-04-04
Basically, If I have a single StringGrid, which the best way to export its contents to clipboard. ie: I need import the contents from Excel.

Is the StringGrid a good alternative ?
If I have a listview (report mode), can I manage it as StringGrid through cols/rows

Thanks in advance
0
Comment
Question by:rdfloc
[X]
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
2 Comments
 

Expert Comment

by:TIgor
ID: 8086107
listenning....
0
 
LVL 5

Accepted Solution

by:
Lukasz Lach earned 200 total points
ID: 8086916
//Copy
procedure TForm1.Button1Click(Sender: TObject);
var
   S:String;
   GRect:TGridRect;
   C,R:Integer;
begin
   GRect:=StringGrid1.Selection;
   S:='';
   for R:=GRect.Top to GRect.Bottom do
   begin
       for C:=GRect.Left to GRect.Right  do
       begin
       if C= GRect.Right then  S:=S+(StringGrid1.Cells[C,R])
         else  S:=S+StringGrid1.Cells[C,R]+#9;
       end;
       S:=S+#13#10;
   end;
   ClipBoard.AsText:= S;
end;

// Paste
procedure TForm1.Button2Click(Sender: TObject);
var
   Grect:TGridRect;
   S,CS,F:String;
   L,R,C:Byte;
begin
   GRect:=StringGrid1.Selection;
   L:=GRect.Left; R:=GRect.Top;
   S:=ClipBoard.AsText;
   R:=R-1 ;
   while Pos(#13,S)>0 do
   begin
       R:=R+1;
       C:=L-1;
       CS:= Copy(S,1,Pos(#13,S));
       while Pos(#9,CS)>0 do
       begin
           C:=C+1;
           if (C<=StringGrid1.ColCount-1)and (R<=StringGrid1.RowCount-1) then
               StringGrid1.Cells[C,R]:=Copy(CS,1,Pos(#9,CS)-1);
               F:= Copy(CS,1,Pos(#9,CS)-1);
           Delete(CS,1,Pos(#9,CS));
       end;
       if (C<=StringGrid1.ColCount-1)and (R<=StringGrid1.RowCount-1) then
               StringGrid1.Cells[C+1,R]:=Copy(CS,1,Pos(#13,CS)-1);
       Delete(S,1,Pos(#13,S));
       if Copy(S,1,1)=#10 then
       Delete(S,1,1);
   end;
end;
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month12 days, 1 hour left to enroll

752 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