Всем привет,
как это сделать, что бы MessageDlg закрывалось автоматически через определенное время?
Спасибо!
Модератор: Модераторы
{ Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Buttons, StdCtrls, ExtCtrls; }
TOnTimerMessage = class
private
ASeconds: Cardinal;
timer: TTimer;
Form: Tform;
procedure GoTimer(Sender: TObject);
public
constructor create(ACaption: String; ATextMessage: String; AMsgType:TMsgDlgType; AButtons: TMsgDlgButtons; ATimeLimit: Cardinal) ;
end;
{ оборачивающая функция }
function ShowMessageWithTimer(ACaption: String; ATextMEssage: String; AMsgType: TMsgDlgType; AButtons: TMsgDlgButtons; AtimeLimit:Cardinal):integer;
constructor TOntimerMessage.create(ACaption: String; ATextMessage: String; AMsgType:TMsgDlgType; AButtons: TMsgDlgButtons; ATimeLimit: Cardinal);
begin
Form:=CreateMessageDialog(ATextMEssage,AMsgType, AButtons);
Form.Caption:=ACaption;
Timer:= TTimer.Create(Form);
Timer.Interval:=1000;
Timer.OnTimer:=@Self.GoTimer;
Aseconds:=ATimeLimit;
Timer.Enabled:=true;
end;
procedure TOnTimerMessage.GoTimer(Sender: TObject);
begin
if Self.Form.Showing then
begin
dec(Aseconds);
{ if Aseconds = 0 then Form.ModalResult:=2; { это вернется в любом случае ^_^ } }
if Aseconds = 0 then Form.close;
end;
end;
function ShowMessageWithTimer(ACaption: String; ATextMEssage: String; AMsgType: TMsgDlgType; AButtons: TMsgDlgButtons; AtimeLimit:Cardinal):integer;
var
Mess:TOntimerMessage;
begin
Mess:=TOnTimerMessage.create(ACaption,AtextMessage,AmsgType,Abuttons,AtimeLimit);
result:=Mess.Form.ShowModal;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessageWithTimer('привет','Через десять секнуд окошко закроется!', mtInformation, [mbOk], 10);
end;
Сейчас этот форум просматривают: Yandex [Bot] и гости: 31