Difference between revisions of "Dialog Examples/sk"

From Lazarus wiki
Jump to navigationJump to search
(initial release)
 
m (Fixed syntax highlighting)
 
(13 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
{{Dialog Examples}}
 
{{Dialog Examples}}
  
= Some useful dialogs=
+
= Niektoré užitočné dialógy =
Here are some useful dialogs not found in the Component Palette:
+
Toto sú niektoré užitočné dialógy, ktoré nenájdete v Palete komonentov:
  
 
* procedure ShowMessage (const Msg: string);
 
* procedure ShowMessage (const Msg: string);
Line 11: Line 11:
 
* function PasswordBox(const ACaption, APrompt : String) : String;
 
* function PasswordBox(const ACaption, APrompt : String) : String;
  
Each of these components causes a small popup box to be displayed, which contains some information and requires a user response: either a button press or some text entry or both. The programmer has little control over the format, size or position of these popup boxes, but can influence their textual content.<br>
+
Každý z týchto komponentov zobrazuje malé vyskakovacie dialógové okno, ktoré obsahuje nejaké informácie a vyžaduje odozvu používateľa: stlačenie tlačítka, zadanie textu alebo oboje. Programátor má minimálnu kontrolu nad formátom, veľkosťou alebo pozíciou týchto vyskakovacích okien, ale môže ovplyvňovať ich textový obsah.<br>
The reason why there are often several very similar alternatives, is to allow different methods of calling the component and receiving data back from the procedure or function.
+
Dôvodom prečo často existujú veľmi podobné alternatívy, je umožniť rôzne spôsoby volania komponentu, a získavania dát, z procedúr a funkcií.
  
==Message Dialogs==
+
==Správové dialógy==
Message dialogs display a message and wait for a key-press or mouse-click response.
+
Správové dialógy zobrazujú správu a čakajú na stlačenie klávesy alebo kliknutie myšou.
 
===ShowMessage===
 
===ShowMessage===
Procedure ShowMessage (const Msg: string);
+
<syntaxhighlight lang=pascal> Procedure ShowMessage (const Msg: string);
 
   
 
   
  { Defined in Dialogs.pp }
+
  { Defined in Dialogs.pp }</syntaxhighlight>
  
The simplest message dialog: takes a simple string as parameter, displays it in a stereotyped box, and waits for a mouse-click or enter-key event before returning to the calling routine or program.<br>
+
Najjednoduchší správový dialóg: prijíma jednoduchý textový prarmeter, zobrazí ho v stereotypnom okne a pred vrátením, do volajúcej rutiny alebo programu, čaká na kliknutie myšou alebo kláves enter.<br>
This is a modal procedure call, that is the box is displayed, receives focus, and does not relinquish focus until the OK box is clicked or otherwise selected.
+
Toto je modálne volanie procedúry, ktoré zobrazí okno, získa zameranie a tohoto sa nevzdá, pokiaľ nie je stlačené OK.
  
Example:
+
Príklad:
 
+
<syntaxhighlight lang=pascal> Program LazMessage;
Program LazMessage;
 
 
  Uses Dialogs;
 
  Uses Dialogs;
 
  begin
 
  begin
   ShowMessage ('This is a message from Lazarus')
+
   ShowMessage ('Toto je správa z Lazarusu!')
  end.
+
  end.</syntaxhighlight>
  
 
===MessageBox===
 
===MessageBox===
Function Application.MessageBox (Text, Caption: PChar; Flags: longint) : Integer;
+
<syntaxhighlight lang=pascal> Function Application.MessageBox (Text, Caption: PChar; Flags: longint) : Integer;
 
   
 
   
  { Defined in Forms.pp as part of TApplication; hence must be called as Application.Messagebox () or using the 'with Application do ...' construct }
+
  { Defined in Forms.pp as part of TApplication; hence must be called as Application.Messagebox ()  
 +
  or using the 'with Application do ...' construct }</syntaxhighlight>
  
Parameters include
+
Parametre:
 +
* '''Text''': reťazec, ktorý je v okne zobrazený ako otázka ale inštrukcia;
 +
* '''Caption''': textový štítok, ktorý je zobrazený na vrchu okna správy;
 +
* '''Flags''': longint - integer vytvorený sčítaním rôznych konštánt, ktorými je definovaný obsah a správanie okna, napríklad '''MB_ABORTRETRYIGNORE + MR_ICONQUESTION''' nastaví, že aplikácia zobrazí ikonu otázky (?) v okne s tromi tlačítkami: ABORT, RETRY a IGNORE.
  
* Text: the string that is displayed as a prompt or instruction in the Box;
+
Funkcia vracia hodnotu integer, ktorá zodpovedá stlačenému tlačítku; jej hodnota je daná odkazom na konštanty [IDOK..IDHELP]
* Caption: the string label at the top of the message box;
 
* Flags: longint - an integer constructed by adding together various constants to define the contents and behaviour of the box, for example MB_ABORTRETRYIGNORE + MR_ICONQUESTION will cause the application to display a query (?) icon in a box with three buttons: ABORT RETRY IGNORE.
 
  
The function returns an integer value corresponding to the button that was pressed; its value can be determined by reference to the constants [IDOK..IDHELP]
+
Môže byť volaná ako procedúra (tj. formulácia 'MessageBox()' namiesto volania funkcie 'Variable := MessageBox()' – viz. príklad nižšie)
  
It can be invoked like a procedure call (ie as a 'MessageBox()' statement rather than as a 'Variable := MessageBox()' function call - see example below)
+
Príklad:
 
+
<syntaxhighlight lang=pascal> Uses Forms, Dialogs, LCLType;
Example
 
 
 
Uses Forms, Dialogs, LCLType;
 
 
   
 
   
 
  Procedure DisplayMessageBox;
 
  Procedure DisplayMessageBox;
Line 59: Line 57:
 
       if reply = IDYES then MessageBox ('Yes      ', 'Reply',MB_ICONINFORMATION)
 
       if reply = IDYES then MessageBox ('Yes      ', 'Reply',MB_ICONINFORMATION)
 
       else MessageBox ('No        ', 'Reply', MB_ICONHAND);
 
       else MessageBox ('No        ', 'Reply', MB_ICONHAND);
   end;
+
   end;</syntaxhighlight>
  
Notice that in this example the 'Yes' and 'No' strings have been padded out with spaces; otherwise the box would not be wide enough to display the caption properly
+
Všimnite si, že v tomto príklade sú reťazce 'Yes' a 'No' doplnené medzerami; inak by okno nebolo dosť široké na správne zobrazenie titulku.
  
<center> http://lazarus-ccr.sourceforge.net/kbdata/MessageBoxDemo.png http://lazarus-ccr.sourceforge.net/kbdata/ReplyYes.png
+
<center>[[Image:MessageBoxDemo.png]]    [[Image:ReplyYes.png]]</center>
</center>
 
  
 
===MessageDLG===
 
===MessageDLG===
function MessageDlg(const aMsg: string; DlgType: TMsgDlgType;  
+
<syntaxhighlight lang=pascal> function MessageDlg(const aMsg: string; DlgType: TMsgDlgType;  
 
                     Buttons: TMsgDlgButtons; HelpCtx: Longint): Integer;
 
                     Buttons: TMsgDlgButtons; HelpCtx: Longint): Integer;
 
  function MessageDlg(const aCaption, aMsg: string; DlgType: TMsgDlgType;  
 
  function MessageDlg(const aCaption, aMsg: string; DlgType: TMsgDlgType;  
                     Buttons: TMsgDlgButtons; HelpCtx: Longint): Integer;
+
                     Buttons: TMsgDlgButtons; HelpCtx: Longint): Integer;</syntaxhighlight>
  
Two versions of this function, ie first 'Caption' parameter is optional; if omitted, caption is missing from box
+
Táto funkcia má dve verzie, teda prvý parameter 'Caption' je voliteľný, ak je vynechaný nie je zobrazený Titulok.
  
This is the most complete and elaborate of the message dialogs, and allows the programmer considerable control over the appearance of the dialog box.
+
Toto je najkomplexnejší a najprepracovanejší správový dialóg, ktorý poskytuje programátorovi značnú kontrolu nad vzhľadom dialógového okna. Parametre definujúce typ okna a jeho ikonu sú typy, namiesto konštánt a tlačítka môžu byť zadané ako množina v lomených zátvorkách, napr. '''[mbRetry, mbIgnore, mbAbort, mbCancel]'''. Parameter '''HelpCtx''' aktuálne nie je implementovaný a musí bať nastavený na nulu. Návratová hodnota funkcie je identická ako stlačené tlačítko, reprezentovaná ako integer (viz nasledujúcu definície, [mrNone..mrAll]).
The parameters defining the kind of box and its icon are types rather than integer constants, and the buttons can be specified as a set in square brackets eg [mbRetry, mbIgnore, mbAbort, mbCancel].
 
The HelpCtx parameter is not currently implemented and should be set to zero.
 
The return value from the Function is the identity of the button pressed, expressed as an integer (see the definitions below, [mrNone..mrAll]).
 
  
Example
+
Príklad:
 
+
<syntaxhighlight lang=pascal> Uses forms, dialogs, lcltype, controls;
Uses forms, dialogs, lcltype, controls;
 
 
   
 
   
 
  procedure TryMessageDlg;
 
  procedure TryMessageDlg;
 
  begin
 
  begin
 
   if MessageDlg ('Question', 'Do you wish to Execute?', mtConfirmation,  
 
   if MessageDlg ('Question', 'Do you wish to Execute?', mtConfirmation,  
                   [mbYes, mbNo, mbIgnore],0) = mrYes
+
                   [mbYes, mbNo, mbIgnore], 0) = mrYes
   then { Execute rest of Program };
+
   then  
   end;
+
    { Execute rest of Program };
 +
   end;</syntaxhighlight>
  
 +
<center> [[Image:Question.png]] </center>
  
<center> http://lazarus-ccr.sourceforge.net/kbdata/Question.png
+
== Dialógy textového vstupu ==
</center>
+
Dialógy textového vstupu, zobrazujú správu a dovoľujú používateľovi zadať požadovanú textovú hodnotu.
  
== Text input Dialogs==
 
 
===InputBox===
 
===InputBox===
Text input Dialogs: display a message and await user text input
 
  
Function InputBox(const ACaption, APrompt, ADefault : String) : String;
+
<syntaxhighlight lang=pascal>Function InputBox(const ACaption, APrompt, ADefault : String) : String;</syntaxhighlight>
  
Displays a box with defined title and prompt, and expects user input in a text box. A default string can optionally be displayed in the text box. The user-entered or default string is returned as the function result.
+
Zobrazuje okno s definovaným nadpisom, otázku a čaká na používateľský vstup v textovom poli. Voliteľne môže byť pre textové pole definovaný aj predvolený reťazec. Používateľom zadaný text alebo predvolený reťazec je vrátený ako výsledok funkcie.
  
Example
+
Príklad:
 
+
<syntaxhighlight lang=pascal> Uses forms, lcltype, dialogs, controls;
Uses forms, lcltype, dialogs, controls;
 
 
   
 
   
 
  procedure TryInputBox;
 
  procedure TryInputBox;
Line 112: Line 104:
 
                           'Please type in some  information', 'Some sample text');
 
                           'Please type in some  information', 'Some sample text');
 
   ShowMessage (userstring)
 
   ShowMessage (userstring)
  end;
