unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, CheckLst, IniFiles, ShlObj, ActiveX, ShellAPI,
XPMan, Mask;type
TForm1 = class(TForm)
Button1: TButton;
Button3: TButton;
Button4: TButton;
CheckListBox1: TCheckListBox;
Button5: TButton;
LabeledEdit1: TLabeledEdit;
LabeledEdit2: TLabeledEdit;
Button6: TButton;
Button7: TButton;
Button8: TButton;
LabeledEdit3: TLabeledEdit;
Button10: TButton;
LabeledEdit4: TLabeledEdit;
Image1: TImage;
procedure listTitle;
procedure Button4Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure CheckListBox1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
num:integer;
ini,numini:Tinifile;
implementation{$R *.dfm}function GetFolder:string;
var
BI: TBrowseInfo;
Buf: PChar;
Dir, Root: PItemIDList;
Alloc: IMalloc;
begin
result:='';
SHGetMalloc(Alloc);
Buf := Alloc.Alloc(Max_Path); // CSIDL_BITBUCKET RecycleBin
// CSIDL_CONTROLS ControlPanel
// CSIDL_DESKTOP Desktop
// CSIDL_DRIVES My Computer
// CSIDL_FONTS Fonts
// CSIDL_NETHOOD Network Neighborhood
// CSIDL_NETWORK The virtual version of the above
// CSIDL_PERSONAL 'Personal'
// CSIDL_PRINTERS printers
// CSIDL_PROGRAMS Programs in the Start Menu
// CSIDL_RECENT Recent Documents
// CSIDL_SENDTO Folder SendTo
// CSIDL_STARTMENU The whole Start menu
// CSIDL_STARTUP The Autostart Group
// CSIDL_TEMPLATES Document templates // use of the constants above
SHGetSpecialFolderLocation(Application.Handle, CSIDL_DESKTOP, Root);
with BI do
begin
hwndOwner := Form1.Handle;
// NIL means show all
pidlRoot := Root;
pszDisplayName := Buf;
lpszTitle := '選擇目錄';
ulFlags := 0;
lpfn := nil;
end; try
Dir := SHBrowseForFolder(BI);
if Dir<>nil then
begin
SHGetPathFromIDList(Dir, Buf);
Result:=buf;
Alloc.Free(Dir);
end;
finally
Alloc.Free(Root);
Alloc.Free(Buf);
end;
end;procedure TForm1.ListTitle;
var
jobname,numname:string;
i:integer;
listnum:tstringlist;
joblistini,noini:TINIFILE;
begin
CheckListBox1.Clear; jobname:=ExtractFilePath(paramstr(0))+'Joblist.ini';
//numname:=ExtractFilePath(paramstr(0))+'Num.ini'; joblistini:=TInifile.Create(jobname);
//noini:=TInifile.Create(numname); listnum:=tstringlist.create; joblistini.ReadSection(inttostr(num),listnum);
//numini.ReadSection('Num',listnum); for i:=0 to listnum.Count-1 do
CheckListBox1.AddItem(listnum.Strings[i],CheckListBox1.Items);
listnum.Free ;
joblistini.Free ;
//noini.Free ;
end;procedure TForm1.Button4Click(Sender: TObject);
begin
Close;
end;procedure TForm1.Button6Click(Sender: TObject);
begin
LabeledEdit1.Text:=GetFolder+'\';
end;procedure TForm1.Button7Click(Sender: TObject);
begin
LabeledEdit2.Text:=GetFolder+'\';
end;procedure TForm1.Button1Click(Sender: TObject);
begin
if LabeledEdit3.Text<>'' then
begin
if LabeledEdit1.Text<>'' then
begin
if LabeledEdit2.Text<>'' then
begin
if LabeledEdit4.text<>'' then
begin
num:=num+1;
ini.WriteString(inttostr(num),'Exe Link',LabeledEdit4.Text);
end
else
begin
showmessage('請輸入Exe Link的路徑...');
exit;
end;
ini.WriteString(inttostr(num),'To',LabeledEdit2.Text);
end
else
begin
showmessage('請選擇或輸入To的路徑...');
exit;
end;
ini.WriteString(inttostr(num),'From',LabeledEdit1.Text);
end
else
begin
showmessage('請選擇或輸入From的路徑...');
exit;
end;
ini.WriteString(inttostr(num),'Name',LabeledEdit3.Text);
CheckListBox1.AddItem(LabeledEdit3.Text,CheckListBox1.Items);
end
else
begin
showmessage('請輸入Name...');
exit;
end;
LabeledEdit1.Text:='';
LabeledEdit2.Text:='';
LabeledEdit3.Text:='';
LabeledEdit4.Text:='';
end;procedure TForm1.FormCreate(Sender: TObject);
begin
ini:=Tinifile.Create(ExtractFilePath(Paramstr(0))+'Joblist.ini');
numini:=Tinifile.Create(ExtractFilePath(Paramstr(0))+'Num.ini');
num:=numini.ReadInteger('Num','Num',num);
ListTitle
end;procedure TForm1.Button8Click(Sender: TObject);
begin
winexec(pchar('xcopy.exe "'+LabeledEdit1.text+'" "'+LabeledEdit2.text+'" /W/F/L/E/D/Y'), SW_Hide);
end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
numini.WriteInteger('Num','Num',num);
end;procedure TForm1.CheckListBox1Click(Sender: TObject);
begin
//Image1.Picture.Bitmap.LoadFromFile('.\Images\'+inttostr(1)+'.BMP');
end;end.
joblist.ini
[1]
Exe Link=3
To=3
From=3
Name=3
[2]
Exe Link=4
To=4
From=44
Name=4
[3]
Exe Link=13
To=13
From=13
Name=13
[4]
Exe Link=4
To=4
From=4
Name=4
[5]
Exe Link=5
To=5
From=5
Name=5num.ini
[Num]
Num=5我想問怎樣可以在checklistbox里顯示joblist.ini里的name.
如圖:
checklistbox
↓
-----------
|○1 |
|○2 |
|○3 |
|○4 |
|○5 |
-----------
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, CheckLst, IniFiles, ShlObj, ActiveX, ShellAPI,
XPMan, Mask;type
TForm1 = class(TForm)
Button1: TButton;
Button3: TButton;
Button4: TButton;
CheckListBox1: TCheckListBox;
Button5: TButton;
LabeledEdit1: TLabeledEdit;
LabeledEdit2: TLabeledEdit;
Button6: TButton;
Button7: TButton;
Button8: TButton;
LabeledEdit3: TLabeledEdit;
Button10: TButton;
LabeledEdit4: TLabeledEdit;
Image1: TImage;
procedure listTitle;
procedure Button4Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure CheckListBox1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
num:integer;
ini,numini:Tinifile;
implementation{$R *.dfm}function GetFolder:string;
var
BI: TBrowseInfo;
Buf: PChar;
Dir, Root: PItemIDList;
Alloc: IMalloc;
begin
result:='';
SHGetMalloc(Alloc);
Buf := Alloc.Alloc(Max_Path); // CSIDL_BITBUCKET RecycleBin
// CSIDL_CONTROLS ControlPanel
// CSIDL_DESKTOP Desktop
// CSIDL_DRIVES My Computer
// CSIDL_FONTS Fonts
// CSIDL_NETHOOD Network Neighborhood
// CSIDL_NETWORK The virtual version of the above
// CSIDL_PERSONAL 'Personal'
// CSIDL_PRINTERS printers
// CSIDL_PROGRAMS Programs in the Start Menu
// CSIDL_RECENT Recent Documents
// CSIDL_SENDTO Folder SendTo
// CSIDL_STARTMENU The whole Start menu
// CSIDL_STARTUP The Autostart Group
// CSIDL_TEMPLATES Document templates // use of the constants above
SHGetSpecialFolderLocation(Application.Handle, CSIDL_DESKTOP, Root);
with BI do
begin
hwndOwner := Form1.Handle;
// NIL means show all
pidlRoot := Root;
pszDisplayName := Buf;
lpszTitle := '選擇目錄';
ulFlags := 0;
lpfn := nil;
end; try
Dir := SHBrowseForFolder(BI);
if Dir<>nil then
begin
SHGetPathFromIDList(Dir, Buf);
Result:=buf;
Alloc.Free(Dir);
end;
finally
Alloc.Free(Root);
Alloc.Free(Buf);
end;
end;procedure TForm1.ListTitle;
var
jobname,numname:string;
i:integer;
listnum:tstringlist;
joblistini,noini:TINIFILE;
begin
CheckListBox1.Clear; jobname:=ExtractFilePath(paramstr(0))+'Joblist.ini';
//numname:=ExtractFilePath(paramstr(0))+'Num.ini'; joblistini:=TInifile.Create(jobname);
//noini:=TInifile.Create(numname); listnum:=tstringlist.create; joblistini.ReadSection(inttostr(num),listnum);
//numini.ReadSection('Num',listnum); for i:=0 to listnum.Count-1 do
CheckListBox1.AddItem(listnum.Strings[i],CheckListBox1.Items);
listnum.Free ;
joblistini.Free ;
//noini.Free ;
end;procedure TForm1.Button4Click(Sender: TObject);
begin
Close;
end;procedure TForm1.Button6Click(Sender: TObject);
begin
LabeledEdit1.Text:=GetFolder+'\';
end;procedure TForm1.Button7Click(Sender: TObject);
begin
LabeledEdit2.Text:=GetFolder+'\';
end;procedure TForm1.Button1Click(Sender: TObject);
begin
if LabeledEdit3.Text<>'' then
begin
if LabeledEdit1.Text<>'' then
begin
if LabeledEdit2.Text<>'' then
begin
if LabeledEdit4.text<>'' then
begin
num:=num+1;
ini.WriteString(inttostr(num),'Exe Link',LabeledEdit4.Text);
end
else
begin
showmessage('請輸入Exe Link的路徑...');
exit;
end;
ini.WriteString(inttostr(num),'To',LabeledEdit2.Text);
end
else
begin
showmessage('請選擇或輸入To的路徑...');
exit;
end;
ini.WriteString(inttostr(num),'From',LabeledEdit1.Text);
end
else
begin
showmessage('請選擇或輸入From的路徑...');
exit;
end;
ini.WriteString(inttostr(num),'Name',LabeledEdit3.Text);
CheckListBox1.AddItem(LabeledEdit3.Text,CheckListBox1.Items);
end
else
begin
showmessage('請輸入Name...');
exit;
end;
LabeledEdit1.Text:='';
LabeledEdit2.Text:='';
LabeledEdit3.Text:='';
LabeledEdit4.Text:='';
end;procedure TForm1.FormCreate(Sender: TObject);
begin
ini:=Tinifile.Create(ExtractFilePath(Paramstr(0))+'Joblist.ini');
numini:=Tinifile.Create(ExtractFilePath(Paramstr(0))+'Num.ini');
num:=numini.ReadInteger('Num','Num',num);
ListTitle
end;procedure TForm1.Button8Click(Sender: TObject);
begin
winexec(pchar('xcopy.exe "'+LabeledEdit1.text+'" "'+LabeledEdit2.text+'" /W/F/L/E/D/Y'), SW_Hide);
end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
numini.WriteInteger('Num','Num',num);
end;procedure TForm1.CheckListBox1Click(Sender: TObject);
begin
//Image1.Picture.Bitmap.LoadFromFile('.\Images\'+inttostr(1)+'.BMP');
end;end.
joblist.ini
[1]
Exe Link=3
To=3
From=3
Name=3
[2]
Exe Link=4
To=4
From=44
Name=4
[3]
Exe Link=13
To=13
From=13
Name=13
[4]
Exe Link=4
To=4
From=4
Name=4
[5]
Exe Link=5
To=5
From=5
Name=5num.ini
[Num]
Num=5我想問怎樣可以在checklistbox里顯示joblist.ini里的name.
如圖:
checklistbox
↓
-----------
|○1 |
|○2 |
|○3 |
|○4 |
|○5 |
-----------
SecStrs:TStrings;
begin
SecStrs:=TStringList.Create;
IniFile.ReadSections(SecStrs);
for i:=0 to Strings.Count-1 do
begin
checklistbox.Items.Add(ReadString(SecStrs.Strings[i],'name',''));
end;
end;
var
SecStrs:TStrings;
begin
SecStrs:=TStringList.Create;
IniFile.ReadSections(SecStrs);
for i:=0 to Strings.Count-1 do //i沒賦類型 還有Strings.Count這里有錯
begin
checklistbox.Items.Add(ReadString(SecStrs.Strings[i],'name',''));//這里checklistbox少了1,還有ReadString(SecStrs.Strings[i],'name','')這句我不會改呀!!!
end;
end;
改了以後:
var
i:integer;
SecStrs:TStrings;
begin
SecStrs:=TStringList.Create;
IniFile.ReadSections(SecStrs);
for i:=0 to SecStrs.Count-1 do
begin
checklistbox.Items.Add(ReadString(SecStrs.Strings[i],'name',''));
end;
end;麻煩幫我改改ReadString(SecStrs.Strings[i],'name','')為什麼不行!!!
procedure TForm1.ListTitle;
var
i:integer;
SecStrs:TStrings;
begin
SecStrs:=TStringList.Create;
ini.ReadSections(SecStrs);
for i:=0 to SecStrs.Count-1 do
begin
checklistbox1.Items.Add(ini.ReadString(SecStrs.Strings[i],'name',''));
end;
end;
LabeledEdit1.Text:=jobini里的Exe Link
LabeledEdit2.Text:=jobini里的To
LabeledEdit3.Text:=jobini里的From
LabeledEdit4.Text:=jobini里的Name