如何使用 dwsXPlatform.CollectFiles TCollectFileProgressEvent
How to use dwsXPlatform.CollectFiles TCollectFileProgressEvent
由于我是 delphi 活动的新手,我正在努力研究如何将 dwsXPlatform.TCollectFileProgressEvent 与 dwsXPlatform.CollectFiles 结合使用。
在 DWScript 存储库中没有它的示例甚至测试代码。
type
TForm1 = class(TForm)
btn1: TButton;
mmoDirList: TMemo;
mmoOnCollectFiles: TMemo;
procedure btn1Click(Sender: TObject);
private
OnCollectFileProgressEvent: TCollectFileProgressEvent;
end;
{...}
procedure TForm1.btn1Click(Sender: TObject);
begin
mmoDirList.Clear;
CollectFiles('c:\MyDelphiFiles', '*.pas', mmoDirList.Lines, True, OnCollectFileProgressEvent);
end;
[已解决]
unit MainFormU;
interface
uses
Winapi.Windows,
Winapi.Messages,
System.SysUtils,
System.Variants,
System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.StdCtrls,
dwsXPlatform;
type
TForm1 = class(TForm)
btn1: TButton;
mmoDirList: TMemo;
mmoOnCollectFiles: TMemo;
chkEnableOnCollectEvent: TCheckBox;
procedure btn1Click(Sender: TObject);
procedure OnCollectFileProgressEvent(const aDirectory: string; var aSkipScan: Boolean);
private
FOnCollectFiles: TCollectFileProgressEvent;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btn1Click(Sender: TObject);
begin
mmoDirList.Clear;
mmoOnCollectFiles.Clear;
if chkEnableOnCollectEvent.Checked then
FOnCollectFiles := OnCollectFileProgressEvent
else
FOnCollectFiles := nil;
// procedure CollectFiles(const directory: UnicodeString;
// fileMask: UnicodeString;
// list: TStrings;
// recurseSubdirectories: Boolean = False;
// onProgress: TCollectFileProgressEvent = nil);
CollectFiles('c:\MyFolder\', '*.pas', mmoDirList.Lines, True, FOnCollectFiles);
end;
procedure TForm1.OnCollectFileProgressEvent(const aDirectory: string; var aSkipScan: Boolean);
begin
if aDirectory = 'c:\MyFolder\SkipThisFolder\' then begin
ShowMessage('Folder ' + aDirectory + ' was skipped!');
aSkipScan := True;
end;
mmoOnCollectFiles.Lines.Add(aDirectory);
end;
end.
根据文档 TCollectFileProgressEvent 声明如下:
TCollectFileProgressEvent = procedure (const directory : String; var skipScan : Boolean) of object;
让我们把它分成 3 部分:
1) TCollectFileProgressEvent
2) 过程(const 目录:字符串;var skipScan:布尔)
3) 对象
第一部分TCollectFileProgressEvent 是事件类型的名称。您的示例中的任何事情都不需要它。
第二部分过程....是您应该如何声明事件的秘诀
第三部分"of object"表示你的程序需要放在class上。
让我给你看一些代码:
TForm1 = class(TForm)
btn1: TButton;
mmoDirList: TMemo;
mmoOnCollectFiles: TMemo;
procedure btn1Click(Sender: TObject);
private
procedure CollectFileProgress(const directory : String; var skipScan : Boolean);
end;
{ TForm1 }
procedure TForm1.btn1Click(Sender: TObject);
begin
mmoDirList.Clear;
CollectFiles('c:\MyDelphiFiles', '*.pas', mmoDirList.Lines, True, CollectFileProgress);
end;
procedure TForm1.CollectFileProgress(const directory: String; var skipScan: Boolean);
begin
mmoDirList.Lines.Add(directory);
end;
由于我是 delphi 活动的新手,我正在努力研究如何将 dwsXPlatform.TCollectFileProgressEvent 与 dwsXPlatform.CollectFiles 结合使用。
在 DWScript 存储库中没有它的示例甚至测试代码。
type
TForm1 = class(TForm)
btn1: TButton;
mmoDirList: TMemo;
mmoOnCollectFiles: TMemo;
procedure btn1Click(Sender: TObject);
private
OnCollectFileProgressEvent: TCollectFileProgressEvent;
end;
{...}
procedure TForm1.btn1Click(Sender: TObject);
begin
mmoDirList.Clear;
CollectFiles('c:\MyDelphiFiles', '*.pas', mmoDirList.Lines, True, OnCollectFileProgressEvent);
end;
[已解决]
unit MainFormU;
interface
uses
Winapi.Windows,
Winapi.Messages,
System.SysUtils,
System.Variants,
System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.StdCtrls,
dwsXPlatform;
type
TForm1 = class(TForm)
btn1: TButton;
mmoDirList: TMemo;
mmoOnCollectFiles: TMemo;
chkEnableOnCollectEvent: TCheckBox;
procedure btn1Click(Sender: TObject);
procedure OnCollectFileProgressEvent(const aDirectory: string; var aSkipScan: Boolean);
private
FOnCollectFiles: TCollectFileProgressEvent;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btn1Click(Sender: TObject);
begin
mmoDirList.Clear;
mmoOnCollectFiles.Clear;
if chkEnableOnCollectEvent.Checked then
FOnCollectFiles := OnCollectFileProgressEvent
else
FOnCollectFiles := nil;
// procedure CollectFiles(const directory: UnicodeString;
// fileMask: UnicodeString;
// list: TStrings;
// recurseSubdirectories: Boolean = False;
// onProgress: TCollectFileProgressEvent = nil);
CollectFiles('c:\MyFolder\', '*.pas', mmoDirList.Lines, True, FOnCollectFiles);
end;
procedure TForm1.OnCollectFileProgressEvent(const aDirectory: string; var aSkipScan: Boolean);
begin
if aDirectory = 'c:\MyFolder\SkipThisFolder\' then begin
ShowMessage('Folder ' + aDirectory + ' was skipped!');
aSkipScan := True;
end;
mmoOnCollectFiles.Lines.Add(aDirectory);
end;
end.
根据文档 TCollectFileProgressEvent 声明如下:
TCollectFileProgressEvent = procedure (const directory : String; var skipScan : Boolean) of object;
让我们把它分成 3 部分:
1) TCollectFileProgressEvent
2) 过程(const 目录:字符串;var skipScan:布尔)
3) 对象
第一部分TCollectFileProgressEvent 是事件类型的名称。您的示例中的任何事情都不需要它。
第二部分过程....是您应该如何声明事件的秘诀
第三部分"of object"表示你的程序需要放在class上。
让我给你看一些代码:
TForm1 = class(TForm)
btn1: TButton;
mmoDirList: TMemo;
mmoOnCollectFiles: TMemo;
procedure btn1Click(Sender: TObject);
private
procedure CollectFileProgress(const directory : String; var skipScan : Boolean);
end;
{ TForm1 }
procedure TForm1.btn1Click(Sender: TObject);
begin
mmoDirList.Clear;
CollectFiles('c:\MyDelphiFiles', '*.pas', mmoDirList.Lines, True, CollectFileProgress);
end;
procedure TForm1.CollectFileProgress(const directory: String; var skipScan: Boolean);
begin
mmoDirList.Lines.Add(directory);
end;