How to write a REG_MULTI_SZ value into the registry in Delphi
April 2010.
procedure kg_WriteStrings(const valueName: string; aStrings: TStrings; oReg:TRegistry) ;
var
p, buffer : PChar ;
i : Integer ;
size : DWORD ;
begin
size := 0 ;
for i := 0 to aStrings.Count - 1 do
Inc(size, Length(aStrings [i]) + 1) ;
Inc (size) ;
GetMem(buffer, size) ;
try
p := buffer ;
for i := 0 to aStrings.count - 1 do
begin
lstrcpy(p, PChar(aStrings [i])) ;
Inc(p, lstrlen (p) + 1)
end;
p^ := #0 ;
SetLastError(RegSetValueEx(oReg.CurrentKey, PChar(valueName), 0, REG_MULTI_SZ, buffer, size)) ;
if GetLastError <> ERROR_SUCCESS then
raise Exception.Create('Unable to write MULTI_SZ value') ;
finally
FreeMem(buffer)
end
end;