<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<br>
<div class="moz-cite-prefix">Il 03/09/2014 18:03, Dennis ha scritto:<br>
</div>
<blockquote cite="mid:54073BD9.20808@avidsoft.com.hk" type="cite">
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
<br>
<br>
Giuliano Colla wrote:
<blockquote cite="mid:5406D3EC.2060605@fastwebnet.it" type="cite">
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
<br>
<div class="moz-cite-prefix">Il 03/09/2014 10:17, Dennis ha
scritto:<br>
</div>
<blockquote cite="mid:5406CE99.1070003@avidsoft.com.hk"
type="cite">
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
<div class="moz-text-html" lang="x-unicode"> <font size="+1">when
displaying data in a TStringGrid, I want to associate an
object with each row of the grid so that when later use
select a certain row, I can just determine the selected
row and then retrieve the associate object for further
processing (e.g. display further information of this
object in some controls).<br>
<br>
How do I do that?<br>
<br>
Currently, I use OnSelection (Sender: TObject; aCol,
aRow: Integer) to obtain aRow but how do I associate an
object with each row?<br>
<br>
</font></div>
</blockquote>
<br>
Example:<br>
<br>
StringGrid1.Rows[0].AddObject('some text',anObject);<br>
<br>
Giuliano<br>
</blockquote>
Thanks.<br>
<br>
But I checked, <br>
StringGrid1.Rows[0] is a TStrings<br>
<br>
this line <br>
StringGrid1.Rows[0].AddObject('some text',anObject);<br>
seems to add an object to the last item in this TStrings instead
of just one object for the entire row.<br>
<br>
</blockquote>
<br>
Yes, actually you can associate an object to each Cell, you cannot
associate an object to each Row.<br>
If you need just an Object per row, you must decide in which column
to put it. e.g. you may decide that your object will always be in
column 0.<br>
sort of:<br>
<br>
anObject := TObject.Create;<br>
StringGrid1.Cells[0,0] := 'Some Row Caption';<br>
StringGrid1.Objects[0,0] := anObject;<br>
<br>
Then in your OnSelection, you pick up the Row, but you look only at
the object in column 0.<br>
Sort of:<br>
<br>
procedure TForm1.StringGrid1Selection(Sender: TObject; aCol, aRow:
Integer);<br>
var<br>
myObject: TObject;<br>
begin<br>
if Sender is TStringGrid then begin<br>
myObject := StringGrid1.Objects[0,aRow];<br>
end;<br>
end;<br>
<br>
Giuliano<br>
<br>
</body>
</html>