Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to copy and paste TStringGrids cells to/from ClipBoard Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
05-Apr-03
Category
VCL-General
Language
Delphi 3.x
Views
158
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: William Gerbert

How to copy/paste TStringGrids cells to/from ClipBoard

Answer:

1   uses
2     Clipbrd;
3   
4   //Copy  
5   
6   procedure TForm1.Button1Click(Sender: TObject);
7   var
8     S: string;
9     GRect: TGridRect;
10    C, R: Integer;
11  begin
12    GRect := StringGrid1.Selection;
13    S := '';
14    for R := GRect.Top to GRect.Bottom do
15    begin
16      for C := GRect.Left to GRect.Right do
17      begin
18        if C = GRect.Right then
19          S := S + (StringGrid1.Cells[C, R])
20        else
21          S := S + StringGrid1.Cells[C, R] + #9;
22      end;
23      S := S + #13#10;
24    end;
25    ClipBoard.AsText := S;
26  end;
27  
28  //Paste 
29  
30  procedure TForm1.Button2Click(Sender: TObject);
31  var
32    Grect: TGridRect;
33    S, CS, F: string;
34    L, R, C: Byte;
35  begin
36    GRect := StringGrid1.Selection;
37    L := GRect.Left;
38    R := GRect.Top;
39    S := ClipBoard.AsText;
40    R := R - 1;
41    while Pos(#13, S) > 0 do
42    begin
43      R := R + 1;
44      C := L - 1;
45      CS := Copy(S, 1, Pos(#13, S));
46      while Pos(#9, CS) > 0 do
47      begin
48        C := C + 1;
49        if (C <= StringGrid1.ColCount - 1) and (R <= StringGrid1.RowCount - 1) then
50          StringGrid1.Cells[C, R] := Copy(CS, 1, Pos(#9, CS) - 1);
51        F := Copy(CS, 1, Pos(#9, CS) - 1);
52        Delete(CS, 1, Pos(#9, CS));
53      end;
54      if (C <= StringGrid1.ColCount - 1) and (R <= StringGrid1.RowCount - 1) then
55        StringGrid1.Cells[C + 1, R] := Copy(CS, 1, Pos(#13, CS) - 1);
56      Delete(S, 1, Pos(#13, S));
57      if Copy(S, 1, 1) = #10 then
58        Delete(S, 1, 1);
59    end;
60  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC