Mirror

How to change the caption of a MessageDlg (Views: 100)


Problem/Question/Abstract:

How to change the caption of a MessageDlg

Answer:

Build your own:

function MyMessageDlg(const Msg: string; DlgType: TMsgDlgType; Buttons:
  TMsgDlgButtons;
  const ACaption: string = 'Hi'; DefaultButtonIndex: Integer = -1; HelpCtx: Longint =
    0): Integer;
var
  Index: Integer;
  ButtonIndex: Integer;
begin
  with CreateMessageDialog(Msg, DlgType, Buttons) do
  try
    HelpContext := HelpCtx;
    if ACaption <> '' then
      Caption := ACaption;
    if DefaultButtonIndex >= 0 then
    begin
      ButtonIndex := -1;
      for Index := 0 to ControlCount - 1 do
      begin
        if Controls[Index] is TButton then
        begin
          Inc(ButtonIndex);
          TButton(Controls[Index]).Default := ButtonIndex = DefaultButtonIndex;
          if ButtonIndex = DefaultButtonIndex then
            ActiveControl := TButton(Controls[Index]);
        end;
      end;
    end;
    Result := ShowModal;
  finally
    free;
  end;
end;

<< Back to main page