Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3045
  • Last Modified:

Delphi TStringGrid cells to store multiple objects

Hi,

I am writing a program which has 12 records in it, each with different data content.  I want to use a grid (i.e. TStringGrid) to store the records in cells.

I want to be able to store say records R1, R3, R8 in cell 1, records R5, R3, R10 in cell 2 etc.  in other words I need the grid cell to be able to reference multiple objects.

Then, when I click on a cell a message dialogue will appear listing the objects stored in the particular cell clicked, with a printout of the record data.

I know I can use StringGrid.Objects[ACol, ARow] := Obj; to reference a single object but how can I store and access multiple objects for a cell?

I am new to Delphi so I need some help with this if anyone has any ideas.  I am open to any suggestions including 3rd party components.

Thanks in advance.
0
engdmorr
Asked:
engdmorr
  • 2
  • 2
1 Solution
 
pritaeasSoftware EngineerCommented:
You can create an object-list in StringGrid.Objects[ACol, ARow]. In this list you can then store your objects.
0
 
engdmorrAuthor Commented:
So, I can use object Lists, but how to I separate the object list when I want to read an individual cell by clicking on it?  StringGrid1.Objects[ACol, ARow] only returns a TObject, I want to be able, when I click on the cell, to retrieve individual objects with its data, something like this.

if Objects.Items[i] is R1 then
  begin
    Memo1.lines.add('R1 is here');
   ...
  end;

Any ideas?
0
 
pritaeasSoftware EngineerCommented:
TObjectList itself is an object in a gridcell.
Create it like: StringGrid.Objects[ACol, ARow] := TObjectList.Create(True);

Then you can use:

if TObjectList(StringGrid.Objects[ACol, ARow])[i] is R1 then begin .. end;

TObjectList has a count property you can use i think.

See here for an example: http://www.festra.com/wwwboard/messages/1881.html
0
 
engdmorrAuthor Commented:
Never used TObjectList before, looks like an excellent feature of Delphi, thanks for the help, just what I was looking for.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now