+
  end;</syntaxhighlight>
  
 
===InputQuery===
 
===InputQuery===
Function InputQuery(const ACaption, APrompt : String;
+
<syntaxhighlight lang=pascal> Function InputQuery(const ACaption, APrompt : String;
 
                     MaskInput : Boolean; var Value : String) : Boolean;
 
                     MaskInput : Boolean; var Value : String) : Boolean;
 
  Function InputQuery(const ACaption, APrompt : String;
 
  Function InputQuery(const ACaption, APrompt : String;
                     var Value : String) : Boolean;
+
                     var Value : String) : Boolean;</syntaxhighlight>
 
 
Two versions of this function which displays a prompt and expects user input of textual data; the first includes a MaskInput boolean parameter which determines whether the user input is masked out by asterisks in the text-input box (like during entry of a password), while the second omits this property. The text entered by the user is returned in the variable parameter 'Value'; the function result is a boolean which returns TRUE if the OK button was pressed, or FALSE if the box was closed by any other mechanism (such as clicking the 'Close' icon on the top title bar). Omitting the MaskInput parameter is equivalent to setting it FALSE.
 
  
Example
+
Dve verzie tejto funkcie, ktoré zobrazujú otázku a čakajú používateľský vstup textových dát; prvá verzia zahŕňa logický parameter '''MaskInput''', ktorý určuje, či má byť používateľský vstup v textovom poli maskovaný hviezdičkami (ako pri zadávaní hesla), zatiaľ čo druhá túto vlastnosť vynecháva. Používateľom zadaný text je vrátený v parametri 'Value'; výsledkom funkcie je logická hodnota, ktorá vracia '''TRUE''', ak bolo stlačené tlačítko OK alebo '''FALSE''', ak bolo okno zatvorené iným spôsobom (napríklad kliknutím na ikonu 'Zatvoriť' v lište okna). Vynechanie parametra MaskInput má rovnaký výsledok ako jeho nastavenie na FALSE.
  
