掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
複数のTStringListを、そのうち一つのStringListのソートの結果と同じ並び順でソートするには (ID:151545)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
StringGrid にデータは入れない var StringList: TStringList; uses StrUtils; procedure TForm1.Button1Click(Sender: TObject); begin Memo1.Lines.Add('A'); StringList.Sort; Memo1.Lines.Add('B'); StringGrid1.Invalidate; StringGrid2.Invalidate; StringGrid3.Invalidate; end; procedure TForm1.FormCreate(Sender: TObject); var I,J: Integer; ITEM: TDATA_ITEM; begin StringGrid1.OnDrawCell := StringGrid1DrawCell; StringGrid2.OnDrawCell := StringGrid1DrawCell; StringGrid3.OnDrawCell := StringGrid1DrawCell; //--------------------------- // 仮データ //--------------------------- StringList := TStringList.Create; J := 200000; for I:=0 to (J-1) do begin ITEM := TDATA_ITEM.Create; ITEM.TEXT1 := 'A' + IntToStr(I); //StringGrid1 用 ITEM.TEXT2 := 'B' + IntToStr(I); //StringGrid2 用 ITEM.TEXT3 := 'C' + IntToStr(I); //StringGrid3 用 StringList.AddObject(RightStr('000000' + IntToStr(J-I),6) , ITEM); end; StringGrid1.RowCount := J; StringGrid2.RowCount := J; StringGrid3.RowCount := J; //--------------------------- // 編集しないのなら不要 //--------------------------- StringGrid1.Options := StringGrid1.Options + [goEditing]; StringGrid2.Options := StringGrid1.Options + [goEditing]; StringGrid3.Options := StringGrid1.Options + [goEditing]; StringGrid1.OnSetEditText := StringGrid1SetEditText; StringGrid2.OnSetEditText := StringGrid1SetEditText; StringGrid3.OnSetEditText := StringGrid1SetEditText; StringGrid1.OnGetEditText := StringGrid1GetEditText; StringGrid2.OnGetEditText := StringGrid1GetEditText; StringGrid3.OnGetEditText := StringGrid1GetEditText; end; procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); var I: Integer; ITEM: TDATA_ITEM; begin for I:=0 to StringList.Count - 1 do begin ITEM := TDATA_ITEM(StringList.Objects[I]); ITEM.Free; end; StringList.Free; end; procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: LongInt; Rect: TRect; State: TGridDrawState); var ITEM: TDATA_ITEM; TEXT: String; StringGrid: TStringGrid; begin ITEM := TDATA_ITEM(StringList.Objects[AROW]); if (ACOL = 1) and (AROW <> 0) then begin if Sender = StringGrid1 then TEXT := ITEM.TEXT1; if Sender = StringGrid2 then TEXT := ITEM.TEXT2; if Sender = StringGrid3 then TEXT := ITEM.TEXT3; TStringGrid(Sender).Canvas.FillRect(Rect); TStringGrid(Sender).Canvas.TextRect(Rect,Rect.Left,Rect.Top,TEXT); end; end; procedure TForm1.StringGrid1GetEditText(Sender: TObject; ACol, ARow: LongInt; var Value: string); var ITEM: TDATA_ITEM; begin ITEM := TDATA_ITEM(StringList.Objects[AROW]); if Sender = StringGrid1 then Value := ITEM.TEXT1; if Sender = StringGrid2 then Value := ITEM.TEXT2; if Sender = StringGrid3 then Value := ITEM.TEXT3; end; procedure TForm1.StringGrid1SetEditText(Sender: TObject; ACol, ARow: LongInt; const Value: string); var ITEM: TDATA_ITEM; begin ITEM := TDATA_ITEM(StringList.Objects[AROW]); if Sender = StringGrid1 then ITEM.TEXT1 := Value; if Sender = StringGrid2 then ITEM.TEXT2 := Value; if Sender = StringGrid3 then ITEM.TEXT3 := Value; end;
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.