Dismiss Notice

REGISTRATION IS AFTER ADMIN ACTIVATION

DONATIONS WITH PAYPAL CLICK TO BUTTON

6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$

DONATIONS WITH Bitcoin Address:3NRs3CK3fhXifrNYxHEZKpETDd9vNLMsMD

Dismiss Notice
The registration is approved by the Administrator. It takes about 1 day to approve your registration
Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

Timed Dialogs

Discussion in 'Delphi Programming' started by AdminDF, Dec 5, 2013.

  1. AdminDF
    Online

    AdminDFAdminDF is a Verified Member DelphiFan Administrator Staff Member DF Staff

    Suppose that you want an "error" (or "warning") dialog-box that closes automatically, say after 60 seconds. You want to call that dialog from your code just like you call Delphi's dialogs, for example call like this:


    Code:
    TimedDlg.Execute('Warning', 
      'Unexpected value in edit-box AGE. Please correct.'); 


    Here's a quick and simple solution:


    Add a new form to your project and name the form TimedDlg. Save the new unit as TimedDlgU.
    Set the form's BorderStyle property to bsDialog.
    Add three components:
    - a TTimer; set its property Interval to 60000 (that's 60000 milliseconds); set its property Enabled to False;
    - a TMemo;
    - a TBitButton; set its property Kind to bkOK.
    In the PUBLIC section of unit TimedDlgU, declare a procedure with the name Execute:


    Code:
    unit TimedDlgU;
    interface
    uses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls, Buttons;
    type
      TTimedDlg = class(TForm)
      btnOK: TBitBtn;
      private
        { Private declarations }
      public
        { Public declarations }
        procedure Execute(Title, Contents: string); // added by you
      end;
    var
      TimedDlg: TTimedDlg;

    In the implementation section of your new unit, add the following code:


    Code:
    procedure TTimedDlg.Execute(Title, Contents: string);
    begin
      Caption := Title;       // set the caption of the form  
      Memo1.Text := Contents; // set the text of the memo
      Timer1.Enabled := True; // start the timer
      ShowModal;
    end;


    Double click on the TTimer component. Delphi will write an "OnTimer" event handler in your code.
    Complete this "OnTimer" procedure as follows:


    Code:
    procedure TTimedDlg.Timer1Timer;
    begin
      Timer1.Enabled := False; // stop the timer
      ModalResult := mrOK;     // close the form
    end;


    The procedure Execute shows the form in a "modal" way, that means: the dialog form appears on top of the other window(s) and your application doesn't continue before the dialog form is closed.
    When the user clicks the OK button, the dialog form is closed.
    But if the user doesn't click the OK button within 60 seconds, this form is closed "automatically".


    Note: don't forget to add the unit TimedDlgU to the uses directive in each unit from where you call TimedDlg.Execute, like this:


    Code:
    uses ..., ..., TimedDlgU;
     

Share This Page

Laws
Our website, law, laws, copyright and aims to be respectful of individual rights. Our site, as defined in the law of 5651 serves as a provider of space. According to the law, contrary to the law of site management has no obligation to monitor content. Therefore, our site has adopted the principle of fit and remove. Works are subject to copyright laws and is shared in a manner that violated their legal rights, or professional associations, rights holders who, adsdelphi@gmail.com I can reach us at e-mail address. Complaints considered to be infringing on the examination of the content will be removed from our site.
Donate Help To Us and Be VIP
DONATIONS WITH PAYPAL CLICK TO BUTTON
6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$
Social Block