Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
On which storage is you application? Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
30-Jan-03
Category
System
Language
Delphi All Versions
Views
15
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			 Author: Christian Cristofori

Sometimes, when you develop a software you need to disable the execution of the 
code from certain types of media, for example, if your application uses a database 
file, you can't write on it if it's located on a CR-ROM.
How to manage this in a easy way? There's the solution.

Answer:

Just write down these short routines:

1   function IsOnHDD: boolean;
2   begin
3     result := GetDriveType(pChar(uppercase(copy(ParamStr(0), 1, 3)))) = DRIVE_FIXED;
4   end;
5   
6   function IsOnCD: boolean;
7   begin
8     result := GetDriveType(pChar(uppercase(copy(ParamStr(0), 1, 3)))) = DRIVE_CDROM;
9   end;
10  
11  function IsOnRemoveable: boolean;
12  begin
13    result := GetDriveType(pChar(uppercase(copy(ParamStr(0), 1, 3)))) = 
14  DRIVE_REMOVABLE;
15  end;


The use them in your project file (.DPR) like this:

16  program Project1;
17  
18  uses
19    Windows, // Added manually
20    SysUtils, // Added manually
21    Dialogs, // Added manually
22    Forms,
23    Unit1 in 'Unit1.pas' {Form1};
24  
25  {$R *.RES}
26  
27  function IsOnCD: boolean;
28  begin
29    result := GetDriveType(pChar(uppercase(copy(ParamStr(0), 1, 3)))) = DRIVE_CDROM;
30  end;
31  
32  begin
33    Application.Initialize;
34    if IsOnCD then
35    begin
36      ShowMessage('This program cannot be executed from a CD-ROM drive.');
37      Application.Terminate;
38    end
39    else
40    begin
41      Application.CreateForm(TForm1, Form1);
42      Application.Run;
43    end;
44  end.


This program will not start if located on a CD-ROM. And no other code than the 
necessary one will be executed.

Christian Cristofori

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC