Although there is a huge amount that is the same for Delphi and C++ Builder developers between VCL and FireMonkey, one thing that has changed is the FireMonkey grids.

[caption id="attachment_201" align="alignnone" width="300" caption="FireMonkey Grid Example"]FireMonkey Grid Example[/caption]

After a recent question at an event, I thought I would put a little demo together to help understand some of the changes that come with the new style grid in FireMonkey.

Having come from a VCL background and having used grids for years, the new style of grid tripped me up at first as I was expecting them to work in the same way as the old VCL style grid that allowed you to load in data and then just leave it. - One major problem with the old approach was memory! Can you imaging loading in 1000 images to memory so you can just leave them in the grid incase the end user wants to scroll that far down?

The FireMonkey grid approach only loads the data that is shown on screen. This dramatically improves the scalability of the grids and removes potential bottlenecks in your application load time.

This also makes it easier to manage the data outside the grid: You can start (for example) using sort algorithms on object lists; use the Move methods of object lists etc and the grid just shows everything in the correct order with very little effort! This makes coding using the new style FireMonkey grid a lot simpler, as these type of changes don't encourage coding that references methods for clearing and reloading the grids all the time. - I for one, certainly find that a lot easier to read and like the fact it encourages separation of business and display logic.

Before we go any further, the demo source code for the Grid example I've done is available using the following link from code central

With the grids, there are two key events to code:

procedure TGrid.GetValue(Sender: TObject; const Col, Row: Integer;
var Value: Variant);

procedure TGrid.SetValue(Sender: TObject; const Col, Row: Integer;
const Value: Variant);

OnGetValue is used to read in for a column and row the value
OnSetValue is used for updating your object with the value from the grid.

The other useful call is that to TGrid.Realign - You can call this once you have managed the objects externally to ensure the grid redraws. This allows multiple changes to run before you update the grid to ensure that the process runs as quickly as possible without the grid constantly trying to update changes.

I also love the ability to embed controls into the grid which is a lot easier than the OwnerDraw work we had to do before. This coupled with the different grid columns really does make for quite a useful grid indeed.

Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder. Design. Code. Compile. Deploy.

Start Free Trial   Free Delphi Community Edition   Free C++Builder Community Edition   Upgrade Today  

  • Also, make sure you have Update 4 hotfix 1 installed. This fixed a few issues with the grid.
  • I don't see any sluggishness in the scrolling or when adding items. I've just tried adding the following to have 1000 records in the grid and it adds exceptionally quickly and scrolls OK. The point is that it doesn't manage the items in the grid, its outside the grid, so its only ever showing what is in view at anyone time. procedure TForm3.Button2Click(Sender: TObject); var I : Integer; begin if MyStuffList = nil then MyStuffList := TObjectList.Create; I := 0; while I < 1000 do begin MyStuffList.Add(TMyStuff.Create(MyStuffList.Count+1)); Inc(I); end; Grid1.RowCount := MyStuffList.Count; Grid1.Realign; end;
  • Why is scrolling so slugish when the items are gets more than what can be displayed. Same goes with the Add Item button its response becomes slower and slower very soon.
  • Thanks a lot Steven for this very useful demo. You're right, it is different way how to think about vizualize your data. We all must learn how to separate logic and presentation. This will simplify develop multi-tier and multi platform applications.