Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Instance and floopy

Posted on 1997-09-09
2
Medium Priority
?
310 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 800 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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 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 tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

722 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