Home > Back-end >  Delphi read registry number string (REG_MULTI_SZ)
Delphi read registry number string (REG_MULTI_SZ)

Time:09-25

Add the Registry in unit
A custom function is as follows:
The function getREG_MULTI_SZ (RSTR, kStr: string) : string;
Var
Myreg: TRegistry;
STemp: string;
Mtype ValueSize: dwords.
ArrChar: an array of char [0.. 200];
I: Integer;
C: char;
The begin
Result:=';
Myreg:=TRegistry. Create; Try
Mtype:=REG_MULTI_SZ;
Myreg. RootKey:=HKEY_LOCAL_MACHINE;//open the registry key, for sure, if you want to open the other primary key, can also define your own, like KSTR, also can change the other primary keys
If myreg. OpenKey (RSTR, false) then
The begin
ValueSize:=sizeof (ArrChar);
RegQueryValueEx (myreg CurrentKey, PChar (KSTR), nil, @ Mtype, @ ArrChar, @ ValueSize);
For I:=0 to 200 do
The begin
C:=ArrChar [I];
While c=# 0 do
The begin
While ArrChar [I + 1] <> # 0 do
The begin
ArrChar: [I]=' ';
break;
end;
break;
end;
end;
STemp:=ArrChar;
Result:=Trim (STemp);
end;
The finally
Myreg. CloseKey;
Myreg. Free;
end;
end;


Call: for example: getREG_MULTI_SZ (' SYSTEM \ CurrentControlSet \ services \ Tcpip \ the Parameters', 'DhcpNameServer)

CodePudding user response:

 USES 
Registry;

Type
TMultiString=array of string;

TMultiRegistry=class (TRegistry)
Public
The function ReadMultiString (const name: string) : TMultiString;
end;

The function TMultiRegistry. ReadMultiString (const name: string) : TMultiString;
Var
RegData: TRegDataType;
Info: TRegDataInfo;
Buffer: pchar;
PTR: pchar;
I: Integer;
The begin
If GetDataInfo (Name, Info) then
The begin
GetMem (buffer, info. DataSize);
ReadBinaryData (name, buffer ^, info DataSize);
PTR:=buffer;
I:=0;
While (PTR ^ & lt;> The do # 0)
The begin
SetLength (the Result, I + 1);
Result: [I]=PTR;
Inc (I);
Inc (PTR, StrLen (PTR) + 1);
end;
FreeMem (buffer);
end;
end;


Inheritance TRegistry, increase function ReadMultiString

The following
 var 
Reg: TMultiRegistry;
V: TMultiString;
I: Integer;
The begin
Reg:=TMultiRegistry. Create;
Try
Reg. RootKey:=HKEY_LOCAL_MACHINE;
If not reg. OpenKey (' SYSTEM \ CurrentControlSet \ services \ Tcpip \ the Parameters', False) then
Exit;
V:=reg. ReadMultiString (' DhcpNameServer ');
The finally
Reg. Free;
end;
For I:=0 to Length (v) - 1 do
The begin
ShowMessage (v [I]);
end;
//HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ services \ ALG
end;

CodePudding user response:

RegQueryValueEx

CodePudding user response:



The true can yo, if you need, please send my QQ, I directly to your
  • Related