Difference between revisions of "Dialog Examples/de"
Line 94: | Line 94: | ||
== Texteingabe Dialoge== | == Texteingabe Dialoge== | ||
===InputBox=== | ===InputBox=== | ||
− | + | Texteingabe Dialoge: zeigen eine Nachricht und erwarten eine Benutzereingabe | |
Function InputBox(const ACaption, APrompt, ADefault : String) : String; | Function InputBox(const ACaption, APrompt, ADefault : String) : String; | ||
− | + | Zeigt eine Box mit definiertem Titel und Eingabeaufforderung, und erwartet die Benutzereingabe in einem Textfeld. Eine Vorgabe-Zeichenkette kann optional im Textfeld angezeigt werden. Die vom Benutzer eingegebene oder die Vorgabe-Zeichenkette wird als Funktionsergebnis zurückgegeben. | |
Beispiel | Beispiel |
Revision as of 14:14, 15 October 2005
Einige nützliche Dialoge
Dies sind einige nützliche Dialoge, die nicht in der Komponentenpalette zu finden sind:
- 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;
Jede dieser Komponenten bewirkt die Anzeige einer kleinen popup Box, welche einige Informationen enthält und eine Benutzer Rückmeldung erfordert: entweder eine Schaltfläche drücken oder Texteingabe oder beides. Der Porgrammierer hat kaum Kontrolle über das Format, die Größe oder Position dieser popup Boxen, aber kann den textlichen Inhalt beeinflussen.
Der Grund warum es oft verschiedene sehr ähnliche Alternativen gibt, ist es verschiedene Methoden des Aufrufs von Komponenten zu erlauben und Daten zurück von der Prozedur oder Funktion zu erhalten.
Nachrichten Dialoge
Nachrichten Dialoge zeigen eine Nachricht an und warten auf eine Tastendruck-oder Mausklick-Antwort.
ShowMessage
Procedure ShowMessage (const Msg: string); { Definiert in Dialogs.pp }
Der einfachste Nachrichtendialog: nimmt eine einfache Zeichenkette als Parameter, zeigt sie in einer stereotypen Box, und wartet auf ein Mausklick oder Tastendruck Ereignis bevor er zur aufrufenden Routine oder Programm zurückkehrt.
Dies ist ein modaler Prozeduraufruf, der eine Box anzeigt, und den Fokus nicht zurückgibt bis die OK Box angeklickt wird oder anderweitig gewählt wird.
Beispiel:
Program LazMessage; Uses Dialogs; begin ShowMessage ('Dies ist eine Nachricht von Lazarus') end.
MessageBox
Function Application.MessageBox (Text, Caption: PChar; Flags: longint) : Integer; { Definiert in Forms.pp als Teil von TApplication; muß deshalb aufgerufen werden als Application.Messagebox () oder unter Verwendung des 'with Application do ...' Konstrukts }
Enthaltene Parameter
- Text: die Zeichenkette, die als Hinweis oder Anleitung in der Box angezeigt wird;
- Caption: die Zeichenketten Beschriftung oben in der Nachrichten Box;
- Flags: longint - ein 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.
Die Funktion gibt einen Integer Wert zurück entsprechend der gedrückten Schaltfläche; sein Wert kann festgelegt werden durch Referenz auf die Konstanten [IDOK..IDHELP]
Sie kann aufgerufen werden wie ein Prozeduraufruf (d.h. wie eine 'MessageBox()' Anweisung eher als ein 'Variable := MessageBox()' Funktionsaufruf - siehe Beispiel unten)
Beispiel
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;
Beachten sie, daß in diesem Beispiel die 'Yes' und 'No' Zeichenketten ohne Leerzeichen gefüllt wurden; andernfalls wäre die Box nicht breit genug um die Beschriftung richtig anzuzeigen
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;
Es gibt zwei Versionen dieser Funktion, daß heißt der erste 'Caption' Parameter ist optional; wenn er weggelassen wird, fehlt die Überschrift in der Box.
Dies ist der kompletteste und aufwendigste der Nachrichtendialoge, und erlaubt dem Programmierer beachtliche Kontrolle über das Erscheinungsbild der Dialogbox. Die Parameter, welche die Art der Box und ihr Icon definieren, sind eigentlich Typen wie Integer Konstanten, und die Schaltflächen können spezifiziert werden als Gruppe in eckigen Klammern z.B. [mbRetry, mbIgnore, mbAbort, mbCancel]. Der HelpCtx Parameter ist gegenwärtig nicht implementiert und sollte auf Null gesetzt werden. Der Rückgabewert der Funktion ist die Identität der gedrückten Schaltfläche, ausgedrückt als ein Integer (siehe die Definitionen unten, [mrNone..mrAll]).
Beispiel
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;
Texteingabe Dialoge
InputBox
Texteingabe Dialoge: zeigen eine Nachricht und erwarten eine Benutzereingabe
Function InputBox(const ACaption, APrompt, ADefault : String) : String;
Zeigt eine Box mit definiertem Titel und Eingabeaufforderung, und erwartet die Benutzereingabe in einem Textfeld. Eine Vorgabe-Zeichenkette kann optional im Textfeld angezeigt werden. Die vom Benutzer eingegebene oder die Vorgabe-Zeichenkette wird als Funktionsergebnis zurückgegeben.
Beispiel
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;
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.
Beispiel
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 ('Dont be silly', 'Please try again', userstring); ShowMessage (userstring) end end;
PasswordBox
Function PasswordBox(const ACaption, APrompt : String) : String;
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).
Constants und Types used in message dialogs
Several constants and types relevant for use with the dialog boxes are pre-defined in the LCL library:
const { Defined in LCLType.pp }
integer constants for defining the types of buttons and the icon for display in 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;
integer constants defining the return value from MessageBox according to which button was pressed
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;
define whether first, second or third button is default
MB_DEFBUTTON1 = $00000000; MB_DEFBUTTON2 = $00000100; MB_DEFBUTTON3 = $00000200; MB_DEFBUTTON4 = $00000300;
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 AType of TMsgDlgType and AButtons of 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 ); { Definiert 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;
Diese Seite wurde von der epikwiki Version importiert.