Recent

Author Topic: Have a red cross or green tick ShowMessage dialog  (Read 1147 times)

Gizmo

  • Hero Member
  • *****
  • Posts: 831
Have a red cross or green tick ShowMessage dialog
« on: October 17, 2018, 06:08:57 pm »
Hi

I have a ShowMessage dialog that shows one message if something is true and another message if something is false. e.g.
Code: Pascal  [Select][+][-]
  1. begin
  2.   If (Value > 5) then
  3.     ShowMessage('It is bigger than 5')
  4.   else ShowMessage('It is smaller than 5');
  5. end;
  6.  

In both instances, the "OK" button for the dialog has a green tick on it, for both the true and negative response.

I'd like to be able to make the OK button have a green tick if the valuation of the statement is true, but if the valuation is false, I'd like the OK button to have a red cross.

Code: Pascal  [Select][+][-]
  1. begin
  2.   If (Value > 5) then
  3.     ShowMessage('It is bigger than 5') // Show green tick in the OK button
  4.   else ShowMessage('It is smaller than 5'); // Show red cross in the OK button
  5. end;
  6.  

Is there a way to customise the OK button of ShowMessage dialog in this way? Before people send me to the section titled 'QuestionDlg' at http://wiki.freepascal.org/Dialog_Examples, I'm not ruling that out, but I'm not sure I understand how it would work in the simple context above of just evaluating a value. I wanted to know if there was a siple way of just changing a setting to get a red cross in ShowMessage without resorting more complex avenues.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Have a red cross or green tick ShowMessage dialog
« Reply #1 on: October 17, 2018, 06:45:31 pm »
Is there a way to customise the OK button of ShowMessage dialog in this way?

There is no easy way, short of building your own extended dialog. ShowMessage, as its name implies, is a simple, bare-bones, widgetset-dependent dialog. It's easier to just use a more customizable dialog, like p.e. MessageDlg.
Code: Pascal  [Select][+][-]
  1. var
  2.   TheMessage: String;
  3. begin
  4.   If (Value > 5) then
  5.     MessageDlg('It is bigger than 5', mtInformation, [mbOK], -1)
  6.   else
  7.     MessageDlg('It is smaller than 5', mtInformation, [mbClose], -1);
  8. end;
With this you can change both what the button says and how it looks by changing the buttons set. Other dialogs can also be customized as easily.
« Last Edit: October 17, 2018, 06:48:12 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

 

TinyPortal © 2005-2018