In order for this site to work correctly we need to store a small file (called a cookie) on your computer. Most every site in the world does this, however since the 25th of May 2011, by law we have to get your permission first. Please abandon the forum if you disagree.

Para que este foro funcione correctamente es necesario guardar un pequeño fichero (llamado cookie) en su ordenador. La mayoría de los sitios de Internet lo hacen, no obstante desde el 25 de Marzo de 2011 y por ley, necesitamos de su permiso con antelación. Abandone este foro si no está conforme.

How to work with TRegistry class?

Xailer English public forum
Responder
Gejza Horvath
Mensajes: 281
Registrado: Mar Ago 15, 2006 1:50 pm

How to work with TRegistry class?

Mensaje 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
notelo
Mensajes: 54
Registrado: Sab Abr 28, 2007 2:06 pm

How to work with TRegistry class?

Mensaje 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
Gejza Horvath
Mensajes: 281
Registrado: Mar Ago 15, 2006 1:50 pm

How to work with TRegistry class?

Mensaje 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
>
Gejza Horvath
Mensajes: 281
Registrado: Mar Ago 15, 2006 1:50 pm

How to work with TRegistry class?

Mensaje por Gejza Horvath »

And the :nLastError is always 1.
Gejza Horvath
notelo
Mensajes: 54
Registrado: Sab Abr 28, 2007 2:06 pm

How to work with TRegistry class?

Mensaje 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
Gejza Horvath
Mensajes: 281
Registrado: Mar Ago 15, 2006 1:50 pm

How to work with TRegistry class?

Mensaje 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)Â
Avatar de Usuario
jfgimenez
Site Admin
Mensajes: 5718
Registrado: Lun Abr 06, 2015 8:48 pm
Contactar:

How to work with TRegistry class?

Mensaje 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
José F. Giménez
[Equipo de Xailer / Xailer team]
http://www.xailer.com
http://www.xailer.info
Gejza Horvath
Mensajes: 281
Registrado: Mar Ago 15, 2006 1:50 pm

How to work with TRegistry class?

Mensaje 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
>
>
Responder