掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
再入防止のためにイベントハンドラを別メソッドでラップするには? (ID:14461)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
TButton の OnClick だけですが、イベントハンドラのラップということで procedure WrapEventHandlersToAvoidReEntrant(AOwner: TComponent); var I: Integer; C: TComponent; B: TButton; begin for I := 0 to AOwner.ComponentCount - 1 do begin C := AOwner.Components[I]; if (C is TButton) then begin B := C as TButton; if (not Assigned(B.Action)) then begin B.Action := TBasicAction.Create(C); B.Action.OnExecute := B.OnClick; end; B.OnClick := Form1.WrapEventHandler; end; WrapEventHandlersToAvoidReEntrant(C); end; end; procedure TForm1.WrapEventHandler(Sender: TObject); begin if (Sender is TButton) then begin if (Tag <> 0) then Exit; Tag := 1; try TButton(Sender).Action.Execute; finally Tag := 0; end; end; end; procedure TForm1.FormCreate(Sender: TObject); begin WrapEventHandlersToAvoidReEntrant(Self); end; procedure TForm1.Button1Click(Sender: TObject); procedure Delay(MS: DWORD); var T: DWORD; begin T := GetTickCount; while (GetTickCount - T < MS) do begin Application.ProcessMessages; Sleep(1); end; end; begin Memo1.Lines.Add('Start'); Delay(1000); Memo1.Lines.Add('End'); end;
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.