Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle large String Grids?

Tags:

delphi

I find that I might have to use a String Grid of less than 10 columns, but about 50k rows.

Experiments have showed it to be a very unresponsive CPU hog.

Any pointers?

Code or components?

Preferably Delphi (7) build in or TMS (for which I have a license) or FOSS (for commercial use).


Update: please don't just tell me to use Virtual Tree View, etc. Please tell me why, so that I can learn something. Thanks.

like image 497
Mawg says reinstate Monica Avatar asked Jan 05 '11 01:01

Mawg says reinstate Monica


2 Answers

I don't think the problem came from adding this number to the TStringGrid.

Adding 100k rows took less than 1 second (700ms) (Not high end PC, just Dual Core).

procedure TForm1.btn1Click(Sender: TObject);
Const
  arr : array[1..5] of string = ('One','Two','Three','Four','Five');
  Rows = 100000;
var
  I: Integer;
  F,E : Integer;
begin
  StringGrid1.RowCount := Rows;
  F := GetTickCount;
  for I := 0 to Rows do
  begin
    StringGrid1.Cells[1,I] := Arr[1] + IntToStr(I);
    StringGrid1.Cells[2,I] := Arr[2]+ IntToStr(I);
    StringGrid1.Cells[3,I] := Arr[3]+ IntToStr(I);
    StringGrid1.Cells[4,I] := Arr[4]+ IntToStr(I);
    StringGrid1.Cells[5,I] := Arr[5]+ IntToStr(I);
  end;
  E := GetTickCount;
  ShowMessage(Inttostr(E-F));
end;

I think the slowness in your code, do you bring the data from database? if so this is will be the bottleneck of your code, also adding 50k to WHATEVER GRID to show for users called "Bad practice".

And it's hard to tell you why that's slow without showing any code.

like image 161
Mohammed Nasman Avatar answered Oct 04 '22 22:10

Mohammed Nasman


The TListView component in virtual mode is recommended frequently (I have not tried it myself but it sounds rather easy to implement)

like image 25
mjn Avatar answered Oct 04 '22 22:10

mjn