Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming

Add a Check Box to a standard dialog box

By Zarko Gajic, About.com

Suppose you have a confirmation dialog of some kind, where the user can select a checkbox displayinfg "Don't show this message again"). When the user closes the dialog - program can store the state of the check box (checked or not checked) in a global variable - the next time you need to display this dialog - you simply don't show it.

The idea of realization is:
1. Create a dialog using CreateMessageDialog
2. This function will return a form object with dialog
3. In this object we can add a checkbox
4. Show dialog using ShowModal
5. Check a result and process a state of the checkbox
6. Destroy the created checkbox and the dialog

procedure TForm1.Button1Click(Sender: TObject) ;
var
  AMsgDialog: TForm;
  ACheckBox: TCheckBox;
begin
  AMsgDialog := CreateMessageDialog('This is a test message.', mtWarning, [mbYes, mbNo]) ;
  ACheckBox := TCheckBox.Create(AMsgDialog) ;
  with AMsgDialog do
  try
   Caption := 'Dialog Title' ;
   Height := 169;

   with ACheckBox do
   begin
    Parent := AMsgDialog;
    Caption := 'Don''t show me again.';
    Top := 121;
    Left := 8;
   end;

   if (ShowModal = ID_YES) then
   begin
    if ACheckBox.Checked then
      //do if checked
    else
      //do if NOT checked
   end;
  finally
   Free;
  end;
end;

Delphi tips navigator:
» Paint a Form with a tiled bitmap image
« Long ListBox entries as hints

Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming

About.com Special Features

Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Using VCL Components
  5. TRadioButton, TCheckBox
  6. Add a Check Box to a Standard Delphi Dialog Box

©2009 About.com, a part of The New York Times Company.

All rights reserved.