お知らせ

電子会議

ライブラリ

パレット

Delphi FAQ検索

Delphi FAQ一覧

サンプル蔵





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

"stringGridの行の挿入/削除"



StringGridに行を挿入したり、削除したりします。
使用例は
挿入
    insRows(StringGrid1,
           StringGrid1.selection.Top,
           StringGrid1.selection.bottom-StringGrid1.selection.top+1);
削除
  Delrows(stringGrid1,
      stringGrid1.selection.top,
      stringGrid1.selection.bottom);
インターフェースが違いますが、実際この様な引数の方が使いやすいんではない
かと思ました。
列に関してもわずかの修正で対応できると思います。



//挿入
procedure insRows(theGrid:TStringGrid;InsAt,InsCount:Integer);
var
   i:integer;
begin
   if InsCount<1 then Exit;
   if InsAt<0 then Exit;
   with theGrid do
   begin
      RowCount:=RowCount+InsCount;
      For i:=RowCount-1 downTo InsAt+InsCount do
      begin
         Rows[i].assign(Rows[i-InsCount]);
      end;
      For i:=InsAt to InsAt+InsCount-1 do
      begin
         Rows[i].clear;
      end;
   end;
end;

//行を削除
procedure DelRows(theGrid:TStringGrid;DelFrom,DelTo:integer);
var
   i,buf,delItemCount:integer;
begin
   if DelFrom>DelTo then
   begin
      buf:=DelFrom;
      DelFrom:=DelTo;
      DelTo:=buf;
   end;
   with theGrid Do
   begin
      if DelFrom>RowCount-1 then Exit;
      if DelTo>rowcount-1 then DelTo:=rowcount-1;
      if DelFrom<fixedRows then DelFrom:=fixedRows;
      delItemCount:=DelTo-DelFrom+1;
      if (RowCount=FixedRows+1) or
         (RowCount-delItemCount<=FixedRows) then //特殊なケース
      begin
         Rows[FixedRows].Clear;
         if DelFrom<=RowCount-1 then delItemCount:=delItemCount-1;
      end
      else
      begin
         For i:=DelTo+1 to RowCount-1 do
         begin
              Rows[i-delItemCount].assign(Rows[i]);
         end;
      end;
      RowCount:=RowCount-delItemCount;
   end;
end;
☆☆☆ サンプル蔵ブラウザUp!see nifty:FDELPHI/LIB/5/116  ☆☆☆
                                 98/04/11(土) 13:13 凛(MXB01744)

Original document by 凛              氏 ID:(MXB01744)


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

Copyright 1996-2002 Delphi Users' Forum