Hola buenas tengo un problema al leer un valor del registro de windows, el problema esta en que cuando lo lee no se elimina el buffer y cuando lo vuelvo a leer se repite asi sucesivamente... nose esplicarme mejor espero que alguien me pueda echar una manita.. Gracias.

Código: Seleccionar todo

uses
Windows;

var
  Size: Cardinal;
  hKey: Windows.HKEY;
  Buffer: ShortString;
  Str: string;

 procedure CambiarID(NvoNombre : string);
 function LeerID():string;

implementation


function LeerId(): string;
begin
RegOpenKey(HKEY_CURRENT_USER, 'Software\Microsoft\Windows\CurrentVersion', hKey);
Size := SizeOf(Buffer);
RegQueryValueEx(hKey, 'Nombre', nil, nil, @Buffer, @Size);
Str := Str + string(PChar(@Buffer));
RegCloseKey(hKey);
  Result := (Str);
  if Result = '' then
    Result := 'Jesus';
end;
Me respondo yo mismo..

Código: Seleccionar todo

procedure CambiarID(NvoNombre : string);
function LeerID():string;

var
hKey: Windows.HKEY;
Buffer: ShortString;
implementation


function LeerId(): string;
var
Size: Cardinal;
Str: string;
begin
RegOpenKey(HKEY_CURRENT_USER, 'Software\Microsoft\Windows\CurrentVersion', hKey);
Size := SizeOf(Buffer);
RegQueryValueEx(hKey, 'Nombre', nil, nil, @Buffer, @Size);
Str := Str + string(PChar(@Buffer));
Result := (Str);
RegCloseKey(hKey);
if Result = '' then
Result := 'Jesus';
end;
Por si a alguien le sirve ya que ai poco ejemplo en delphi.
Responder

Volver a “Delphi”