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
Pitfalls reading from the Registry (ProxyEnable) 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
24-Aug-02
Category
Win API
Language
Delphi 3.x
Views
45
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas 

Pitfalls reading from the Registry (ProxyEnable)

Answer:

The following has been verified for Delphi 3. It may be slightly different for 
Delphi 5.
In a project I had to read the Boolean field “ProxyEnable” from the registry. It is 
stored in

HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings

On the systems that I work with (NT 4.0/ sp 5, NT 4.0/ sp 6, Win 2000/ sp 1) I 
checked and determined that this value was stored as a REG_DWORD. 0 meant false, 1 
meant true. So I simply coded as shown in 1)

Pitfall 1): Unexpected Entry Type

On some customer machines, the value ProxyEnable was stored as a REG_BINARY. 
Reading a REG_BINARY with ReadInteger() causes an exception – and to make things 
worse, exception handling was not yet in place since it was executed during the 
initialization of my application.

So I changed my code to 2) and hoped it would work.


Pitfall 2): Read the exact length

This was a surprising one. When you have a registry value of type REG_BINARY that 
is 4 bytes long and you try reading it with

ReadBinaryData("MyKey", myBooleanVar, 1);

… then you will experience another exception. The correct code is as shown in part 
3.

1   // Version 1:
2   // raises an exception because of the unexpected entry type
3   
4   ProxyEnabled := ReadBool(sProxyEnable);
5   
6   // Version 2:
7   // detect type with GetDataType(),
8   // but not size... raises an exception if the size is wrong
9   
10  case GetDataType(sProxyEnable) of
11    rdInteger:
12      ProxyEnabled := ReadBool(sProxyEnable);
13    rdBinary:
14      ReadBinaryData(sProxyEnable, ProxyEnabled, 1);
15    // other types..
16  end;
17  
18  // Version 3:
19  // detect type and size (GetDataSize())! Works so far.
20  
21  case GetDataType(sProxyEnable) of
22    rdInteger:
23      ProxyEnabled := ReadBool(sProxyEnable);
24    rdBinary:
25      ReadBinaryData(sProxyEnable, ProxyEnabled, GetDataSize(sProxyEnable));
26    // other types..
27  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