0
votes

I'm attempting to use a TGrid in the Delphi Firemonkey GUI library and I'm falling pretty badly on my face here.

At this point in time, I have a TGrid in my form which three cells, a string cell, and 2 checkbox cells.

At current execution, the Grid show up, with the three separate columns. However, nothing gets saved to the string cell and the checkbox cells do not appear unless you double click the cell. When you click away from the checkbox cell, the checkbox disappears.

I figure that I'm missing some crucial step here. I found a function for the TGrid class, OnGetValue and OnSetValue. I figure these must have something to do with my problem, but the issue is I have absolutely no idea how to use them.

Each calls for a (Sender: TObject; const ACol: Integer; const ARow: Integer; const Value: TValue)

I'm making an assumption with the sender, like when creating events for other controls, you're passing in self as the parameter of Sender. ACol and ARow are pretty obvious. But I'm lost with the TValue parameter, as I can't seem to figure out what the heck TValue is. Embarcadero provides this documentation for TValue, but it doesn't tell me a lot that is useful.

At this point, I'm just trying to simply get a cell to show its value and not lose its value when you click away. I know I must be missing something, but I just don't know where to look. It feels like all the questions on this website and others relating to TGrid for Delphi are grossly outdated (I've seen them stretching all the way back to 2003).

1
On a side-note, I'm not sure how you're seeing these dating back to 2003, Firemonkey didn't even exist back then.Jerry Dodge
Perhaps it wasn't Firemonkey, I just see stuff relating to TGrid going way back and when I try looking for the methods those people mentioned they no longer exist.Zulukas
The answer to this question is Delphi code that shows how to use TGrid.Ken White
I ran across that answer and it's pretty vague. I found monkeystyler.com/guide/TGrid which was a tad bit more useful.Zulukas

1 Answers

4
votes

I eventually found this this guide.

Long story short, the data is NOT held within the TGrid (which seems awful backwards to me, but I can now understand why).

In order to get data to show up, you need two events for the TGrid object itself (not the columns):

OnGetValue and OnSetValue

OnGetValue requests the data from the data structure, therefore it takes a row and column to locate the data within your structure. It puts this into the GUI for you.

OnSetValue does the opposite, it supplies to your structure data from the GUI with a row and column.

Hope this can help someone in the future, it took me a while to find out what Embarcadero didn't bother telling you, or pointing you at least somewhere to look.

Define these two methods similarly as to how is explained in the guide.