Uses forms, lcltype, dialogs, controls;
+
Príklad:
 +
<syntaxhighlight lang=pascal> Uses forms, lcltype, dialogs, controls;
 
   
 
   
 
  procedure TryInputQuery;
 
  procedure TryInputQuery;
Line 137: Line 128:
 
     ShowMessage (userstring);
 
     ShowMessage (userstring);
 
   end
 
   end
  end;
+
  end;</syntaxhighlight>
  
<center> http://lazarus-ccr.sourceforge.net/kbdata/MessageDlgQuestion.png </center>
+
<center>[[Image:MessageDlgQuestion.png]]    [[Image:DontBeSillly.png]]</center>
 
 
<center> http://lazarus-ccr.sourceforge.net/kbdata/DontBeSillly.png </center>
 
  
 
===PasswordBox===
 
===PasswordBox===
Function PasswordBox(const ACaption, APrompt : String) : String;
+
<syntaxhighlight lang=pascal> Function PasswordBox(const ACaption, APrompt : String) : String;</syntaxhighlight>
  
Behaves very similarly to the InputQuery function with MaskInput = TRUE; the difference is that the password that was typed in is returned as the result of the function (like InputBox).
+
Správa sa veľmi podobne ako funkcia '''InputQuery''' s MaskInput = TRUE; rozdiel je, že heslo, ktoré bolo zadané je vrátené ako výsledok funkcie (ako '''InputBox''').
  
