Search code examples
delphifiremonkey

FireUI's TStringGrid - set the values as it paints


My use of Delphi XE7's FireMonkey TStringGrid has it holding a million rows. Populating the contents of the TStringGrid with millions of strings would consume too much memory.

How does one set the values of the cells as they are painted?

My code would fill in the contents of the cells from a huge temporary file as the cells scrolled into view.

The TurboPower Orpheus TOvcTable component in the legacy version of my app did this with a hook called OnGetCellData(). I don't see anything like that in FireUI's TStringGrid.


Solution

  • Instead of TStringGrid use TGrid with TColumn columns. Then use the OnGetValue event to fetch values for display in the grid. This is closest to the VCLs TDrawGrid.

    procedure TForm1.Grid1GetValue(Sender: TObject; const Col, Row: Integer;
      var Value: TValue);
    begin
      Value := inttostr(col)+', '+inttostr(row);
    end;
    

    Sample result of grid with 10 mio rows:

    enter image description here