📄 ufrmbatmodify.pas
字号:
unit ufrmBatModify;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, CheckLst, ExtCtrls, ComCtrls,ShellAPI;
type
TfrmBatMoidfy = class(TForm)
dlgOpen1: TOpenDialog;
Panel1: TPanel;
pnl1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
chklst1: TCheckListBox;
btnDelete: TButton;
btnAdd: TButton;
Panel4: TPanel;
pb1: TProgressBar;
Panel5: TPanel;
btn3: TButton;
Panel6: TPanel;
mmoReplace: TMemo;
Panel7: TPanel;
Panel8: TPanel;
Panel9: TPanel;
mmoSource: TMemo;
Panel10: TPanel;
edtAttribs: TComboBox;
edtNodes: TComboBox;
chkSkipDxx: TCheckBox;
lbl1: TLabel;
lbl2: TLabel;
procedure btn3Click(Sender: TObject);
procedure btnDeleteClick(Sender: TObject);
procedure btnAddClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
DragDropDefWndProc, DragDropWndProcInstance: Pointer;
procedure DragDropWndProc(var Message: TMessage);
procedure DragDropFiles(hDropHandle: HDrop);
procedure AddAFile(AFile:string);
public
end;
var
frmBatMoidfy: TfrmBatMoidfy;
implementation
uses uBatModify;
{$R *.dfm}
procedure TfrmBatMoidfy.AddAFile(AFile: string);
begin
if chklst1.Items.IndexOf(AFile)<=0 then
begin
chklst1.Items.Add(AFile);
chklst1.Checked[chklst1.Items.Count-1]:=True;
end;
end;
procedure TfrmBatMoidfy.btn3Click(Sender: TObject);
var
i:Integer;
sFile:string;
vOption:TXModifyOption;
begin
FillChar(vOption,SizeOf(vOption),0);
vOption.NodeNames:=edtNodes.Text;
vOption.Attribs:=edtAttribs.Text;
vOption.SourceText:=mmoSource.Text;
vOption.ReplaceText:=mmoReplace.Text;
vOption.SkipDxx:=chkSkipDxx.Checked;
pb1.Max:=chklst1.Count;
pb1.Position:=0;
pb1.Min:=0;
for i := 0 to chklst1.Count - 1 do
begin
if chklst1.Checked[i] then
begin
sFile:=chklst1.Items[i];
try
ModifyXmlFile(sFile,vOption);
except
end;
end;
pb1.StepIt;
end;
pb1.Position:=0;
end;
procedure TfrmBatMoidfy.btnAddClick(Sender: TObject);
var
i:Integer;
sFile:string;
begin
if dlgOpen1.Execute then
begin
for i := 0 to dlgOpen1.Files.Count - 1 do
begin
sFile:=dlgOpen1.Files[i];
AddAFile(sFile);
end;
end;
end;
procedure TfrmBatMoidfy.btnDeleteClick(Sender: TObject);
var
iIndex:Integer;
begin
if chklst1.ItemIndex>=0 then
begin
iIndex:=chklst1.ItemIndex;
chklst1.Items.Delete(chklst1.ItemIndex);
if iIndex<chklst1.Items.Count then
chklst1.ItemIndex:=iIndex
else
chklst1.ItemIndex:=iIndex-1;
end;
end;
procedure TfrmBatMoidfy.DragDropFiles(hDropHandle: HDrop);
var
PFilename: PChar;
i,Count: Integer;
begin
GetMem(PFilename, 256);
try
Count := DragQueryFile(hDropHandle, $FFFFFFFF, nil, 255);
if Count > 0 then
begin
for i:=0 to Count-1 do
begin
DragQueryFile(hDropHandle, i, PFilename, 255);
AddAFile(PFilename);
end;
end;
SetForegroundWindow(Application.Handle);
finally
FreeMem(PFilename, 256);
end;
end;
procedure TfrmBatMoidfy.DragDropWndProc(var Message: TMessage);
begin
with Message do begin
if Msg = WM_DROPFILES then
DragDropFiles(HDrop(wParam))
else
Result := CallWindowProc(DragDropDefWndProc, Handle, Msg, WParam, LParam);
end;
end;
procedure TfrmBatMoidfy.FormCreate(Sender: TObject);
begin
// Drag files
DragDropWndProcInstance :=Forms.MakeObjectInstance(DragDropWndProc);
DragDropDefWndProc := Pointer(GetWindowLong(Handle, GWL_WNDPROC));
SetWindowLong(Handle, GWL_WNDPROC, LongInt(DragDropWndProcInstance));
DragAcceptFiles(Handle, True);
end;
procedure TfrmBatMoidfy.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
// Drag Files
DragAcceptFiles(Handle, False);
SetWindowLong(Handle, GWL_WNDPROC, LongInt(DragDropDefWndProc));
Forms.FreeObjectInstance(DragDropWndProcInstance);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -