Delphi 이벤트 트리거!

2576 단어 Delphi
1.         。
unit UNotifyProcess;

interface

uses Windows, Registry, SysUtils, StrUtils, winsock, Classes, Contnrs, Dialogs;

const
  Restart_Stocket = 0;
  Allow_Work = 1;
  Forbid_Work = 2;
type
  TMyNotifyEvent = procedure(Sender: TObject; TaskSign,chn: integer) of object;
 
  TNotifyProcess = class(TObject)
  private
    FOnPopupMenuNotify: TMyNotifyEvent;
  public

    constructor Create();
    procedure ProcessPopupMenuNotify(TaskSign,chn: integer);

  published
    property OnPopupMenuNotify: TMyNotifyEvent read FOnPopupMenuNotify write FOnPopupMenuNotify;
  end;

var
  NotifyProcess: TNotifyProcess;
implementation
constructor TNotifyProcess.Create();
begin

end;

procedure TNotifyProcess.ProcessPopupMenuNotify(TaskSign,chn: integer);
var
  Sender: TObject;
begin
  Sender := nil;
  FOnPopupMenuNotify(Sender, TaskSign,chn);
end;

initialization
  NotifyProcess := TNotifyProcess.Create;

finalization
  NotifyProcess.Free;

end.
2     。    UNotifyProcess
procedure TFamTestInfo.N1Click(Sender: TObject);
begin
  NotifyProcess.ProcessPopupMenuNotify(Restart_Stocket,chn);
end;


procedure TFamTestInfo.N2Click(Sender: TObject);
begin
   NotifyProcess.ProcessPopupMenuNotify(Allow_Work,chn);
end;


procedure TFamTestInfo.N3Click(Sender: TObject);
begin
  NotifyProcess.ProcessPopupMenuNotify(Forbid_Work,chn);
end;
3.           UNotifyProcess
  private
    { Private declarations }
    procedure OnPopupMenuNotify(Sender: TObject; TaskSign, chn: integer);
   show         。
procedure TFrmMain.FormShow(Sender: TObject);
begin
  NotifyProcess.OnPopupMenuNotify := OnPopupMenuNotify;
end;
 
  
 procedure TFrmMain.OnPopupMenuNotify(Sender: TObject; TaskSign, chn: integer);
begin
  case TaskSign of
    Restart_Stocket: ReConnectNetWork(chn);
    Allow_Work: SocketClient[chn].SocketAskSend('AA', '00010');
    Forbid_Work: SocketClient[chn].SocketAskSend('AA', '00011');
  end;
end;
 
  
 
  
 
  
 
  
 
  
 
  
 
 

좋은 웹페이지 즐겨찾기