1
votes

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.

1
Does assigning an FMX.Grid.TCustomGrid.OnGetValue event method TOnGetValue = procedure(Sender: TObject; const Col, Row: Integer; var Value: System.Rtti.TValue) of object;work? - LU RD
I think there is a OnBeforeDrawing event in TColumn which can be overridden and you can use it to supply content on-the-fly. You can check FMS.Grid to see which methods you can override or hook to. - John Kouraklis
@LURD OnGetValue isn't exposed for TStringGrid and the documentations says it is called when a value is retrieved. I suppose if it were called before the value was retrieved for drawing then it would work. - Mike at Bookup
@JohnKouraklis I'm not finding any documentation on OnBeforeDrawing. I suppose I could hook into OnPaint or OnPainting but even there I'd be setting the values which would over time eat memory as the user scrolled through millions of painted cells. - Mike at Bookup
@MikeatBookup, I don't think it is documented. You will find it in the FMX.Grid unit but you need to subclass the TColumn to make use of it; and then add the new class to the grid. Yes you can use the OnPaint/Painting event. - John Kouraklis

1 Answers

4
votes

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