==Constants and Types used in message dialogs==
+
==Konštanty a Typy v správových dialógoch ==
  
Several constants and types relevant for use with the dialog boxes are pre-defined in the LCL library:
+
Niektoré konštanty a typy, ktoré majú vzťah k použitiu v dialógových oknách a sú preddefinované v knižnici LCL:
  
const { Defined in LCLType.pp }
+
<syntaxhighlight lang=pascal> const { Defined in LCLType.pp }</syntaxhighlight>
  
integer constants for defining the types of buttons
+
Celočíslené konštanty pre definovanie typov tlačítiek a ikon pre zobrazenie v '''MessageBox'''
and the icon for display in MessageBox
+
<syntaxhighlight lang=pascal> MB_OK = $00000000;
 
 
MB_OK = $00000000;
 
 
  MB_OKCANCEL = $00000001;
 
  MB_OKCANCEL = $00000001;
 
  MB_ABORTRETRYIGNORE = $00000002;
 
  MB_ABORTRETRYIGNORE = $00000002;
Line 163: Line 150:
 
  MB_YESNO = $00000004;
 
  MB_YESNO = $00000004;
 
  MB_RETRYCANCEL = $00000005;
 
  MB_RETRYCANCEL = $00000005;
 
 
   
 
   
 
  MB_ICONHAND = $00000010;
 
  MB_ICONHAND = $00000010;
Line 171: Line 157:
 
  MB_ICONWARNING = MB_ICONEXCLAMATION;
 
  MB_ICONWARNING = MB_ICONEXCLAMATION;
 
  MB_ICONERROR = MB_ICONHAND;
 
  MB_ICONERROR = MB_ICONHAND;
  MB_ICONINFORMATION = MB_ICONASTERICK;
+
  MB_ICONINFORMATION = MB_ICONASTERICK;</syntaxhighlight>
 
 
integer constants defining the return value from MessageBox according to which button was pressed
 
  
IDOK = 1; ID_OK = IDOK;
+
Celočíselné konštanty definujúce návratovú hodnotu z '''MessageBox''', v závislosti na stlačenom tlačítku
 +
<syntaxhighlight lang=pascal> IDOK = 1; ID_OK = IDOK;
 
  IDCANCEL = 2; ID_CANCEL = IDCANCEL;
 
  IDCANCEL = 2; ID_CANCEL = IDCANCEL;
 
  IDABORT = 3; ID_ABORT = IDABORT;
 
  IDABORT = 3; ID_ABORT = IDABORT;
Line 183: Line 168:
 
  IDNO = 7; ID_NO = IDNO;
 
  IDNO = 7; ID_NO = IDNO;
 
  IDCLOSE = 8; ID_CLOSE = IDCLOSE;
 
  IDCLOSE = 8; ID_CLOSE = IDCLOSE;
  IDHELP = 9; ID_HELP = IDHELP;
