Solved

Instance and floopy

Posted on 1997-09-09
2
304 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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi - replicating a form 8 74
When I am typing into a TEdit last word repeats 7 134
Error E2158 compiling with Delphi XE10 Seattle 2 100
Wincontrol not (correctly) drawn 15 38
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

777 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