whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

32 Visitors Online


 
..set a message-dialogs default button?
Autor: Thomas Stutz
[ Print tip ]  

Tip Rating (6):  
     


function DefMessageDlg(const ACaption: string;
  const Msg: string;
  DlgType: TMsgDlgType;
  Buttons: TMsgDlgButtons;
  DefButton: Integer;
  HelpCtx: Longint): Integer;
var
  
i: Integer;
  btn: TButton;
begin
  with 
CreateMessageDialog(Msg, DlgType, Buttons) do
    try
      
Caption := ACaption;
      HelpContext := HelpCtx;
      for i := 0 to ComponentCount - 1 do
      begin
        if 
(Components[i] is TButton) then
        begin
          
btn := TButton(Components[i]);
          btn.default := btn.ModalResult = DefButton;
          if btn.default then ActiveControl := btn;
        end;
      end;
      Result := ShowModal;
    finally
      
Free;
    end;
end;

// Sets the focus on the "No"-Button
// Setzt den Fokus auf den "Nein"-Button

procedure TForm1.Button1Click(Sender: TObject);
begin
  if 
DefMessageDlg('Title',
    '....?',
    mtConfirmation,
    mbYesNoCancel,
    mrNo,
    0) = mrYes then
    
ShowMessage('....');
end;

 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners