在单元开始的 uses 里加上 Registry 引用,我这里就创建一个过程吧
这个函数是在要记录控件名称的单元里写的,
procedure RemeberControlName;
var
mReg:Tregistry;
begin
mReg := Tregistry.create;
try
with mReg do
begin
RootKey := HKEY_LOCAL_MACHINE ;
if not KeyExists('System\SoftwareInformation') then
begin
if OpenKey('System\SoftwareInformation',true) then
begin
WriteString('ControlName',name);
end;
end;
finally
mReg.free;
end;
end;
procedure ReadControlName;
var
mReg:Tregistry;
mName :string; //获取控件名称的变量
begin
mReg := Tregistry.create;
try
with mReg do
begin
RootKey := HKEY_LOCAL_MACHINE ;
if OpenKey('System\SoftwareInformation',false) = true then
mName := ReadString('ControlName',name);
end;
finally
mReg.free;
end;
end;