Hello. I'm using a TStringGrid. For each row, I need to display data from a database record. For the most part, that is working fine. I also need to store the record id in the grid, but not make it visible. The record key is an integer.
So I store this value like this, for example:
var SomeRecordID : integer;
When I try to reference that same object I just added, it returns a 0 because the object is not assigned.
showmessage(inttostr(integer(stringgrid1.Rows[gridrow].Objects))); //objects is nil yet I just added it!
So, I guess my question is, once I add an object, how do I read that same object? I've done something similar using a TListview before, so I don't understand what makes this different.
Don't use AddObject(), just set the Object of an existing cell in the row, eg:
StringGrid1.Rows[GridRow].Objects := TObject(somerecordid);
Which is really just a wrapper for the grid's own Objects property:
StringGrid1.Objects[0, GridRow] := TObject(somerecordid);
Thanks. That got me out of a bind as usual. Works great.