實用的文章,網吧助手做實例講解:
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(SoftwareMicrosoftwindowsCuRRentVersionRun,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:=;