我有一个包含10列的TStringGrid。向其中添加500行需要约2秒钟的时间。这种性能表现正常吗?
对我来说,这似乎有点慢。
我从数据库查询中获取数据。如果我循环遍历查询结果但不将结果写入StringGrid,则该过程大约需要100毫秒,因此不是数据库拖慢了速度。
一旦添加了行,StringGrid的性能就很好。
这是我正在使用的代码:
Grid.RowCount := Query.RecordCount;
J := 0;
while not Query.EOF do
begin
Grid.Cells[0,J]:=Query.FieldByName('Value1').AsString;
Grid.Cells[1,J]:=Query.FieldByName('Value2').AsString;
Grid.Cells[2,J]:=Query.FieldByName('Value3').AsString;
// etc for other columns.
Inc(J);
Query.Next();
end;
实际代码要复杂一些(表格列与查询列并不完全对应),但这是基本思路。