I think TcomponentList is inherited from TObjectList so the list members
should be freed when the components are? I've never used either but the help
file reads that way.

So short answer is you probably don't need to clear the list.

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of [EMAIL PROTECTED]
Sent: Tuesday, 11 November 2003 9:21 a.m.
To: Multiple recipients of list delphi
Subject: RE: [DUG]: Close failure

Is the following possible reasoning?

You've added DirMonitor1 to DirMonList.

You free DirMonitor1.

When you call DirMonList.Clear, internally maybe it tries to reference
and free DirMonitor.  Have a look at the source maybe.

One solution might be to cycle through your DirMonList and free all
items yourself.  After that, you shouldn't have to call Clear, but can
should free your DirMonList straight away.

Alternatively, can you use TObjectList and see if it frees contained
objects for you?

Not sure how accurate these are, but maybe some food for thought.

Cheers,

C.

-----Original Message-----
From: Alistair George [mailto:[EMAIL PROTECTED]

Good morning.
Got a problem been bugging my program for ages. It raises its ugly head
sometimes when in the FormCloseQuery event, and is one specific item.
Here goes (shortened for brevity)............

DirMonitor1: TDirMonitor;
DirMonList: Tcomponentlist;

procedure TMainform.DirMonArrayAdd(WatchDir: string);
var Tval: Integer;
  CurrDir, PathVal, NameVal: string;
  DriveVal: Char;
begin
  DirMonitor1 := TdirMonitor.create(self);
  DirMonList.Add(DirMonitor1);
  TDirMonitor(DirMonList.Items[DirMonList.count - 1]).Directory :=
CurrDir;
  TDirMonitor(DirMonList.Items[DirMonList.count - 1]).Onchange :=
DirMonitor1Change;
  TDirMonitor(DirMonList.Items[DirMonList.count - 1]).FilterNotification
:= [nfFILE_NAME, nfSIZE, nfLAST_WRITE];
  TDirMonitor(DirMonList.Items[DirMonList.count - 1]).FilterAction :=
[faADDED, faMODIFIED];
  TDirMonitor(DirMonList.Items[DirMonList.count - 1]).WatchsubTree :=
RxChecklistBox12.Checked[1];
end;

Then in FormCloseQuery I have tried all combinations of below:
//    DirMonArrayStopStart(False); //this tells it to stop monitoring
//    DirMonitor1.Free;
//    DirmonList.Clear;
    FreeandNil(DirMonitor1);
//    FreeandNil(DirMonlist);

DirmonList.Clear; raises an exception every time. With
FreeandNil(DirMonitor1);
being the least offensive.
---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/

---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/

Reply via email to