+
  IDHELP = 9; ID_HELP = IDHELP;</syntaxhighlight>
  
define whether first, second or third button is default
+
Definuje, či je predvolené prvé, druhé alebo tretie tlačítko
  
MB_DEFBUTTON1 = $00000000;
+
<syntaxhighlight lang=pascal> MB_DEFBUTTON1 = $00000000;
 
  MB_DEFBUTTON2 = $00000100;
 
  MB_DEFBUTTON2 = $00000100;
 
  MB_DEFBUTTON3 = $00000200;
 
  MB_DEFBUTTON3 = $00000200;
  MB_DEFBUTTON4 = $00000300;
+
  MB_DEFBUTTON4 = $00000300;</syntaxhighlight>
 
 
The Flags parameter of MessageBox is constructed by adding a button constant [MB_OK..MB_RETRYCANCEL],
 
an optional icon constant [MB_ICONHAND..MB_ICONINFORMATION]
 
and an optional default button constant [MB_DEFBUTTON1..MB_DEFBUTTON3]
 
  
Types for use in MessageDlg, which needs parameters
+
Parameter '''Flags''' funkcie '''MessageBox''' je vytvorený pomocou súčtu konštánt tlačítiek '''[MB_OK..MB_RETRYCANCEL]''', voliteľnej konštanty ikony '''[MB_ICONHAND..MB_ICONINFORMATION]''' a voliteľnej konštanty predvoleného tlačítka '''[MB_DEFBUTTON1..MB_DEFBUTTON3]'''
AType of TMsgDlgType and AButtons of TMSgDlgButtons
 
  
 +
Typy prepoužitie v '''MessageDlg''', ktorý potrebuje parametre AType typu '''TMsgDlgType''' a AButtons typu '''TMSgDlgButtons'''
  
