Difference between revisions of "TTaskDialog"
From Free Pascal wiki
Jump to navigationJump to searchLine 11: | Line 11: | ||
Also, property RadioButton has the radio-button object, which was clicked. | Also, property RadioButton has the radio-button object, which was clicked. | ||
+ | ==Example== | ||
This example shows how to create dialog in runtime, and to add custom buttons in runtime: | This example shows how to create dialog in runtime, and to add custom buttons in runtime: | ||
<syntaxhighlight> | <syntaxhighlight> | ||
− | with TTaskDialog.Create(self) do | + | with TTaskDialog.Create(self) do |
− | + | try | |
− | + | Title := 'Confirm removal'; | |
− | + | Caption := 'Confirm'; | |
− | + | Text := 'Remove selected item?'; | |
− | + | CommonButtons := []; | |
− | + | with TTaskDialogButtonItem(Buttons.Add) do | |
− | + | begin | |
− | + | Caption := 'Remove'; | |
− | + | ModalResult := mrYes; | |
− | + | end; | |
− | + | with TTaskDialogButtonItem(Buttons.Add) do | |
− | + | begin | |
− | + | Caption := 'Keep'; | |
− | + | ModalResult := mrNo; | |
− | + | end; | |
− | + | MainIcon := tdiQuestion; | |
− | + | if Execute then | |
− | + | if ModalResult = mrYes then | |
− | + | ShowMessage('Item removed'); | |
− | + | finally | |
− | + | Free; | |
− | + | end | |
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 18:39, 15 February 2017
TTaskDialog is a non-visual component, which shows full-featured dialogs at runtime, dialogs with rich features like Windows TaskDialog API has. It is available under the Dialogs of the Component Palette.
Dialog is shown with the Execute() method, and if it gets True, property ModalResult has id of pressed button:
- id of standard button (OK, Cancel, Yes etc)
- id of custom button, which is specified in each button's ModalResult
Also, property RadioButton has the radio-button object, which was clicked.
Example
This example shows how to create dialog in runtime, and to add custom buttons in runtime:
with TTaskDialog.Create(self) do
try
Title := 'Confirm removal';
Caption := 'Confirm';
Text := 'Remove selected item?';
CommonButtons := [];
with TTaskDialogButtonItem(Buttons.Add) do
begin
Caption := 'Remove';
ModalResult := mrYes;
end;
with TTaskDialogButtonItem(Buttons.Add) do
begin
Caption := 'Keep';
ModalResult := mrNo;
end;
MainIcon := tdiQuestion;
if Execute then
if ModalResult = mrYes then
ShowMessage('Item removed');
finally
Free;
end