Re:TTreeview, TTreeNode Data Field
"Bob" <B...@nowhere.com> skrev i melding
news:975441649.61871@jerusalem.magic.fr...
Quote
> Hi,
> I'm using a TTreeview to store data and i'd like to associate a
TStringGrid
> to save additional info about some of the nodes. I'm wondering if it
was
> possible to use the Data property of the node to save a pointer on a
> particular row of my TStringGrid.
> Not all the nodes have a TStringGrid line associate so i'll check a
'nil'
> data property to see if there is some.
> Does somebody di such a thing or something similar
If you want to make it simple, you could typecast the Data pointer to a
record:
TGridRef = packed record
Col: Word
Row: Word;
end;
...and store the references to the grid like this:
var
ARec: TGridRef;
ANode: TTreeNode;
HasGridRow: boolean
begin
// Create ANode
// Add data to StringGrid1
if HasGridRow then begin
ARec.Col:=StringGrid1.Col;
ARec.Row:=StringGrid1.Row;
ANode.Data:=Pointer(integer(ARec));
end;
var
ARec: TGridRef;
ANode: TTreeNode;
HasGridRow: boolean
begin
[...]
HasGridRow:=ANode.Data <> nil;
if HasGridRow then begin
ARec:=TGridRec(integer(ANode.Data));
StringGrid.Col:=ARec.Col;
StringGrid.Row:=ARec.Row;
end;
..i'm not 100% sure whether you need to typecast via integer, or if a
TGridRec will typecast to pointer...
...just beware that if you use a grid with no header, the upper left
cell will be Col=0, Row=0, which, typecasted to a Pointer is...nil. In
that case, bias either Col or Row or Both with 1.
--
Bjoerge Saether
Consultant / Developer
Asker, Norway
bsaether.removet...@online.no (remove the obvious)