实用的文章,网吧助手做实例讲解:

procedure TForm1.FormCreate(Sender: TObject);
var
num1,num2:integer;
reg:Tregistry;
nums1:Tstringlist;
nums2:Tstringlist;
I:integer;
begin
list.Clear;
nums1:=Tstringlist.Create;
nums2:=Tstringlist.Create;
reg:=Tregistry.create;
reg.Rootkey:=HKEY_LOCAL_MACHINE;
If reg.OpenKey(SOFTWAREMicrosoftWindowsCurrentVersionRun,false) then
begin
reg.GetValueNames(nums1);
num1:=nums1.Count;
end;
For i:=0 To nums1.Count-1 Do
begin
with list.Items.Add do
begin
caption := nums1[i];
subitems.Add(reg.ReadString(nums1.Strings[i]));
end;
end;
reg.RootKey:=HKEY_CURRENT_USER;
If reg.OpenKey(SoftwareMicrosoftWindowsCurrentVersionRun,false) Then
begin
reg.GetValueNames(nums2);
num2:=nums2.Count;
end;
For i:=0 To nums2.count-1 Do
begin
with list.Items.Add do
begin
caption := nums2[i];
subitems.Add(reg.ReadString(nums2.Strings[i]));
end;
end;
reg.CloseKey;
reg.Free;
end;
//删除所选的项目
procedure TForm1.FlatButton10Click(Sender: TObject);
begin
if Assigned(List.selected) then
begin
Reg:=Tregistry.Create;
Reg.Rootkey:= HKEY_CURRENT_USER;
Reg.OpenKey(SoftwareMicrosoftWindowsCurrentVersionRun,False);
Reg.deleteValue(list.Selected.Caption);
Reg.CloseKey;
Reg.Free;
Reg:=Tregistry.Create;
Reg.Rootkey:= HKEY_LOCAL_MACHINE;
Reg.OpenKey(SoftwareMicrosoftWindowsCurrentVersionRun,False);
Reg.deleteValue(list.Selected.Caption);
Reg.CloseKey;
Reg.Free;
list.DeleteSelected;
end
else
showmessage(请选择您要删除的项目名称!);
end;
//修改
procedure TForm5.FlatButton2Click(Sender: TObject);
var
Reg:Tregistry;
begin
if not (edit1.Text=)then //检查项目名称不为空
if not (edit2.Text=) then//检查项目路径不为空
//如果两者完全不为空,则执行以下代码!
begin
Reg:=Tregistry.Create;
Reg.Rootkey:= HKEY_LOCAL_MACHINE;
Reg.OpenKey(SoftwareMicrosoftCuRRentVersionRun,False);
Reg.WriteString(Edit1.Text,Edit2.text);
Reg.CloseKey;
Reg.Free;
StatusBar1.Panels[0].Text:=网吧助手提醒您:修改启动项目成功!;
end;
if (edit1.Text=)then //检查项目名称是空
begin
StatusBar1.Panels[0].Text:=网吧助手提醒您:项目名称不能为空!;
end;
if (edit2.Text=) then //检查项目路径是空
begin
StatusBar1.Panels[0].Text:=网吧助手提醒您:项目路径不能为空!;
end;
if (edit1.Text=)then //检查项目名称是空
if (edit2.Text=) then //检查项目路径是空
begin
StatusBar1.Panels[0].Text:=网吧助手提醒您:项目名称和路径都不能为空!;
end
end;

procedure TForm5.FlatButton1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
edit2.text:=OpenDialog1.FileName;
if not (edit2.Text=) then
//如果edit2.text不为空的话,则返回Edit2.text的内容到StatusBar里
begin
StatusBar1.Panels[0].Text:=路径 → +edit2.text;
end;
end;

procedure TForm5.FlatButton3Click(Sender: TObject);
begin
edit1.Text:=;
edit2.Text:=;
StatusBar1.Panels[0].Text:=网吧助手提醒您:请执行操作!;
end;

end.

//添加
//把文件读取到Edit2.text中
procedure TForm3.FlatButton1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
edit2.text:=OpenDialog1.FileName;
if not (edit2.Text=) then
//如果edit2.text不为空的话,则返回Edit2.text的内容到StatusBar里
begin
StatusBar1.Panels[0].Text:=路径 → +edit2.text;
end;
end;

//重置,将edit1,edit2,StatusBar初始化
procedure TForm3.FlatButton3Click(Sender: TObject);
begin
edit1.Text:=;
edit2.Text:=;
StatusBar1.Panels[0].Text:=网吧助手提醒您:请执行操作!;

end;

//启动时清空edit1,edit2的内容
procedure TForm3.FormCreate(Sender: TObject);
begin
edit1.Text:=;
edit2.Text:=;