gpt4 book ai didi

delphi - 在大型 TStringGrid 的顶行插入

转载 作者:行者123 更新时间:2023-12-03 15:29:45 25 4
gpt4 key购买 nike

我担心这可能是一个“一根绳子有多长”的问题,但想知道是否有人有一些硬数据或建议。

我有一个 TStringGrid,它可能有 3,600 行,也许更多,我们还不确定。由于显示器显然没有足够的空间,因此屏幕上仅显示 20 或 30 行。不幸的是,这些是最先编写的,用户必须向下滚动才能看到添加的行。

颠倒行的顺序可能会更方便用户,即最新的在前,最旧的在最后。为此,我需要执行类似的操作(代码可能不准确)

  // slightly quicker if there are many rows & no flicker
myStringGrid.Visible := False;
rowCount := myStringGrid.RowCount;
for row := 1 to Pred(rowCount) do
myStringGrid.Rows[row + 1] := myStringGrid.Rows[row];
myStringGrid.RowCount := myStringGrid.RowCount + 1;
// now add new row...
myStringGrid.Cells[1, 0] := <somthing>;
myStringGrid.Cells[1, 1] := <somthing else>;
myStringGrid.Cells[1, 2] := <etc>;
TestRunDataStringGrid.Visible := True;

我担心性能。如果没有人有任何经验,我将编写一个测试并返返回告。

只是想知道是否有人有这样做的经验或意见......

最佳答案

试试这个

type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
---
---
private
{ Private declarations }
public
{ Public declarations }
end;

type
TStringGridHack = class(TStringGrid)
protected
procedure InsertRow(ARow: Longint);
end;

implementation

{$R *.dfm}


procedure TStringGridHack.InsertRow(ARow: Longint);
var
iRow: Integer;
begin
iRow := Row;
while ARow < FixedRows do Inc(ARow);
RowCount := RowCount + 1;
MoveRow(RowCount - 1, ARow);
Row := iRow;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
TStringGridHack(StringGrid1).InsertRow(1);
end;

关于delphi - 在大型 TStringGrid 的顶行插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4591464/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com