L
lcl_003
Unregistered / Unconfirmed
GUEST, unregistred user!
代码如下,有几个地方不太明白,有注释。
另外这段代码是让手工选择程序的路径。但是我想让我的程序自动运行,那该如何做呢?
还用获得程序的当前路径吗?
procedure TForm1.Button1Click(Sender: TObject);
var
Reg: TRegistry;
AppFileName: PChar;
begin
if Edit1.Text='' then
begin
MessageBox(Handle,'应用程序名称不可以为空。','错误',MB_OK+MB_ICONERROR);
Exit;
end;
// 初始化AppFileName ,这个appfilename有啥用?
GetMem(AppFileName,256);
Edit1.GetTextBuf(AppFileName,256);
//gettextbuf是啥意思?那256呢?
Reg:=TRegistry.Create;
try
Reg.RootKey:=HKEY_LOCAL_MACHINE;
if (Reg.OpenKey('Software/Microsoft/Windows/CurrentVersion/Run',False))=True then
begin
// 在注册表中添加数值
Reg.WriteString('StartUp1',AppFileName);
//又一个appfilename
end
else
MessageBox(Handle,'打开注册表失败。','错误',MB_OK+MB_ICONERROR);
finally
Reg.CloseKey;
Reg.Free;
FreeMem(AppFileName);
end;
end;
另外这段代码是让手工选择程序的路径。但是我想让我的程序自动运行,那该如何做呢?
还用获得程序的当前路径吗?
procedure TForm1.Button1Click(Sender: TObject);
var
Reg: TRegistry;
AppFileName: PChar;
begin
if Edit1.Text='' then
begin
MessageBox(Handle,'应用程序名称不可以为空。','错误',MB_OK+MB_ICONERROR);
Exit;
end;
// 初始化AppFileName ,这个appfilename有啥用?
GetMem(AppFileName,256);
Edit1.GetTextBuf(AppFileName,256);
//gettextbuf是啥意思?那256呢?
Reg:=TRegistry.Create;
try
Reg.RootKey:=HKEY_LOCAL_MACHINE;
if (Reg.OpenKey('Software/Microsoft/Windows/CurrentVersion/Run',False))=True then
begin
// 在注册表中添加数值
Reg.WriteString('StartUp1',AppFileName);
//又一个appfilename
end
else
MessageBox(Handle,'打开注册表失败。','错误',MB_OK+MB_ICONERROR);
finally
Reg.CloseKey;
Reg.Free;
FreeMem(AppFileName);
end;
end;