unit AdvoPlex_Object;
interface
uses
Windows,
Classes,
SysUtils,
Registry;
const
ADVOPATH = '
Software\AdvoSolutions\AdvoPlex';
type
TAdvoPlex =
class(TObject)
private
FUserSU:
string;
function CurrentUser:
string;
function GetUserSU:
string;
procedure SetUserSU(Value:
string);
public
constructor Create;
destructor Destroy;
override;
published
property UserSU:
string read GetUserSu
write SetUserSU;
procedure SaveUserSU;
procedure LoadUserSU;
end;
implementation
constructor TAdvoPlex.Create;
begin
inherited Create;
end;
destructor TAdvoPlex.Destroy;
begin
inherited Destroy;
end;
function TAdvoPlex.GetUserSU:
string;
begin
Result := FUserSU;
end;
procedure TAdvoPlex.LoadUserSU;
var
reg: TRegistry;
begin
reg := TRegistry.Create(KEY_READ);
try
reg.RootKey := HKEY_CURRENT_USER;
if reg.OpenKeyReadOnly(ADVOPATH)
then
begin
FUserSU := reg.ReadString('
User');
reg.CloseKey;
end
else
raise Exception.CreateFmt('
%s'+#13#10+'
%s', ['
Fehler beim Lesen von UserSU', SysErrorMessage(GetLastError)]);
finally
reg.Free;
end;
end;
procedure TAdvoPlex.SaveUserSU;
var
reg: TRegistry;
begin
reg := TRegistry.Create(KEY_ALL_ACCESS);
try
reg.RootKey := HKEY_CURRENT_USER;
if reg.OpenKey(ADVOPATH, True)
then
begin
reg.WriteString('
User', FUserSU);
reg.CloseKey;
end
else
raise Exception.CreateFmt('
%s'+#13#10+'
%s', ['
Fehler beim Schreiben von UserSU', SysErrorMessage(GetLastError)]);
finally
reg.Free;
end;
end;
procedure TAdvoPlex.SetUserSU(Value:
string);
begin
FUserSU := Value;
end;
function TAdvoPlex.CurrentUser:
string;
var
Buffer :
array[0..MAX_PATH]
of Char;
Size : DWORD;
begin
Size := SizeOf(Buffer);
GetUserName(Buffer, Size);
SetString(Result, Buffer, lstrlen(Buffer));
end;
end.