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
How to determine which storage your application is on 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
Files Operation
Language
Delphi All Versions
Views
94
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;
16  
17  //The use them in your project file (.DPR) like this:
18  
19  program Project1;
20  
21  uses
22    Windows, // Added manually
23    SysUtils, // Added manually
24    Dialogs, // Added manually
25    Forms,
26    Unit1 in 'Unit1.pas' {Form1};
27  
28  {$R *.RES}
29  
30  function IsOnCD: boolean;
31  begin
32    result := GetDriveType(pChar(uppercase(copy(ParamStr(0), 1, 3)))) = DRIVE_CDROM;
33  end;
34  
35  begin
36    Application.Initialize;
37    if IsOnCD then
38    begin
39      ShowMessage('This program cannot be executed from a CD-ROM drive.');
40      Application.Terminate;
41    end
42    else
43    begin
44      Application.CreateForm(TForm1, Form1);
45      Application.Run;
46    end;
47  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