Solved

Instance and floopy

Posted on 1997-09-09
2
306 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

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!

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 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