Solved

Trouble closing a file

Posted on 2000-05-17
6
151 Views
Last Modified: 2010-04-04
I'm running a dll from d5 that sometimes aborts before closing a file.  I don't have anyway within the dll to clean up things.   Is there a way from d5 to close the file?   I general run the dll many times from d5 but have to restart my d5 program if the dll aborts.

It's no problem detecting and trapping the openfile problem but I don't know how to clean things up from d5 without restarting the d5 program.  Any help would be appreciated.
0
Comment
Question by:sartwj
6 Comments
 
LVL 1

Expert Comment

by:sistudio041900
ID: 2817214
there are 2 things to help you D5help

Reset(F);

try
 ...  // process file F
finally
  // will always be called, even if code
  // after try fails
  CloseFile(F);
end;

finalization

will be called when Dll unloads, make sure you close all open files








0
 
LVL 3

Expert Comment

by:smurff
ID: 2817496
Ive had a similar problem, i used this:


procedure KillApp(title : string);
var h : HWND;

begin
h:=FindWindow(nil,@(title)[1]);
if h<>0 then
        begin
        SendMessage(h,WM_CLOSE,0,0);
        Showmessage('App terminated.')
        end
        else
        Showmessage('failed kill app.')
end;

//to close notepad,
KillApp('Notepad');
Hope this helps
Smurff
0
 

Author Comment

by:sartwj
ID: 2817767
smurff,

Unfortunately by the time I make a check on the opened file I've already performed a FreeLibrary() on the dll so FindWindow always returns 0.  The only thing left open is the improperly closed file.  I've also tried leaving the dll open until I'm completely done with it and let your procedure KillApp stop the dll when needed, but that doesn't do it either.   Any other ideas.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 20

Expert Comment

by:Madshi
ID: 2820097
Is it your own dll? Do you have the sources?
0
 

Author Comment

by:sartwj
ID: 2821277
I own the dll - it's a large FORTRAN program compiled as a dll.  When it works, it works well.  But when it fails...it leaves opened files in limbo.

I've never found the right compiler options (on the FORTRAN side) to ignore fatal errors and just close normally.
0
 
LVL 20

Accepted Solution

by:
Madshi earned 100 total points
ID: 2821614
Okay, you will probably not like this idea, but it should work:
How about writing another very little executable, that does nothing but take some parameters and load/unload that fortran dll? Your main executable could then execute that other mini executable. When the mini executable finishes, all handles are automatically closed by Windows.

Regards, Madshi.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
error 1.1 400 Bad request idhttp delphi 18 199
Tembedded WB animatid gifs not animated on some pcs 2 85
Wincontrol not (correctly) drawn 15 47
Twebbrowser add css to the header 3 37
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question