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

Can a component be created with a nil owner?

18 views
Skip to first unread message

David Biggins

unread,
Sep 29, 1998, 3:00:00 AM9/29/98
to
Dear All

Is is possible to specify 'nil' as an argument to a create method?
I am using FPiettes internet components, which require an argument in the
create method. I was using code as below:

constructor TNetworkInterface.Create;
begin
FRxSocket := TWSocket.Create(Application);
FTxSocket := TWSocket.Create(Application);
end;

destructor TNetworkInterface.Destroy;
begin
FRxSocket.Free;
FTxSocket.Free;
end;

As these are part of a non-visual component, there is no form so using
application seemed to work. Unfortunately, when the application is closing I
got an access violation. This appeared to be due to the Application object
freeing the TWSocket components it owned before freeing the TNetworkinterface
component - therefore FRxSocket etc. were invalid.

Calling the create method as Create(nil) seems to fix this problem. But I am
unsure if this is a valid thing to do? If it is for these particular
components (which are not visible), is it true in general for non-visual
components?


--
David Biggins
Philips Projects
Cambridge UK


Kristoffer Henriksson

unread,
Sep 29, 1998, 3:00:00 AM9/29/98
to
Passing Nil as the owner is perfectly valid. The only consequence that
I am aware of is that you have to free the objects yourself instead of
relying on Delphi to do so.
Cheers,
-Kristoffer

--
WWW: http://www.ftpedit.com/kristoffer/
Quote of the day-
The smart thing to do is to begin trusting your intuition. - fc

clayton collie

unread,
Sep 29, 1998, 3:00:00 AM9/29/98
to
David,
the rule is that the parameter passed to the constructor is responsible
for freeing the component. By setting the owner to NIL, you become
responsible.

clayton collie

David Biggins wrote in message ...

David Biggins

unread,
Sep 29, 1998, 3:00:00 AM9/29/98
to
Clayton / Kristoffer

Thank you for the very quick response. As I want to be able to destroy the
components myself, passing the nil pointer achieves exactly what I want.

I've had these mysterious errors on exit for some time in other parts of my
code and never really understood them - finally an explanation!

Regards

David


In article <6uqv0k$nd...@forums.borland.com>, Clayton collie wrote:
> the rule is that the parameter passed to the constructor is responsible
> for freeing the component. By setting the owner to NIL, you become
> responsible.
>

--

0 new messages