Difference between revisions of "Dialog Examples/ja"

From Free Pascal wiki
Jump to navigationJump to search
 
(10 intermediate revisions by 2 users not shown)
Line 2: Line 2:
 
{{Japanese Menu}}
 
{{Japanese Menu}}
  
= 使いやすいダイアログ =
+
= 便利なダイアログ =
ここでは、コンポーネントパレットにはない、使いやすいダイアログを紹介します:
+
ここでは、コンポーネントパレットにはない、便利なダイアログを紹介します:
  
* procedure ShowMessage (const Msg: string);
+
* procedure [[Dialog_Examples/ja#ShowMessage | ShowMessage ]] (const Msg: string);
 
* function MessageBox (Text, Caption : PChar; Flags: Word): Integer;
 
* function MessageBox (Text, Caption : PChar; Flags: Word): Integer;
 
* function MessageDlg (const Msg: string; AType: TMsgDlgType; AButtons: TMsgDlgButtons; HelpCtx: LongInt): Word;
 
* function MessageDlg (const Msg: string; AType: TMsgDlgType; AButtons: TMsgDlgButtons; HelpCtx: LongInt): Word;
Line 12: Line 12:
 
* 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>
+
どのコンポーネントも、幾つかの情報とユーザのレスポンスを求める小さなポップアップを表示します: ボタンを押すか何かテキストを入力するか、もしくはその両方の種類があります。プログラマーはフォーマットやサイズ、ポップアップの場所をある程度制御することが出来ます。また、テキストの内容を変更することもできます。<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.
+
このように幾つかのとてもよく似た選択がある理由は、コンポーネントの呼び出し方や、procedure や function から返されたデータの受け取りに異なる手法できるようにするためです。
  
 
== メッセージダイアログ ==
 
== メッセージダイアログ ==
 
メッセージダイアログは、メッセージを表示したり、キー入力やマウスクリックを待つといった際に使用します。
 
メッセージダイアログは、メッセージを表示したり、キー入力やマウスクリックを待つといった際に使用します。
  
===ShowMessage===
+
=== ShowMessage ===
 
  Procedure ShowMessage (const Msg: string);
 
  Procedure ShowMessage (const Msg: string);
 
   
 
   
 
  { Defined in Dialogs.pp }
 
  { Defined in Dialogs.pp }
  
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>
+
もっともシンプルなメッセージダイアログです: シンプルな文字をパラメータとして指定し、所定の形状のダイアログを表示します。ランタイムやプログラムから呼び出され、マウスクリックもしくは 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.
+
これは呼び出しの例です。ダイアログを表示し、フォーカスを受け取ります。なお、OK ボタンをクリックされるまでフォーカスを放棄しません。
  
 
例:
 
例:
Line 31: Line 31:
 
  Uses Dialogs;
 
  Uses Dialogs;
 
  begin
 
  begin
   ShowMessage ('This is a message from Lazarus')
+
   ShowMessage ('これは Lazarus からのメッセージです')
 
  end.
 
  end.
  
Line 43: Line 43:
 
* Text: ボックス内に表示される指示や紹介用の文字列;
 
* Text: ボックス内に表示される指示や紹介用の文字列;
 
* Caption: メッセージボックスの上にあるラベル文字列;
 
* Caption: メッセージボックスの上にあるラベル文字列;
* 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.
+
* Flags: longint - メッセージボックスの内容と振る舞いを定義するため様々な定数を、必要に応じて加算して指定します。例えば MB_ABORTRETRYIGNORE + MR_ICONQUESTION とすれば、メッセージボックス内には ABORT RETRY IGNORE の3つのボタンと問い合わせ(?)アイコンの付いたメッセージボックスを表示させることになります。
  
 
この関数は押されたボタンに応じて整数値を返します。この数値は[IDOK..IDHELP] といった定数値を参照して値が決定されます。
 
この関数は押されたボタンに応じて整数値を返します。この数値は[IDOK..IDHELP] といった定数値を参照して値が決定されます。
Line 63: Line 63:
 
   end;
 
   end;
  
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
+
この例での 'Yes' 'No' の文字列ですが、後ろに空白文字を追加して文字長を長くしています。というのも、キャプションをちゃんと表示するのに十分な幅にならない為です。
 +
 
  
 
<center> http://lazarus-ccr.sourceforge.net/kbdata/MessageBoxDemo.png  http://lazarus-ccr.sourceforge.net/kbdata/ReplyYes.png
 
<center> http://lazarus-ccr.sourceforge.net/kbdata/MessageBoxDemo.png  http://lazarus-ccr.sourceforge.net/kbdata/ReplyYes.png
Line 98: Line 99:
 
== 文字入力ダイアログ ==
 
== 文字入力ダイアログ ==
 
===InputBox===
 
===InputBox===
Text input Dialogs: display a message and await user text input
+
テキスト入力ダイアログ: ダイアログを表示し、ユーザにテキスト入力を促します。
  
 
  Function InputBox(const ACaption, APrompt, ADefault : String) : String;
 
  Function InputBox(const ACaption, APrompt, ADefault : String) : String;
  
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.
+
タイトルとプロンプトのある四角いフォームを表示して、ユーザーにテキストボックスに入力を促します。オプションとしてデフォルトの文字列を表示させることができます。ユーザーが入力したり、あるいはデフォルトのままの文字列が関数の戻り値として返されます。
  
Example
+
  
 
  Uses forms, lcltype, dialogs, controls;
 
  Uses forms, lcltype, dialogs, controls;
Line 122: Line 123:
 
                     var Value : String) : Boolean;
 
                     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.
+
この関数には、2つのバージョンがあり、どちらもプロンプトを表示して、ユーザーにテキストデータの入力をもとめます。最初のものは、MascInputという論理値のパラメータがあり、ユーザーの入力が、(パスワード入力中のように)入力ボックス内でアスタリスクでマスクされるかどうかを決めることができます。2番目のものは、このプロパティはありません。ユーザーが入力したテキストは、'Value'という変数パラメータで返されます。この関数の戻り値は、'OK'が押されたときはTRUEを、その他の方法(たとえば、タイトルバーの'閉じる'アイコンをクリックされたときなど)で入力フォームが閉じられたときは、FALSEを返します。MaskInputパラメータを省略することは、MaskInputパラメータにFALSEを指定することと同じです。
 +
 
  
Example
+
例:
  
 
  Uses forms, lcltype, dialogs, controls;
 
  Uses forms, lcltype, dialogs, controls;
Line 150: Line 152:
 
MaskInput を TRUE にした状態の InputQuery 関数とよく似た動作です。違いは、関数(InputBox のように)の返し値にパスワードがセットされる点です。
 
MaskInput を TRUE にした状態の InputQuery 関数とよく似た動作です。違いは、関数(InputBox のように)の返し値にパスワードがセットされる点です。
  
==Constants and Types used in message dialogs==
+
== メッセージダイアログで使用される定数値と型 ==
  
Several constants and types relevant for use with the dialog boxes are pre-defined in the LCL library:
+
幾つかのメッセージダイアログで使用される定数値と型は LCL ライブラリの中で予め定義されています:
  
 
const { Defined in LCLType.pp }
 
const { Defined in LCLType.pp }
  
integer constants for defining the types of buttons
+
メッセージボックスの外観にあるアイコンとボタンの型を定義する定数値
and the icon for display in MessageBox
 
  
 
  MB_OK = $00000000;
 
  MB_OK = $00000000;
Line 175: Line 176:
 
  MB_ICONINFORMATION = MB_ICONASTERICK;
 
  MB_ICONINFORMATION = MB_ICONASTERICK;
  
integer constants defining the return value from MessageBox according to which button was pressed
+
ボタンが押された時に、MessageBox から送られる一致するボタンの種類の定数値
  
 
  IDOK = 1; ID_OK = IDOK;
 
  IDOK = 1; ID_OK = IDOK;
Line 187: Line 188:
 
  IDHELP = 9; ID_HELP = IDHELP;
 
  IDHELP = 9; ID_HELP = IDHELP;
  
define whether first, second or third button is default
+
1番目のボタン、2番目のボタン、3番目のボタン...のどれがデフォルトかを定義します。
  
 
  MB_DEFBUTTON1 = $00000000;
 
  MB_DEFBUTTON1 = $00000000;
Line 194: Line 195:
 
  MB_DEFBUTTON4 = $00000300;
 
  MB_DEFBUTTON4 = $00000300;
  
The Flags parameter of MessageBox is constructed by adding a button constant [MB_OK..MB_RETRYCANCEL],
+
MessageBoxのFlagsパラメータは、ボタン定数を加えることで指定します。
an optional icon constant [MB_ICONHAND..MB_ICONINFORMATION]
+
[MB_OK..MB_RETRYCANCEL],
and an optional default button constant [MB_DEFBUTTON1..MB_DEFBUTTON3]
+
オプションとしてアイコン定数があります。
 +
[MB_ICONHAND..MB_ICONINFORMATION]
 +
さらにオプションとして、デフォルトボタン定数があります。
 +
[MB_DEFBUTTON1..MB_DEFBUTTON3]
  
Types for use in MessageDlg, which needs parameters
+
MessageDlgを使う型は、次のようなパラメータを必要とします。
AType of TMsgDlgType and AButtons of TMSgDlgButtons
+
TMsgDlgTypeのAType, TMsgDlgButtonsのAButtons
  
  
Line 245: Line 249:
  
 
----
 
----
This page has been imported from the epikwiki [http://lazarus-ccr.sourceforge.net/index.php?wiki=DialogExamples version].
+
このページはepikwiki [http://lazarus-ccr.sourceforge.net/index.php?wiki=DialogExamples バージョン]からインポートされました。

Latest revision as of 15:23, 28 October 2006

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

日本語版メニュー
メインページ - Lazarus Documentation日本語版 - 翻訳ノート - 日本語障害情報

便利なダイアログ

ここでは、コンポーネントパレットにはない、便利なダイアログを紹介します:

  • 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;

どのコンポーネントも、幾つかの情報とユーザのレスポンスを求める小さなポップアップを表示します: ボタンを押すか何かテキストを入力するか、もしくはその両方の種類があります。プログラマーはフォーマットやサイズ、ポップアップの場所をある程度制御することが出来ます。また、テキストの内容を変更することもできます。
このように幾つかのとてもよく似た選択がある理由は、コンポーネントの呼び出し方や、procedure や function から返されたデータの受け取りに異なる手法できるようにするためです。

メッセージダイアログ

メッセージダイアログは、メッセージを表示したり、キー入力やマウスクリックを待つといった際に使用します。

ShowMessage

Procedure ShowMessage (const Msg: string);

{ Defined in Dialogs.pp }

もっともシンプルなメッセージダイアログです: シンプルな文字をパラメータとして指定し、所定の形状のダイアログを表示します。ランタイムやプログラムから呼び出され、マウスクリックもしくは Enter キーが押されるまで待機します。
これは呼び出しの例です。ダイアログを表示し、フォーカスを受け取ります。なお、OK ボタンをクリックされるまでフォーカスを放棄しません。

例:

Program LazMessage;
Uses Dialogs;
begin
  ShowMessage ('これは Lazarus からのメッセージです')
end.

MessageBox

Function Application.MessageBox (Text, Caption: PChar; Flags: longint) : Integer;

{ Forms.pp 内の TApplication で定義されています; よって Application.Messagebox () と記述するか、 'with Application do ...end'  の中でコールする必要があります}

パラメータは次の通りです。

  • Text: ボックス内に表示される指示や紹介用の文字列;
  • Caption: メッセージボックスの上にあるラベル文字列;
  • Flags: longint 型 - メッセージボックスの内容と振る舞いを定義するため様々な定数を、必要に応じて加算して指定します。例えば MB_ABORTRETRYIGNORE + MR_ICONQUESTION とすれば、メッセージボックス内には ABORT RETRY IGNORE の3つのボタンと問い合わせ(?)アイコンの付いたメッセージボックスを表示させることになります。

この関数は押されたボタンに応じて整数値を返します。この数値は[IDOK..IDHELP] といった定数値を参照して値が決定されます。

これは procedure コールのように呼び出すこともできます(ただ'MessageBox()'という記述よりも'Variable := MessageBox()' というファンクションコールで使用します - 下の例を見て下さい)

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;

この例での 'Yes' と 'No' の文字列ですが、後ろに空白文字を追加して文字長を長くしています。というのも、キャプションをちゃんと表示するのに十分な幅にならない為です。


http://lazarus-ccr.sourceforge.net/kbdata/MessageBoxDemo.png http://lazarus-ccr.sourceforge.net/kbdata/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;

この関数には二つのバージョンがあります。最初のキャプション(Caption)パラメータが任意です。もし省略した場合、キャプションは表示されません。

MessageDLGは、メッセージダイアログの中で最も完全で詳細なもので、プログラマーは様々なこれを使って様々なダイアログボックスを作成できます。 ボックスやアイコンの種類を定義するパラメータは整数の定数値よりも、むしろ定義の方を使用します。ボタンで言えば [mbRetry, mbIgnore, mbAbort,mbCancel] といったコの字括弧を使って定義されています。 HelpCtx パラメータは現在使われておらず、0 をセットしておく必要があります。 関数から返された値は、押されたボタンの識別番号であり、Integer 型の扱いになります。(下に述べる[mrNone..mrAll]を参照して下さい)

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;


http://lazarus-ccr.sourceforge.net/kbdata/Question.png

文字入力ダイアログ

InputBox

テキスト入力ダイアログ: ダイアログを表示し、ユーザにテキスト入力を促します。

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

タイトルとプロンプトのある四角いフォームを表示して、ユーザーにテキストボックスに入力を促します。オプションとしてデフォルトの文字列を表示させることができます。ユーザーが入力したり、あるいはデフォルトのままの文字列が関数の戻り値として返されます。

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;

この関数には、2つのバージョンがあり、どちらもプロンプトを表示して、ユーザーにテキストデータの入力をもとめます。最初のものは、MascInputという論理値のパラメータがあり、ユーザーの入力が、(パスワード入力中のように)入力ボックス内でアスタリスクでマスクされるかどうかを決めることができます。2番目のものは、このプロパティはありません。ユーザーが入力したテキストは、'Value'という変数パラメータで返されます。この関数の戻り値は、'OK'が押されたときはTRUEを、その他の方法(たとえば、タイトルバーの'閉じる'アイコンをクリックされたときなど)で入力フォームが閉じられたときは、FALSEを返します。MaskInputパラメータを省略することは、MaskInputパラメータにFALSEを指定することと同じです。


例:

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;
http://lazarus-ccr.sourceforge.net/kbdata/MessageDlgQuestion.png
http://lazarus-ccr.sourceforge.net/kbdata/DontBeSillly.png

PasswordBox

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

MaskInput を TRUE にした状態の InputQuery 関数とよく似た動作です。違いは、関数(InputBox のように)の返し値にパスワードがセットされる点です。

メッセージダイアログで使用される定数値と型

幾つかのメッセージダイアログで使用される定数値と型は LCL ライブラリの中で予め定義されています:

const { Defined in LCLType.pp }

メッセージボックスの外観にあるアイコンとボタンの型を定義する定数値

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;

ボタンが押された時に、MessageBox から送られる一致するボタンの種類の定数値

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;

1番目のボタン、2番目のボタン、3番目のボタン...のどれがデフォルトかを定義します。

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

MessageBoxのFlagsパラメータは、ボタン定数を加えることで指定します。 [MB_OK..MB_RETRYCANCEL], オプションとしてアイコン定数があります。 [MB_ICONHAND..MB_ICONINFORMATION] さらにオプションとして、デフォルトボタン定数があります。 [MB_DEFBUTTON1..MB_DEFBUTTON3]

MessageDlgを使う型は、次のようなパラメータを必要とします。 TMsgDlgTypeのAType, TMsgDlgButtonsのAButtons


{ 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;

このページはepikwiki バージョンからインポートされました。