Tipo de valor do registro

Delphi

28/06/2005

Estou fazendo um aplicativo que precise ler e alterar alguns valores no registro. Na parte da leitura ocorre um erro, aqui esta o codigo:

procedure TForm1.FormActivate(Sender: TObject);
begin
  reg:=tregistry.Create;
  with reg do
  begin
    rootkey:=HKEY_LOCAL_MACHINE;
    if OpenKey (´SYSTEM\ControlSet001\Services\{701F69B7-0061-4EC5-8776-713E4C6383C2}\Parameters\Tcpip´,false) then
    gtw:=readstring (´DefaultGateway´);
    ip:=readstring(´IPAddress´);
    label3.caption:=gtw;
    label4.caption:=ip;
    closekey;
    free;
  end;

end;


O erro é o seguinte [color=red:c877dbe4e8]´Invalid data type´[/color:c877dbe4e8]
Creio que seja por causa da funcção readstring que le somente valores do tipo string, o valor que consta nesta chave do registro é do tipo [color=blue:c877dbe4e8]REG_MULT_SZ[/color:c877dbe4e8], sendo assim, como ler um valor deste tipo?


Fernando Lempê

Fernando Lempê

Curtidas 0

Respostas

Beppe

Beppe

28/06/2005

Então terá que usar a API diretamente, RegQueryValueEx. Saberia usá-la?


GOSTEI 0
Fernando Lempê

Fernando Lempê

28/06/2005

Infelizmente não sei como usar, poderia me dar uma ajuda se possivel?

Na verdade essa aplicação é para alterar o ip e o gateway da maquina, então pesquisei no registro as chaves que continham as informações sobre ip e gateway, para isso quero ler e alterar estes valores.


GOSTEI 0
Fernando Lempê

Fernando Lempê

28/06/2005

sobe


GOSTEI 0
Beppe

Beppe

28/06/2005

var
  Key: HKEY;
  Size: Cardinal;
  Data: String;
begin
  with TRegistry.Create do
  try
    RootKey := HKEY_CURRENT_USER;
    if OpenKey(´\´, False) then
    begin
      Size := 0;
      if RegQueryValueEx(CurrentKey, ´Q1´, nil, nil, nil, @Size) = ERROR_SUCCESS then
      begin
        SetLength(Data, Size);
        RegQueryValueEx(CurrentKey, ´Q1´, nil, nil, Pointer(Data), @Size);
        Caption := Data;
        //
      end;
    end;
  finally
    Free;
  end;
end;



GOSTEI 0
POSTAR