Página 1 de 1

How to work with TRegistry class?

Publicado: Dom Abr 29, 2007 11:57 am
por Gejza Horvath
Hi,
please help me, how to use the TRegistry class. The help file contains no information
about using this class.
I need read the text value of VemaRoot property in the HKEY_LOCAL_MACHINESoftwareVema
key
Thanks
Gejza Horvath

How to work with TRegistry class?

Publicado: Dom Abr 29, 2007 1:00 pm
por notelo
Gejza,
> please help me, how to use the TRegistry class. The help file contains no information
> about using this class.
Check if your help file is updated since this component is documented from
many time ago.
> I need read the text value of VemaRoot property in the HKEY_LOCAL_MACHINESoftwareVema
> key
#include "WinReg.api"
WITH OBJECT TRegistry():Create()
:Root := HKEY_LOCAL_MACHINE
IF :OpenKey( "SoftwareVema"
cText := :GetString( "VemaRoot", "MyDefaultValue" )
:CloseKey()
ENDIF
END
Regards,
José Lalí­n

How to work with TRegistry class?

Publicado: Mar May 01, 2007 7:38 am
por Gejza Horvath
José,
it seems, your example is not complete.
in the line
> IF :OpenKey( "SoftwareVema"
is somthing missing.
I put 2 edit boxes on the form, getting the key name from oEdit1 and the desired item name
from oEdit2.
I'm using the next code to test the TRregistry class:
---------------------------------------------
METHOD Button1Click( oSender ) CLASS TForm1
LOCAL oReg, cString,nError,aKeys
WITH OBJECT oReg := TRegistry():Create()
:Root := HKEY_LOCAL_MACHINE
IF nError := :OpenKey( ::oEdit1:Value) > 0
cString := :GetString( ::oEdit2:Value, "MyDefaultValue" )
aKeys := :EnumKeys()
MessageBox(Self,"Error code: " + TRANSFORM(:nLastError,"999") + CRLF +;
"Number of items:" + TRANSFORM(LEN(aKeys),"999"))
:CloseKey()
ELSE
MessageBox(Self,"Error opening Registry Key: " + TRANSFORM(nError,"999"))
ENDIF
END
::oLabel1:cText := cString
---------------------------------------------
My problem:
I tried many keys from my Registry, the result is always the same
- cString is "MyDefaultValue"
- LEN(aKeys) is zero
Any advise?
Gejza Horvath
"José Lalín" <notelo@digo.com> pí¹e v diskusním pøíspìvku
news:46347afe$[email=1@ozsrv2.ozlan.local...]1@ozsrv2.ozlan.local...[/email]
>
> Gejza,
>
>> please help me, how to use the TRegistry class. The help file contains no information
>> about using this class.
>
> Check if your help file is updated since this component is documented from many time
> ago.
>
>> I need read the text value of VemaRoot property in the HKEY_LOCAL_MACHINESoftwareVema
>> key
>
> #include "WinReg.api"
>
> WITH OBJECT TRegistry():Create()
> :Root := HKEY_LOCAL_MACHINE
> IF :OpenKey( "SoftwareVema"
> cText := :GetString( "VemaRoot", "MyDefaultValue" )
> :CloseKey()
> ENDIF
> END
>
> Regards,
> José Lalín
>

How to work with TRegistry class?

Publicado: Mar May 01, 2007 7:51 am
por Gejza Horvath
And the :nLastError is always 1.
Gejza Horvath

How to work with TRegistry class?

Publicado: Mar May 01, 2007 6:16 pm
por notelo
Gejza,
I have just tested this example and it works as expected:
---
#include "WinReg.api"
METHOD Button1Click( oSender ) CLASS TForm1
LOCAL cName
WITH OBJECT TRegistry():Create()
:Root := HKEY_LOCAL_MACHINE
IF :OpenKey( "SoftwareMicrosoftWindowsCurrentVersion" ) == 0
cName := :GetString( "ProductName" )
:CloseKey()
ENDIF
:Destroy()
END WITH
MsgInfo( cName )
RETURN Nil
---
Check it and let me know.
Regards,
José Lalí­n

How to work with TRegistry class?

Publicado: Mié May 02, 2007 5:16 am
por Gejza Horvath
José,
your code doesn't works for me. The value "ProductName" doesn't exist in Registry on my
computer, I used ProductId and the result is empty cName.
May be the problem is somwhere in my computer?
My project is attached, the oButton1 on TForm1 tests this class.
Gejza Horvath
"José Lalín" <notelo@digo.com> pí¹e v diskusním pøíspìvku
news:[email=46376824@ozsrv2.ozlan.local...]46376824@ozsrv2.ozlan.local...[/email]
>
> Gejza,
>
> I have just tested this example and it works as expected:
>
> ---
> #include "WinReg.api"
>
> METHOD Button1Click( oSender ) CLASS TForm1
>
> LOCAL cName
>
> WITH OBJECT TRegistry():Create()
> :Root := HKEY_LOCAL_MACHINE
> IF :OpenKey( "SoftwareMicrosoftWindowsCurrentVersion" ) == 0
> cName := :GetString( "ProductName" )
> :CloseKey()
> ENDIF
> :Destroy()
> END WITH
>
> MsgInfo( cName )
>
> RETURN Nil
> ---
>
> Check it and let me know.
>
> Regards,
> José Lalín
>


Attached files Rezia.zip (14.3 KB)Â

How to work with TRegistry class?

Publicado: Mié May 02, 2007 11:15 am
por jfgimenez
Gejza,
> your code doesn't works for me. The value "ProductName" doesn't exist in
> Registry on my computer, I used ProductId and the result is empty cName.
> May be the problem is somwhere in my computer?
>
> My project is attached, the oButton1 on TForm1 tests this class.
The code at line 93 in HlavneOkno.prg is:
IF nError := :OpenKey( ::oEdit1:Value) > 0
and should be:
IF nError := :OpenKey( ::oEdit1:Value) == 0
Note that OpenKey() returns 0 if ok.
--
Regards,
Jose F. Gimenez
http://www.xailer.com
http://www.xailer.info

How to work with TRegistry class?

Publicado: Mié May 02, 2007 2:28 pm
por Gejza Horvath
Thanks José,
your support is quick and fantastic, I would like tu buy the product next week.
Best regards
Gejza Horvath
"Jose F. Gimenez" <jfgimenez@wanadoo.es> pí¹e v diskusním pøíspìvku
news:4638569e$[email=1@ozsrv2.ozlan.local...]1@ozsrv2.ozlan.local...[/email]
> Gejza,
>
>> your code doesn't works for me. The value "ProductName" doesn't exist in Registry on my
>> computer, I used ProductId and the result is empty cName.
>> May be the problem is somwhere in my computer?
>>
>> My project is attached, the oButton1 on TForm1 tests this class.
>
> The code at line 93 in HlavneOkno.prg is:
>
> IF nError := :OpenKey( ::oEdit1:Value) > 0
>
> and should be:
>
> IF nError := :OpenKey( ::oEdit1:Value) == 0
>
> Note that OpenKey() returns 0 if ok.
>
> --
> Regards,
>
> Jose F. Gimenez
> http://www.xailer.com
> http://www.xailer.info
>
>