Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

pointers ?

1 view
Skip to first unread message

Sean

unread,
Feb 28, 2002, 5:57:58 AM2/28/02
to
Hi,

I am using a TTreeView control which has a Data pointer for each item.
How do you determine if this pointer points to an object ?

ta,
S


Ian Kirk

unread,
Feb 28, 2002, 6:08:19 AM2/28/02
to
"Sean" <Mc...@Consultant.com> wrote in message news:3c7e0d0e_1@dnews...

> Hi,
>
> I am using a TTreeView control which has a Data pointer for each item.
> How do you determine if this pointer points to an object ?

There'll only be an object pointed to if you set Data yourself; otherwise
you can set it to Nil to indicate that there's no object (I think it
defaults to Nil anyway, but why take chances?). If you free the object
before the tree node's removed, set Data back to Nil to reflect this.

Ian


Mike Orriss (TeamB)

unread,
Feb 28, 2002, 6:28:14 AM2/28/02
to
In article <3c7e0f27_1@dnews>, Ian Kirk wrote:
> If you free the object
> before the tree node's removed, set Data back to Nil to reflect this.
>

It could be implied from your answer that the object is freed
automatically when the node is removed.

I would just like to ensure that impression is not reached. Also a good
place to free an object is via the OnDeletion event handler, which fires
for each node.


Mike Orriss (TeamB and DevExpress)


Arioch /BDV/

unread,
Feb 28, 2002, 6:35:35 AM2/28/02
to
Hello, Mike!

You wrote on Thu, 28 Feb 2002 11:28:14 GMT:

>> If you free the object before the tree node's removed, set Data back
>> to Nil to reflect this.

MOT> It could be implied from your answer that the object is freed
MOT> automatically when the node is removed.

I wonder why FreeAndNil functionality is not embedded into .Free method and
into Dispose/FreeMem procedures.

With best regards, . E-mail:

Ian Kirk

unread,
Feb 28, 2002, 6:47:44 AM2/28/02
to
"Mike Orriss (TeamB)" <m...@3kcc.co.uk> wrote in message
news:VA.00002980.08a33bed@pcmike1...

Good point Mike, that certainly wasn't my intent, but I can see how it could
easily be read that way!

Ian


Pablo Messana

unread,
Feb 28, 2002, 8:12:01 AM2/28/02
to
you must only to question

if TreeView.Selected.Data <> nil then // if the pointer points an object
begin
.....
end
else // if the data pointer was not assigned
begin
..
end;

"Sean" <Mc...@Consultant.com> schrieb im Newsbeitrag
news:3c7e0d0e_1@dnews...

Tony

unread,
Feb 28, 2002, 8:40:37 AM2/28/02
to
Depends that on whether the object pointed to by data has been freed.
In that case you must set data to nil or you'll get an access
violation.


Please keep spamming my email account. I don't mind because I don't read it.
"Cure Spammers for ever, Shoot the b*st**ds" Tony

Jan Emil Larsen

unread,
Feb 28, 2002, 9:23:33 AM2/28/02
to

"Gary Williams" <gwtem...@yahoo.com> skrev i en meddelelse
news:3c7e3c4b$1_2@dnews...
>
> "Arioch /BDV/" <the_A...@yahoo.com> wrote in message
> news:3c7e15fc$1_1@dnews...
> Because very often, the programmer will have many things pointing to the
> same object in memory. It is wrong for any component to assume it owns
> anything it points to and can delete them at will, since the object being
> pointed to may have a broader scope than that of the component pointing to
> it.

But doesn't Free do exactly that: disposes the memory (a.m.o.t), but keeping
"self" pointing at it?


Gary Williams

unread,
Feb 28, 2002, 9:18:55 AM2/28/02
to

"Arioch /BDV/" <the_A...@yahoo.com> wrote in message
news:3c7e15fc$1_1@dnews...

Because very often, the programmer will have many things pointing to the


same object in memory. It is wrong for any component to assume it owns
anything it points to and can delete them at will, since the object being
pointed to may have a broader scope than that of the component pointing to
it.

-Gary

Gary Williams

unread,
Feb 28, 2002, 9:54:08 AM2/28/02
to

"Jan Emil Larsen" <j...@g-it.dk> wrote in message news:3c7e3d66_2@dnews...

I was referring to components such as TListView, TTreeView, TListBox, etc.
which can have objects attached to items at run-time. I mis-read the
question. I thought the poster was asking why TListView, etc. didn't
automatically destroy the objects that were attached to it at run-time.

-Gary


Tony

unread,
Feb 28, 2002, 10:03:19 AM2/28/02
to
That's a fundamental design issue. If you have more than one reference
to an object, one of them must be 'in charge' and the only one that
frees the memory. I have an enormous distrust of this method as it's a
PITA to maintain and a regular generator for a/vs. I think it's far
better to use a linking class which is in charge of the multiply
referenced objects and then free the linking class instead of the base
object. You can even implement reference counting in this scheme to
tidy up dynamically.

Mike Orriss (TeamB)

unread,
Feb 28, 2002, 10:06:22 AM2/28/02
to
In article <3c7e15fc$1_1@dnews>, Arioch /BDV/ wrote:
> I wonder why FreeAndNil functionality is not embedded into .Free method and
> into Dispose/FreeMem procedures.
>

Because it can't. An object does not know anything about the pointer to
itself. Besides, there may be more than one pointer.

Mike Orriss (TeamB)

unread,
Feb 28, 2002, 10:06:23 AM2/28/02
to
In article <3c7e2ca9_1@dnews>, Pablo Messana wrote:
> you must only to question
>
> if TreeView.Selected.Data <> nil then // if the pointer points an object
> begin
> ......
> end
>

That is not foolproof.

After:

TObject(TreeView.Selected.Data).Free;


Then Data still points to where the object used to be. If there is any
possibility of Data being referenced again, it must be set to nil.

mm

unread,
Feb 28, 2002, 11:48:01 AM2/28/02
to
Maybe a kind of "SetPointer" method should be included into the TObject
class to create the double link between objects and pointers. In deed its
quite cumbersome making sure that a pointer is really still pointing to a
valid object and this throughout the code.
At least Assigned(P) should do it not just check that P is not NIL.

Matheus

"Mike Orriss (TeamB)" <m...@3kcc.co.uk> ha scritto nel messaggio
news:VA.00002981.096aeeb2@pcmike1...

Mike Orriss (TeamB)

unread,
Feb 28, 2002, 12:11:50 PM2/28/02
to
In article <3c7e5f45_1@dnews>, Mm wrote:
> Maybe a kind of "SetPointer" method should be included into the TObject
> class to create the double link between objects and pointers.
>

Rather a large overhead when it affects *all* objects. Even then it would
not cope with multiple references to the object.

0 new messages