CnPack Forum


 
Subject: 建议 CnFileSystemWatcher 增加 Sender 这个参数
小帆
普通灌水员
Rank: 2



UID 1619
Digest Posts 0
Credits 63
Posts 24
点点分 63
Reading Access 10
Registered 2006-1-4
Status Offline
Post at 2009-8-6 22:44  Profile | Blog | P.M. 
建议 CnFileSystemWatcher 增加 Sender 这个参数

在很多时候我们需要传递 Sender 使用,所以

TFileDealMethod = procedure(FileOperation: TFileOperation; const FileName1,    FileName2: string) of object;

最好改为:

TFileDealMethod = procedure(Sender: Tobject; FileOperation: TFileOperation; const FileName1,    FileName2: string) of object;

这样做的好处显而易见,可以将 Sender 参数传递给需要的时候使用,多个CnFileSystemWatcher 可以共用一个事件过称,靠 Sender 来控制各自的不同的设置。
Top
小帆
普通灌水员
Rank: 2



UID 1619
Digest Posts 0
Credits 63
Posts 24
点点分 63
Reading Access 10
Registered 2006-1-4
Status Offline
Post at 2009-8-7 19:29  Profile | Blog | P.M. 
建议它改为这样:(红色部分为修改)
TFileDealMethod = procedure(FileOperation: TFileOperation; const FileName1,
    FileName2: string) of object;
改为:
TFileDealMethod = procedure(Sender: Tobject; FileOperation: TFileOperation; const FileName1,
    FileName2: string) of object;

TCnFileSystemWatcher = class;//增加

  TCnShellChangeThread = class(TThread)
  private
    FParent: TCnFileSystemWatcher;//增加
......
  public
    constructor Create(AParent:TCnFileSystemWatcher; ChangeEvent: TFileDealMethod); virtual;
.........
  end;

constructor TCnShellChangeThread.Create(AParent:TCnFileSystemWatcher; ChangeEvent: TFileDealMethod);
begin
............
FParent := AParent;//增加
  inherited Create(True);
end;

procedure TCnFileSystemWatcher.Start;
begin
  if csDesigning in ComponentState then
    Exit;
  if Assigned(FOnChange) then
  begin
    FThread := TCnShellChangeThread.Create(Self,FOnChange);
..............
end;

procedure TCnShellChangeThread.DoIOCompletionEvent;
var
  TempBuffer: TNotificationBuffer;
  FileOpNotification: PFileNotifyInformation;
  Offset: Longint;
  FileName1, FileName2: string;
  FileOperation: TFileOperation;
  procedure DoDirChangeEvent;
  var
    IsInFileMasks: Boolean;
  begin
    if Assigned(ChangeEvent) and FActive then
    begin
      if FTmpFileMasks.Count > 0 then
        IsInFileMasks := FileMatchesMasks(FileName1, FTmpFileMasks)
      else
        IsInFileMasks := FileMatchesMasks(FileName1, '*.*', False);
      if IsInFileMasks then
      begin
        if FIncludePath then
        begin
          FileName1 := GetTrueFileName(FDirectory + FileName1);
          if FileOperation = foRenamed then
            FileName2 := GetTrueFileName(FDirectory + FileName2);
        end;
        ChangeEvent(FParent, FileOperation, FileName1, FileName2);
      end;
    end;
  end;
  function GetFileName(const FileName: PWideChar; FileNameLength: DWORD):string;
end;

[ 本帖最后由 小帆 于 2009-8-7 19:30 编辑 ]
Top
Passion (LiuXiao)
管理员
Rank: 9Rank: 9Rank: 9


UID 359
Digest Posts 19
Credits 6838
Posts 3591
点点分 6838
Reading Access 102
Registered 2004-3-28
Status Offline
Post at 2009-8-10 09:39  Profile | Blog | P.M. 
有道理,接受此增强修改。
感谢楼主的热心参与。
Top
solokey
新警察
Rank: 1



UID 30253
Digest Posts 0
Credits 28
Posts 12
点点分 28
Reading Access 10
Registered 2007-11-2
Status Offline
Post at 2010-5-5 18:09  Profile | Blog | P.M. 
一直想改成Collection..一直懒得改....
还是靠自己多放几个组件吧....囧..
Top
 




All times are GMT++8, the time now is 2024-11-27 11:56

    本论坛支付平台由支付宝提供
携手打造安全诚信的交易社区 Powered by Discuz! 5.0.0  © 2001-2006 Comsenz Inc.
Processed in 0.009414 second(s), 9 queries , Gzip enabled

Clear Cookies - Contact Us - CnPack Website - Archiver - WAP