Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Instance and floopy

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses
Course of the Month12 days, 14 hours left to enroll

971 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