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
--
WWW: http://www.ftpedit.com/kristoffer/
Quote of the day-
The smart thing to do is to begin trusting your intuition. - fc
clayton collie
David Biggins wrote in message ...
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.
>
--