Solved

Trouble closing a file

Posted on 2000-05-17
6
145 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 20

Expert Comment

by:Madshi
Comment Utility
Is it your own dll? Do you have the sources?
0
 

Author Comment

by:sartwj
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now