Solved

Instance and floopy

Posted on 1997-09-09
2
302 Views
Last Modified: 2010-04-04
Delphi expert,

How can I detect whether another instance is running or not ?

How can I check whether a floopy disk is write protect or not ?

Andrew
0
Comment
Question by:andrewyu
  • 2
2 Comments
 
LVL 1

Accepted Solution

by:
anilms earned 200 total points
ID: 1344537
1. As HPrevInst does not work anylonger, there are three different ways of finding out whether there is another instance running. They are :
  a. Get the Window Class Name from the application and do a find window class name - classical VC++ way of doing it.
  b. The functions RegisterClass, GetClass, FindClass can be used. This works properly for Streaming classes.
  c. The practical way is to put an entry in the registry and update the values. I give an example. Create a form with a label on it. Add the necessary code as given below and run the application. Please read the Tregistry details in the help file for proper explanation of functions:

{uses - add Registry to the list}

var
  Form1: TForm1;
  IReg : TRegIniFile;
  CurInstances:integer;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
     IReg := TregIniFile.Create('Test App');
     CurInstances := Ireg.ReadInteger('Running','Instances',0)+1;
     IReg.WriteInteger('Running','Instances',CurInstances);
     Label1.Caption := IntToStr(CurInstances)+' Instances Running';

end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
     CurInstances := Ireg.ReadInteger('Running','Instances',0)-1;
     IReg.WriteInteger('Running','Instances',CurInstances);
end;

end.

The above code will tell you how many instances of the application are already running.  Instead of integer, you can use bool and decide whether to run multiple instances or nor.

2. To find whether a disk is write protected or not or whether a network drive is read only or not - can be achieved with a simple function. In fact we use the same function for our workflow automation system. I give an example to check whether the disk in DDrive A is read only or read/write.

function drivetest:boolean;
{returns true is you can write to it, false if it is read only}
var chkfile:textfile;
begin
     assign(chkfile,'a:\chk');
{$I-}rewrite(chkfile);{$I+}
     if ioresult<>0 then drivetest := false else
     begin
          deletefile('c:\chk\');
          drivetest := true;
     end;
end;

We just simply write a check file. Setting $I- tells the compiler that we are going to do our own IO error handling. This function
is a straight carry over since the early days of Turbo Pascal and still works fine with Delphi
0
 
LVL 1

Expert Comment

by:anilms
ID: 1344538
Function DriveTest : The statement Assign should be changed to AssignFile
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

759 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

24 Experts available now in Live!

Get 1:1 Help Now