{ Defined in Dialogs.pp }
+
<syntaxhighlight lang=pascal> { Defined in Dialogs.pp }
 
  type
 
  type
 
   TMsgDlgType    = (mtWarning, mtError, mtInformation,  mtConfirmation,
 
   TMsgDlgType    = (mtWarning, mtError, mtInformation,  mtConfirmation,
Line 208: Line 189:
 
   TMsgDlgButtons = set of TMsgDlgBtn;
 
   TMsgDlgButtons = set of TMsgDlgBtn;
 
    
 
    
 
 
  const
 
  const
 
   mbYesNoCancel = [mbYes, mbNo, mbCancel];
 
   mbYesNoCancel = [mbYes, mbNo, mbCancel];
Line 214: Line 194:
 
   mbAbortRetryIgnore = [mbAbort, mbRetry, mbIgnore];
 
   mbAbortRetryIgnore = [mbAbort, mbRetry, mbIgnore];
 
    
 
    
 
 
   MsgDlgBtnToBitBtnKind: array[TMsgDlgBtn] of TBitBtnKind = (
 
   MsgDlgBtnToBitBtnKind: array[TMsgDlgBtn] of TBitBtnKind = (
 
   bkYes, bkNo, bkOK, bkCancel, bkAbort, bkRetry, bkIgnore,
 
   bkYes, bkNo, bkOK, bkCancel, bkAbort, bkRetry, bkIgnore,
 
     bkAll, bkNoToAll, bkYesToAll, bkHelp, bkClose
 
     bkAll, bkNoToAll, bkYesToAll, bkHelp, bkClose
 
   );
 
   );
 
 
   
 
   
 
   BitBtnKindToMsgDlgBtn: array[TBitBtnKind] of TMsgDlgBtn = (
 
   BitBtnKindToMsgDlgBtn: array[TBitBtnKind] of TMsgDlgBtn = (
 
     mbOk, mbOK, mbCancel, mbHelp, mbYes, mbNo,
 
     mbOk, mbOK, mbCancel, mbHelp, mbYes, mbNo,
 
     mbClose, mbAbort, mbRetry, mbIgnore, mbAll, mbNoToALl, mbYesToAll
 
     mbClose, mbAbort, mbRetry, mbIgnore, mbAll, mbNoToALl, mbYesToAll
     );
+
     );</syntaxhighlight>
 
 
   
 
   
{ Defined in Controls.pp }
+
<syntaxhighlight lang=pascal> { Defined in Controls.pp }
 
  const
 
  const
 
   mrNone = 0;
 
   mrNone = 0;
Line 240: Line 217:
 
   mrNoToAll = mrNone + 9;
 
   mrNoToAll = mrNone + 9;
 
   mrYesToAll = mrNone + 10;
 
   mrYesToAll = mrNone + 10;
   mrLast = mrYesToAll;
+
   mrLast = mrYesToAll;</syntaxhighlight>
  
 
----
 
----
This page has been imported from the epikwiki [http://lazarus-ccr.sourceforge.net/index.php?wiki=DialogExamples version].
+
*Initial translation by --[[User:Slavko|Komunista]] 20:57, 17 November 2008 (CET)
 +
*This page has been imported from the epikwiki [http://lazarus-ccr.sourceforge.net/index.php?wiki=DialogExamples version].

Latest revision as of 07:15, 13 February 2020

Deutsch (de) English (en) español (es) suomi (fi) français (fr) 日本語 (ja) polski (pl) русский (ru) slovenčina (sk) 中文(中国大陆)‎ (zh_CN)

Niektoré užitočné dialógy

Toto sú niektoré užitočné dialógy, ktoré nenájdete v Palete komonentov:

  • procedure ShowMessage (const Msg: string);
  • function MessageBox (Text, Caption : PChar; Flags: Word): Integer;
  • function MessageDlg (const Msg: string; AType: TMsgDlgType; AButtons: TMsgDlgButtons; HelpCtx: LongInt): Word;
  • function InputBox (const ACaption, APrompt, ADefault: string); string;
  • function InputQuery (const ACaption, APrompt: string; var Value: string): Boolean;
  • function PasswordBox(const ACaption, APrompt : String) : String;

Každý z týchto komponentov zobrazuje malé vyskakovacie dialógové okno, ktoré obsahuje nejaké informácie a vyžaduje odozvu používateľa: stlačenie tlačítka, zadanie textu alebo oboje. Programátor má minimálnu kontrolu nad formátom, veľkosťou alebo pozíciou týchto vyskakovacích okien, ale môže ovplyvňovať ich textový obsah.
Dôvodom prečo často existujú veľmi podobné alternatívy, je umožniť rôzne spôsoby volania komponentu, a získavania dát, z procedúr a funkcií.

Správové dialógy

Správové dialógy zobrazujú správu a čakajú na stlačenie klávesy alebo kliknutie myšou.

ShowMessage

 Procedure ShowMessage (const Msg: string);
 
 { Defined in Dialogs.pp }

Najjednoduchší správový dialóg: prijíma jednoduchý textový prarmeter, zobrazí ho v stereotypnom okne a pred vrátením, do volajúcej rutiny alebo programu, čaká na kliknutie myšou alebo kláves enter.
Toto je modálne volanie procedúry, ktoré zobrazí okno, získa zameranie a tohoto sa nevzdá, pokiaľ nie je stlačené OK.

Príklad:

 Program LazMessage;
 Uses Dialogs;
 begin
   ShowMessage ('Toto je správa z Lazarusu!')
 end.

MessageBox

 Function Application.MessageBox (Text, Caption: PChar; Flags: longint) : Integer;
 
 { Defined in Forms.pp as part of TApplication; hence must be called as Application.Messagebox () 
   or using the 'with Application do ...' construct }

Parametre:

  • Text: reťazec, ktorý je v okne zobrazený ako otázka ale inštrukcia;
  • Caption: textový štítok, ktorý je zobrazený na vrchu okna správy;
  • Flags: longint - integer vytvorený sčítaním rôznych konštánt, ktorými je definovaný obsah a správanie okna, napríklad MB_ABORTRETRYIGNORE + MR_ICONQUESTION nastaví, že aplikácia zobrazí ikonu otázky (?) v okne s tromi tlačítkami: ABORT, RETRY a IGNORE.

Funkcia vracia hodnotu integer, ktorá zodpovedá stlačenému tlačítku; jej hodnota je daná odkazom na konštanty [IDOK..IDHELP]

Môže byť volaná ako procedúra (tj. formulácia 'MessageBox()' namiesto volania funkcie 'Variable := MessageBox()' – viz. príklad nižšie)

Príklad:

 Uses Forms, Dialogs, LCLType;
 
 Procedure DisplayMessageBox;
   var reply, boxstyle: integer;
   begin
     with application do begin
       boxstyle :=  MB_ICONQUESTION + MB_YESNO;
       reply :=  MessageBox ('Press either button', 'MessageBoxDemo', boxstyle);
       if reply = IDYES then MessageBox ('Yes       ', 'Reply',MB_ICONINFORMATION)
       else MessageBox ('No         ', 'Reply', MB_ICONHAND);
   end;

Všimnite si, že v tomto príklade sú reťazce 'Yes' a 'No' doplnené medzerami; inak by okno nebolo dosť široké na správne zobrazenie titulku.

MessageBoxDemo.png ReplyYes.png

MessageDLG

 function MessageDlg(const aMsg: string; DlgType: TMsgDlgType; 
                    Buttons: TMsgDlgButtons; HelpCtx: Longint): Integer;
 function MessageDlg(const aCaption, aMsg: string; DlgType: TMsgDlgType; 
                    Buttons: TMsgDlgButtons; HelpCtx: Longint): Integer;

Táto funkcia má dve verzie, teda prvý parameter 'Caption' je voliteľný, ak je vynechaný nie je zobrazený Titulok.

Toto je najkomplexnejší a najprepracovanejší správový dialóg, ktorý poskytuje programátorovi značnú kontrolu nad vzhľadom dialógového okna. Parametre definujúce typ okna a jeho ikonu sú typy, namiesto konštánt a tlačítka môžu byť zadané ako množina v lomených zátvorkách, napr. [mbRetry, mbIgnore, mbAbort, mbCancel]. Parameter HelpCtx aktuálne nie je implementovaný a musí bať nastavený na nulu. Návratová hodnota funkcie je identická ako stlačené tlačítko, reprezentovaná ako integer (viz nasledujúcu definície, [mrNone..mrAll]).

Príklad:

 Uses forms, dialogs, lcltype, controls;
 
 procedure TryMessageDlg;
 begin
   if MessageDlg ('Question', 'Do you wish to Execute?', mtConfirmation, 
                  [mbYes, mbNo, mbIgnore], 0) = mrYes
   then 
     { Execute rest of Program };
  end;
Question.png

Dialógy textového vstupu

Dialógy textového vstupu, zobrazujú správu a dovoľujú používateľovi zadať požadovanú textovú hodnotu.

InputBox

Function InputBox(const ACaption, APrompt, ADefault : String) : String;

Zobrazuje okno s definovaným nadpisom, otázku a čaká na používateľský vstup v textovom poli. Voliteľne môže byť pre textové pole definovaný aj predvolený reťazec. Používateľom zadaný text alebo predvolený reťazec je vrátený ako výsledok funkcie.

Príklad:

 Uses forms, lcltype, dialogs, controls;
 
 procedure TryInputBox;
 var userstring: string;
 begin
   userstring := InputBox ('Get some text input', 
                          'Please type in some   information', 'Some sample text');
   ShowMessage (userstring)
 end;

InputQuery

 Function InputQuery(const ACaption, APrompt : String;
                     MaskInput : Boolean; var Value : String) : Boolean;
 Function InputQuery(const ACaption, APrompt : String;
                     var Value : String) : Boolean;

Dve verzie tejto funkcie, ktoré zobrazujú otázku a čakajú používateľský vstup textových dát; prvá verzia zahŕňa logický parameter MaskInput, ktorý určuje, či má byť používateľský vstup v textovom poli maskovaný hviezdičkami (ako pri zadávaní hesla), zatiaľ čo druhá túto vlastnosť vynecháva. Používateľom zadaný text je vrátený v parametri 'Value'; výsledkom funkcie je logická hodnota, ktorá vracia TRUE, ak bolo stlačené tlačítko OK alebo FALSE, ak bolo okno zatvorené iným spôsobom (napríklad kliknutím na ikonu 'Zatvoriť' v lište okna). Vynechanie parametra MaskInput má rovnaký výsledok ako jeho nastavenie na FALSE.

Príklad:

 Uses forms, lcltype, dialogs, controls;
 
 procedure TryInputQuery;
 var QueryResult: boolean;
   userstring: string;
 begin
   if InputQuery ('Question', 'Type in some data', TRUE, userstring)
   then ShowMessage (userstring)
   else 
   begin
     InputQuery ('Don''t be silly', 'Please try again', userstring);
     ShowMessage (userstring);
   end
 end;
MessageDlgQuestion.png DontBeSillly.png

PasswordBox

 Function PasswordBox(const ACaption, APrompt : String) : String;

Správa sa veľmi podobne ako funkcia InputQuery s MaskInput = TRUE; rozdiel je, že heslo, ktoré bolo zadané je vrátené ako výsledok funkcie (ako InputBox).

Konštanty a Typy v správových dialógoch

Niektoré konštanty a typy, ktoré majú vzťah k použitiu v dialógových oknách a sú preddefinované v knižnici LCL:

 const { Defined in LCLType.pp }

Celočíslené konštanty pre definovanie typov tlačítiek a ikon pre zobrazenie v MessageBox

 MB_OK = $00000000;
 MB_OKCANCEL = $00000001;
 MB_ABORTRETRYIGNORE = $00000002;
 MB_YESNOCANCEL = $00000003;
 MB_YESNO = $00000004;
 MB_RETRYCANCEL = $00000005;
 
 MB_ICONHAND = $00000010;
 MB_ICONQUESTION = $00000020;
 MB_ICONEXCLAMATION = $00000030;
 MB_ICONASTERICK = $00000040;
 MB_ICONWARNING = MB_ICONEXCLAMATION;
 MB_ICONERROR = MB_ICONHAND;
 MB_ICONINFORMATION = MB_ICONASTERICK;

Celočíselné konštanty definujúce návratovú hodnotu z MessageBox, v závislosti na stlačenom tlačítku

 IDOK = 1; 	ID_OK = IDOK;
 IDCANCEL = 2;	ID_CANCEL = IDCANCEL;
 IDABORT = 3;	ID_ABORT = IDABORT;
 IDRETRY = 4;	ID_RETRY = IDRETRY;
 IDIGNORE = 5;	ID_IGNORE = IDIGNORE;
 IDYES = 6;	ID_YES = IDYES;
 IDNO = 7;	ID_NO = IDNO;
 IDCLOSE = 8;	ID_CLOSE = IDCLOSE;
 IDHELP = 9;	ID_HELP = IDHELP;

Definuje, či je predvolené prvé, druhé alebo tretie tlačítko

 MB_DEFBUTTON1 = $00000000;
 MB_DEFBUTTON2 = $00000100;
 MB_DEFBUTTON3 = $00000200;
 MB_DEFBUTTON4 = $00000300;

Parameter Flags funkcie MessageBox je vytvorený pomocou súčtu konštánt tlačítiek [MB_OK..MB_RETRYCANCEL], voliteľnej konštanty ikony [MB_ICONHAND..MB_ICONINFORMATION] a voliteľnej konštanty predvoleného tlačítka [MB_DEFBUTTON1..MB_DEFBUTTON3]

Typy prepoužitie v MessageDlg, ktorý potrebuje parametre AType typu TMsgDlgType a AButtons typu TMSgDlgButtons

 { Defined in Dialogs.pp }
 type
  TMsgDlgType    = (mtWarning, mtError, mtInformation,  mtConfirmation,
                    mtCustom);
  TMsgDlgBtn     = (mbYes, mbNo, mbOK, mbCancel, mbAbort, mbRetry, mbIgnore,
                   mbAll, mbNoToAll, mbYesToAll, mbHelp, mbClose);
  TMsgDlgButtons = set of TMsgDlgBtn;
  
 const
  mbYesNoCancel = [mbYes, mbNo, mbCancel];
  mbOKCancel = [mbOK, mbCancel];
  mbAbortRetryIgnore = [mbAbort, mbRetry, mbIgnore];
  
  MsgDlgBtnToBitBtnKind: array[TMsgDlgBtn] of TBitBtnKind = (
   bkYes, bkNo, bkOK, bkCancel, bkAbort, bkRetry, bkIgnore,
    bkAll, bkNoToAll, bkYesToAll, bkHelp, bkClose
   );
 
  BitBtnKindToMsgDlgBtn: array[TBitBtnKind] of TMsgDlgBtn = (
    mbOk, mbOK, mbCancel, mbHelp, mbYes, mbNo,
    mbClose, mbAbort, mbRetry, mbIgnore, mbAll, mbNoToALl, mbYesToAll
    );
 { Defined in Controls.pp }
 const
  mrNone = 0;
  mrOK = mrNone + 1;
  mrCancel = mrNone + 2;
  mrAbort = mrNone + 3;
  mrRetry = mrNone + 4;
  mrIgnore = mrNone + 5;
  mrYes = mrNone + 6;
  mrNo = mrNone + 7;
  mrAll = mrNone + 8;
  mrNoToAll = mrNone + 9;
  mrYesToAll = mrNone + 10;
  mrLast = mrYesToAll;

  • Initial translation by --Komunista 20:57, 17 November 2008 (CET)
  • This page has been imported from the epikwiki version.