Link to home
Start Free TrialLog in
Avatar of Zonnald
Zonnald

asked on

Destroying Forms.

(A) and (B) are two forms.

I have been using createnew to create a form (B) just before the call to its (B) Show method.  When the form  (B) is closed I then call form(B).release method upon returning to the calling form (A).

I find, by using the 'UBEAUT' new IDE enhancement in DELPHI 3, that the db components (table, datasource,query) have not been freed (as they report as a pointer - not NIL).  This of course means that the form (B) cannot then be freed.

So in the form (B) I have included calls to the various db component's Destroy methods.  I had hoped that this would allow the form (B) to *DIE*.  No such luck.

Next time I need to open this form (B) I check if it is NIL and  if so recreate it.  But it is not NIL so I attempt to access a component (such as a label for changing the forms title or what ever) and BANG the label has a NIL pointer and therefor causes a ACCESS VIOLATION and messes up the application.

Of course one could just leave the form 'ALIVE' until the next time it is needed but this application has some 30 forms and uses  25%-40% of system resources.  I would like to know if it is normal for responsible PC programmers to want to uses a few resource at any one time as possible by  destorying invisible forms or have I spend too much time over the years programming on machines with < 1meg or memory
Avatar of mirek071497
mirek071497

Some source please. I think so you must use :  B.Free;
this is from Delphi help, so i think that you play more with source.

"..The CreateNew method creates a new instance of the current form type without reading any state information from resource files or .DFM files. The form is blank, with no controls and all properties at their default. It can be used in place of Create to bypass loading of the associated form file..."
I think so when You call release the form was freed but valiable not setted to nil. try :
  B.Release;
  B := nil;
Why are you sure that they aren't freed? Pointers usually aren't set to NIL when memory is freed, so this may be your problem.
You are calling the Show-methode so the form is modeless, right?
You can't call free, release etc. because you don't know when the form is closed.
You must write this statement in B's FormClose-event:

Action := caFree;

This will free the form from meory and release all of B's controls/components.

-Torfinn

Avatar of Zonnald

ASKER

Thanks,

The form is modal an I have tried caFree.

With regard to AvonWyss' comment - if it isn't NIL how does one know whether or not it need to be recreated.

Anyway I think that maybe **Win95** may actually be at fault (but don't tell BILL)

I know it is not free as I check using the WATCHES and various other neat debugging tools

Thanks again
ASKER CERTIFIED SOLUTION
Avatar of sperling
sperling

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Zonnald

ASKER

Thanks I'll try this.

Zonnald