was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

36 Visitors Online


 
...Zellinhalte eines TStringGrids in die Zwischenablage kopieren/ einfügen?
Autor: anAKiN
[ Tip ausdrucken ]  

Tip Bewertung (29):  
     


uses
  
Clipbrd;

//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;

 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners