お知らせ

電子会議

ライブラリ

パレット

Delphi FAQ検索

Delphi FAQ一覧

サンプル蔵





FDelphi FAQ
16番会議室「玉石混淆みんなで作るSample蔵」に寄せられたサンプル

"StringGridのCopy&Paste"





■StringGridの選択セル内容をClipBoardにCopy、ClipBoardからPaste。
  use に 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;

//--------------------------------------------------------------------------
適当ですが、一応動きます(^^;

                   _/_/   Athena ( VYH00522 )  _/_/





Original document by Athena          氏 ID:(VYH00522)


ここにあるドキュメントは NIFTY SERVEの Delphi Users' Forum の16番会議室「玉石混淆みんなで作るSample蔵」に投稿されたサンプルです。これらのサンプルはボーランド株式会社がサポートする公式のものではありません。また、必ずしも動作が検証されているものではありません。これらのサンプルを使用したことに起因するいかなる損害も投稿者、およびフォーラムスタッフはその責めを負いません。使用者のリスクの範疇でご使用下さい。

Copyright 1996-2002 Delphi Users' Forum