Dismiss Notice

REGISTRATION IS AFTER ADMIN ACTIVATION

DONATIONS WITH PAYPAL CLICK TO BUTTON

1 MONTH VIP - 5$; 3 MONTHS VIP - 10$; 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.

Source Code HOW TO customize a MessageDlg

Discussion in 'Delphi Programming' started by N0body, Jul 8, 2014.

  1. N0body
    Online

    N0bodyN0body is a Verified Member DelphiFan Administrator Staff Member DF Staff

    You can use something like below to show a Dialog that will be closed automatically.

    Code:
    unit uAutoCloseDialog;
    
    interface
    
    uses
      Windows,
      Messages,
      SysUtils,
      Variants,
      Classes,
      Controls,
      Forms,
      Dialogs,
      StdCtrls,
      ExtCtrls;
    
    type
      TAutoCloseDialog = class
      private
        FDialog: TForm;
        FCheckBox: TCheckBox;
        FTimer: TTimer;
        FInfo: TLabel;
        FCountDown: Integer;
        FCounter: Integer;
        FModalResult: Integer;
        FShowCounter: Boolean;
        function GetButtonText(const Name: string): string;
        function GetCheckDontShow: Boolean;
        function GetTitle: string;
        procedure SetButtonText(const Name, Value: string);
        procedure SetTitle(const Value: string);
        procedure TimerClick(Sender: TObject);
      public
        constructor Create(const Text: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons);
        destructor Destroy; override;
        function Execute(): Boolean;
        property CountDown: Integer read FCountDown write FCountDown;
        property ModalResult: Integer read FModalResult;
        property Title: string read GetTitle write SetTitle;
        property CheckDontShow: Boolean read GetCheckDontShow;
        property ShowCounter: Boolean read FShowCounter write FShowCounter;
        property ButtonCaption[const Name: string]: string read GetButtonText write SetButtonText;
      end;
    
    implementation
    
    { TAutoCloseDialog }
    
    constructor TAutoCloseDialog.Create(const Text: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons);
    begin
      FDialog := CreateMessageDialog(Text, DlgType, Buttons);
    
      FDialog.Height := FDialog.Height + 20;
    
      FCheckBox := TCheckBox.Create(FDialog);
      FCheckBox.Parent := FDialog;
      FCheckBox.SetBounds(8, FDialog.ClientHeight - 17 - 8, 140, 17);
      FCheckBox.Caption := 'Don''t show me again.';
    
      FInfo := TLabel.Create(FDialog);
      FInfo.Parent := FDialog;
      FInfo.SetBounds(FDialog.ClientWidth - 38, FDialog.ClientHeight - 13 - 8, 30, 13);
      FInfo.Alignment := taRightJustify;
    
      FTimer := TTimer.Create(FDialog);
      FTimer.Enabled := False;
      FTimer.OnTimer := TimerClick;
      FCountDown := 10;
      FShowCounter := True;
    end;
    
    destructor TAutoCloseDialog.Destroy;
    begin
      FDialog.Free();
      inherited;
    end;
    
    function TAutoCloseDialog.Execute: Boolean;
    begin
      FCounter := FCountDown;
      FTimer.Enabled := FCounter > 0;
      if (FShowCounter) then
        FInfo.Caption := IntToStr(FCounter);
      FModalResult := FDialog.ShowModal();
      Result := FModalResult = mrYes;
    end;
    
    function TAutoCloseDialog.GetButtonText(const Name: string): string;
    var
      Control: TButton;
    begin
      Control := FDialog.FindComponent(Name) as TButton;
      if (not Assigned(Control)) then
        Exit('');
    
      Exit(Control.Caption);
    end;
    
    function TAutoCloseDialog.GetCheckDontShow: Boolean;
    begin
      Result := FCheckBox.Checked;  // Must be .Checked not .Enabled!  Thanks to yocko
    end;
    
    function TAutoCloseDialog.GetTitle: string;
    begin
      Result := FDialog.Caption;
    end;
    
    procedure TAutoCloseDialog.SetButtonText(const Name, Value: string);
    var
      Control: TButton;
    begin
      Control := FDialog.FindComponent(Name) as TButton;
      if (Assigned(Control)) then
        Control.Caption := Value;
    end;
    
    procedure TAutoCloseDialog.SetTitle(const Value: string);
    begin
      FDialog.Caption := Value;
    end;
    
    procedure TAutoCloseDialog.TimerClick(Sender: TObject);
    begin
      Dec(FCounter);
      if (FShowCounter) then
        FInfo.Caption := IntToStr(FCounter);
      if (FCounter = 0) then
      begin
        FTimer.Enabled := False;
        FDialog.ModalResult := mrYes;
      end;
    end;
    
    end.

    The using is simple.

    Code:
    procedure TForm1.Button2Click(Sender: TObject);
    var
      Text: string;
      Dialog: TAutoCloseDialog;
    begin
      Text := 'This is a test message. with multiple lines.'#13#10'Line 1.'#13#10'Line 2.'#13#10'Line 3.';
      Dialog := TAutoCloseDialog.Create(Text, mtConfirmation, mbYesNoCancel);
      try
        Dialog.ButtonCaption['Yes'] := 'Details';
        Dialog.ButtonCaption['No'] := 'Fat';
        Dialog.ButtonCaption['Cancel'] := 'Cancel';
        Dialog.Title := 'Warning';
        Dialog.CountDown := 5;
        if (Dialog.Execute()) then
        begin
          if (Dialog.CheckDontShow) then
          begin
            // Do whatever
          end;
        end;
      finally
        Dialog.Free();
      end;
    end;
    Another example.

    Code:
    procedure TForm1.Button2Click(Sender: TObject);
    var
      Text: string;
      Dialog: TAutoCloseDialog;
    begin
      Text := 'This is a test message. with multiple lines.'#13#10'Line 1.'#13#10'Line 2.'#13#10'Line 3.';
      Dialog := TAutoCloseDialog.Create(Text, mtConfirmation, mbYesNoCancel);
      try
        Dialog.ButtonCaption['Yes'] := 'Details';
        Dialog.ButtonCaption['No'] := 'Fat';
        Dialog.ButtonCaption['Cancel'] := 'Cancel';
        Dialog.Title := 'Warning';
        Dialog.CountDown := 5;
        Dialog.Execute();
    
        if (Dialog.CheckDontShow) then
        begin
          // Do whatever
        end;
    
        case Dialog.ModalResult of
          mrYes    : ShowMessage('Yes');
          mrNo     : ShowMessage('No');
          mrCancel : ShowMessage('Cancel');
        end;
      finally
        Dialog.Free();
      end;
    end;
     
    gss200610, Lgogo, vcorp and 1 other person like this.
  2. egeven
    Offline

    egeven DF Member

    RE:

    [font=Verdana, Arial, sans-serif]Thanks[/font]
     
  3. perdcomp
    Offline

    perdcomp DF Junior

    Thanks
     
  4. mato0o
    Offline

    mato0o DF Junior

    Thank you!
     
  5. peyman1
    Offline

    peyman1 Guest

    RE:

    thanks
     
  6. topst7
    Offline

    topst7 DF Member

    RE:

    it interesting, thank you
     
  7. pggbs
    Offline

    pggbs Guest

    RE:

    thank you
     
  8. ZOLO
    Offline

    ZOLO Guest

    RE:

    So good.
     
  9. profepaco
    Offline

    profepaco DF Junior

    RE:

    very good. Thanks
     
  10. arabdent
    Offline

    arabdent Guest

    RE:

    thanks
     
  11. Tallys
    Offline

    Tallys DF Junior

    Obrigado!
     
  12. david91
    Offline

    david91 DF Member

    Thanks!
     
  13. vcorp
    Offline

    vcorp DF Junior

    Another food idea to be added to my Real Rally Manager. Thanks for sharing it!
     

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