Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Still can't terminate my application! - HELP please

Status
Not open for further replies.

nurya

Technical User
Mar 2, 2004
12
ES
Hi everybody,

few days ago I started a Thread about this matter. My problem is that when my Application in Delphi should terminate, the forms are all closed but the process still appears in the Task Manager of Windows.

I use Delphi 7 and Windows XP, and my application comes from the upgrade of another made in Delphi 6. Basicly the only difference between them is that now I use dbExpress and before it ran with BDE.

But the previous version of the application terminated correctly!.

I have tried almost everything, there must be something happening because even with 'Application.Terminate' or 'Halt', the Application continues running!

Also if I write:
'repeat Application.Terminate until Application.Terminated;',
which doesn't make any sense, because I thought that as soon you call Application.Terminate, Application.Terminated swicth to 'True', doesn't it?.

The code for the Delphi Project is as follows:

begin
Application.Initialize;
Application.Run;

InitForm := TInitForm.Create(nil);
try
repeat
if ContinueExecuting then begin
InitForm.Panel.Caption := 'Reseting M2DM Organizer ....';
end else begin
InitForm.Panel.Caption := 'Initiating M2DM Organizer ....';
end;
InitForm.Show;
InitForm.Update;

SMTP_DataModule := TSMTP_DataModule.Create(nil);
ModuloDatos := TModuloDatos.Create(nil);
try
OrganizadorForm := TOrganizadorForm.Create(nil);
try
InitForm.Hide;
OrganizadorForm.ShowModal;
finally
OrganizadorForm.Release;
end;
finally
ModuloDatos.Free;
SMTP_DataModule.Free;
end;
InitForm.Hide;
until not ContinueExecuting;
finally
InitForm.Release;
end;
// Halt; or Application.Terminate; here seem to not be working!
end.


I use dbExpress(TClientDataSet) with TDataSetProvider. The Application uses 18 tables (some of them very large) and for each table there is a TDataSource, a TClientDataSet, a TDataSetProvider and a TSQLDataSet.
The previous version managed only TDataSource and TBDEClientDataSet.
Apart from this, the only difference between them is that I need now two functions to manage Autoincrement fields when inserting new rows in two of the tables.

With all this information, has anybody got any clue, why this is happening to me?

Any suggestions are welcome!

Thank you very much,

Nurya ;-)
 
Hi Nurya,
Does the application terminate properly when you run it from within the Delphi Debugger IDE ?

My only other suggestion would be to run it through some kind of memory profiler (eg. Memory Sleuth) to see if there are any objects that are not be freed.

Come to think of it, I have seen similar behaviour when an application creates a COM object, and when it tries to shutdown the COM object does not release its reference properly, and stops the app from closing normally.

Might give you a few leads...
 
At a glance I just noticed.....

Code:
repeat
  ...
  ...
  ...
until not ContinueExecuting;

But the ContinueExecuting is always true if you are in the repeat loop...

KungTure-RX.jpg

//Nordlund
 
Answering to your questions:

Nordlund: 'ContinueExecuting' turns False when you click on an Exit Button in OrganizadorForm, but remains True if yo click a Reset Button. It's only a flag used to determine when to Reset and when to Exit.

Dachyon: Yes, I think the problem must have something to do with objects that are not properly freed.
The problem remains either when running the application from the Delphi Debugger or directly from the executable file. When running from the Delphi Debugger the execution thread gets to the 'end.' instruction, and keeps here. If I write 'Halt' just before the 'end.', it keeps in the 'Halt' and never get to the next source line.
If I write 'Application.Destroy' or 'Application.Free' I get a runtime error 216 (Access violation).

I'm no expert in Delphi. I have always used the most common options, so do you know how I can debug memory allocation or how I can get (and use) this memory profiler you have suggested?

Thank you both very much,

Nurya ;-)
 
Hi nurya,

I think the main problem lies in the fact that you're having an unusual project setup.

normal program code would be like this :

Code:
program Project1;

uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1};

{$R *.res}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

supposing that form1 is the main form of the application:
any initialization part should be in the onCreate event of form1, and cleanup code in the OnDestroy Event.

just my 2 cents...

--------------------------------------
What You See Is What You Get
 
On second look - I think I agree with Whosrdaddy's diagnosis.
But anyway, I use "Memory Sleuth" from Turbopower
I think you would be better advised to try to use a more standard Delphi project structure. The code you have in the project file can be implemented in the onCreate, and onDestroy events of the various forms in your project, as Whosrdaddy suggests.
 
Dachyon said:
But anyway, I use "Memory Sleuth" from Turbopower

Turbopower is out of business, and no updates seems to be done to this product anymore. The last patch I've seen is version 3.06.

I have discovered a lot of bugs in it, and many more was popping up after I applied the Delphi support pack.
This does the application unusable (For me anyway).

Correct me if I'm wrong (Hope someone does, because it's a very useful application) :)

KungTure-RX.jpg

//Nordlund
 
Thank you all, I'll try to redo the Delphi Project and use a more standard structure.

But in the meantime, could you please take a look at another thread named 'Still can't terminate my application 2 - Thread information!' that I launched on the 6th of December? There is where the specific problem lies, but I don't understand it (debug data).

Once again, thank you so much.

Nurya ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top