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 Get all Environment Strings 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
22-Nov-02
Category
System
Language
Delphi 2.x
Views
73
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			 Author: Jonas Bilinkevicius

Sometimes you want to show the user the current settings on his/her machine. One of 
the vital information are the Environment Strings. The Windows API gives us an 
efficient set of funcitons to access these

Answer:

Solve 1:

Actually, it is really easy to access the Windows Environment Strings. The Windows 
API defines a function called "GetEnvironmentStrings" to return a double-null 
terminated buffer filled with null terminated strings seperating all environment 
variables. 

The following procedure will takes a string list as parameter and fill it with all 
environment variables returned. It will parse the buffer string by string, setting 
a pointer behind every string returned in order to retrieve the next one. 

I hope this will help you. 

1   procedure LoadEnvironmentStrings(Strings: TStrings);
2   var
3     AllStrings, CurrentString: PChar;
4   begin
5     AllStrings := GetEnvironmentStrings;
6     try
7       if AllStrings <> nil then
8       begin
9         CurrentString := AllStrings;
10        while True do
11        begin
12          Strings.Add(StrPas(CurrentString));
13          Inc(CurrentString, Succ(StrLen(CurrentString)));
14          if CurrentString[0] = #0 then
15            Break;
16        end;
17      end;
18    finally
19      FreeEnvironmentStrings(AllStrings);
20    end;
21  end;



Solve 2:

22  GetEnvStringsList(TStringList(Memo1.Lines));
23  
24  procedure GetEnvStringsList(EnvStr: TStringList);
25  var
26    PEnv, PCopyEnv: pchar;
27  begin
28    EnvStr.Clear;
29    PEnv := GetEnvironmentStrings;
30    PCopyEnv := PEnv;
31    if PCopyEnv <> nil then
32      repeat
33        EnvStr.Add(StrPas(PCopyEnv));
34        inc(PCopyEnv, StrLen(PCopyEnv) + 1);
35      until PCopyEnv^ = #0;
36    FreeEnvironmentStrings(PEnv);
37    PCopyEnv := nil;
38  end;


			
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