Difference between revisions of "TMemo/ja"

From Lazarus wiki
Jump to navigationJump to search
(Created page with "{{TMemo}} {{ Japanese Menu }} A '''TMemo''' image:tmemo.png is a control with multiple lines of editable text. It is available from the [[Standard tab/ja|Standardタブ]...")
 
 
(2 intermediate revisions by the same user not shown)
Line 3: Line 3:
 
{{ Japanese Menu }}
 
{{ Japanese Menu }}
  
A '''TMemo''' [[image:tmemo.png]] is a control with multiple lines of editable text. It is available from the [[Standard tab/ja|Standardタブ]] of the [[Component Palette/ja|コンポーネントパレット]].
+
'''TMemo''' [[image:tmemo.png]]は複数行を編集できるコントロールである。[[Component Palette/ja|コンポーネントパレット]]タブの[[Standard tab/ja|Standardタブ]]から利用できる。
  
==Usage==
+
==使い方==
To use a TMemo on a [[TForm|form]], you can simply select it on the ''Standard'' component pallet and place it by clicking on the form. In this text box, you can now edit a multiline text at run time.
+
TMemoを用いるには[[TForm|form]]''Standard''コンポーネントパレットで選択しフォーム上でクリックすればよい。このテキストボックスで実行時に複数行のテキストを編集できる。
  
For example, have you added a TMemo ''Memo1'' to your form ''Form1'', you can use '''<code>Memo1.Text:='this is a singleline text';</code>''' to assign a [[String]].
+
例えば、フォーム、''Form1''へTMemo ''Memo1''を加えると[[String]]に'''<code>Memo1.Text:='これは1行のテキストです';</code>'''と割り当てることができる。
  
Also you can use anywhere in the source code the stored text of ''Memo1'' with '''<code>myString:=Memo1.Text;</code>'''.
+
また、'''<code>myString:=Memo1.Text;</code>'''として、保存されたテキスト''Memo1''をソースの中のどこでも使うことができる。
  
It is also possible to assign a multiline text with '''<code>Memo1.Text:='This'+LineEnding+'is'+LineEnding+'a'+LineEnding+'multiline'+LineEnding+'text';
+
複数行のテキスト、'''<code>Memo1.Text:=' これは '+LineEnding+' 複数行の '+LineEnding+' テキスト '+LineEnding+' です ';</code>'''を割り当てることも可能である。
</code>'''.
 
  
===Assignment of a TStrings or TStringList===
+
===TStringsもしくはTStringListを割り当てる===
Common, to assign a text to a TMemo is the use of a [[TStringList-TStrings Tutorial|TStringList]] or its parent [[TStringList-TStrings Tutorial|TStrings]]. The following example shows this (in the event handler of an inserted [[TButton]] ''Button1'' in a [[TForm|form]] ''Form1'' and a TMemo ''Memo1'' on it):
+
通常、TMemoにテキストを割り当てるには、[[TStringList-TStrings Tutorial|TStringList]]、もしくはその親の[[TStringList-TStrings Tutorial|TStrings]]を利用する。以下の例([[TForm|form]] ''Form1''とTMemo ''Memo1''を用いて挿入された[[TButton/ja|TButton]] ''Button1''イベントハンドラで)はこれを示している:
  
 
<syntaxhighlight lang=pascal>
 
<syntaxhighlight lang=pascal>
Line 23: Line 22:
 
   myStringList: TStringList;
 
   myStringList: TStringList;
 
begin
 
begin
   myStringList:=TStringList.Create;              //Create my StringList
+
   myStringList:=TStringList.Create;              //StringListを作る
   myStringList.Add('This is the first line.');    //add a line
+
   myStringList.Add('This is the first line.');    //1行加える
 
   myStringList.Add('This is the second line.');
 
   myStringList.Add('This is the second line.');
 
   myStringList.Add('This is the third line.');
 
   myStringList.Add('This is the third line.');
 
   myStringList.Add('etc.');
 
   myStringList.Add('etc.');
   Memo1.Lines.Assign(myStringList);              //assign text content
+
   Memo1.Lines.Assign(myStringList);              //テキスト内容を割り当てる
   myStringList.Free;                              //free my StringList
+
   myStringList.Free;                              //StringListを解放
 
end;
 
end;
 
</syntaxhighlight>
 
</syntaxhighlight>
  
===Insert lines directly===
+
===直接行を挿入する===
You can add directly the contents of the memo for example:
+
この例ようにメモの内容を直接加えることもできる:
  
 
<syntaxhighlight lang=pascal>
 
<syntaxhighlight lang=pascal>
 
procedure TForm1.Button1Click(Sender: TObject);
 
procedure TForm1.Button1Click(Sender: TObject);
 
begin
 
begin
   Memo1.Lines.Clear;                              //delete all lines of Memo1
+
   Memo1.Lines.Clear;                              //Memo1のすべての行を削除
   Memo1.Lines.Add('This is the first line.');    //add a line
+
   Memo1.Lines.Add('This is the first line.');    //1行加える。
 
   Memo1.Lines.Add('This is the second line.');
 
   Memo1.Lines.Add('This is the second line.');
 
   Memo1.Lines.Add('This is the third line.');
 
   Memo1.Lines.Add('This is the third line.');
Line 47: Line 46:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
===Read a line===
+
===行を読む===
If you want to know what is in a particular line, you can check it directly with '''<code>myString:=Memo1.Lines[Index];</code>'''. Note, the index of ''TMemo.Lines'' is zero based, i.e. the first line would be: '''<code>myString:=Memo1.Lines[0];</code>'''
+
特定の行に何が入っているがを知りたい場合には、直接'''<code>myString:=Memo1.Lines[Index];</code>'''で調べることができる。注意、''TMemo.Lines''はゼロから始まっている。即ち、最初の行は: '''<code>myString:=Memo1.Lines[0];</code>'''となる。
  
The preceding example add yet a TButton ''Button2'', you can display the third line as follows:
+
続く例はさらにTButton ''Button2''を加えて、以下のように3つ目の行を表示している:
  
 
<syntaxhighlight lang=pascal>
 
<syntaxhighlight lang=pascal>
Line 59: Line 58:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
===Selected text===
+
===テキストを選択する===
You can mark text parts at run time by holding the left mouse button or press and hold the [Shift] key and select the text with the mouse or keyboard. This text ([[String]]) you can display like this:
+
テキスト部分をマウスの左ボタンを押し続けるか、[Shift]キーを押すことで、マウスやキーボードでテキストを選択することができる。このテキスト[[String]]をこのように表示することができる:
  
 
<syntaxhighlight lang=pascal>
 
<syntaxhighlight lang=pascal>
Line 69: Line 68:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
===Search text===
+
===テキストを検索する===
  
Contrary to the previous example, you can also looking for a text ([[String]]) in a TMemo and return the place where it is: '''<code>Position:=Memo1.SelStart;</code>'''
+
以上の例とは対照的に、TMemoにある([[String]])を探し、その場所を返すこともできる: '''<code>Position:=Memo1.SelStart;</code>'''
  
The following example shows how you can search and search further for a text in a memo:
+
以下の例ではmemoのなかにあるテキストを探し、さらに探している:
* Create a new application with a [[TEdit]] ''Edit1'', a TMemo ''Memo1'' and two [[TButton]] ''Button1'' and ''Button2''.
+
* [[TEdit]] ''Edit1''、TMemo ''Memo1''[[TButton/ja|TButton]] ''Button1'' ''Button2''を持つ新しいアプリケーションを作る。
* Complete the uses clause to '''LCLProc''' and '''strutils'''.
+
* Uses節に '''LCLProc''' '''strutils''' を加える。
* In the event handler ''OnClick'' of ''Button1'' fill the memo with any text, as in the example [[TMemo#Insert lines directly|Insert lines directly]].
+
* [[TMemo#Insert lines directly|Insert lines directly]]例のように、''Button1''の''OnClick''イベントを何らかのテキストで埋める
* In the source text editor add following function (based on the [http://www.lazarusforum.de/viewtopic.php?p=39260#p39260 example] from the German Lazarusforum):
+
* ソーステキストエディタで以下の関数を(ドイツのLazarusフォーラム [http://www.lazarusforum.de/viewtopic.php?p=39260#p39260]に基づく)入力する:
  
 
<syntaxhighlight lang=pascal>
 
<syntaxhighlight lang=pascal>
// FindInMemo: Returns the position where the string to search was found
+
// FindInMemo: 探す文字列が見つかった場所を返す
 
function FindInMemo(AMemo: TMemo; AString: String; StartPos: Integer): Integer;
 
function FindInMemo(AMemo: TMemo; AString: String; StartPos: Integer): Integer;
 
begin
 
begin
Line 93: Line 92:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
* Now, add following code in the event handler ''OnClick'' from ''Button2'':
+
* ここで、''Button2''のイベントハンドラで''OnClick''に以下のコードを加える:
  
 
<syntaxhighlight lang=pascal>
 
<syntaxhighlight lang=pascal>
 
procedure TForm1.Button2Click(Sender: TObject);
 
procedure TForm1.Button2Click(Sender: TObject);
 
const
 
const
   SearchStr: String = '';                    // The string to search for
+
   SearchStr: String = '';                    // 探す文字列
   SearchStart: Integer = 0;                  // Last position of the string to search for
+
   SearchStart: Integer = 0;                  // 探す文字列の最後の場所
 
begin
 
begin
 
   if SearchStr <> Edit1.Text then begin      // Falls sich der zu suchende String geändert hat
 
   if SearchStr <> Edit1.Text then begin      // Falls sich der zu suchende String geändert hat
Line 113: Line 112:
 
end;
 
end;
 
</syntaxhighlight>
 
</syntaxhighlight>
* Now at run time, you can fill the memo with a text with ''Button1'', paste the text to be searched in ''Edit1'' and looking or keep looking for these in memo with ''Button2''.
+
* 実行時に''Button1''でmemoを埋め、''Edit1''に探されるべきテキストを入れ、''Button2''でそれらを探す、探し続けることができる。
  
 
==== EM_SCROLLCARET ====
 
==== EM_SCROLLCARET ====
Messages like EM_SCROLLCARET as used in windows are not available in Lazarus and thus need a workaround...
+
Windowsで用いられているように EM_SCROLLCARET のようなメッセージはLazarusでは使えないので、別法が必要である...
  
===Save and load===
+
===保存と読み込み===
You can quite easily save and load the contents of a memo by using the methods ''SaveToFile'' and ''LoadFromFile'' of the class [[TStringList-TStrings Tutorial|TStrings]].
+
全く簡単に、[[TStringList-TStrings Tutorial|TStrings]]クラスのメソッド、''SaveToFile''''LoadFromFile''を用いて、memoの内容を保存、読み込みできる。
  
The following example shows you how:
+
以下の例でどのようにするかを示す:
  
* Create a new application with a TMemo ''Memo1'' and three [[TButton]] ''Button1'', ''Button2'' and ''Button3''.
+
* TMemo ''Memo1''と3つのボタン、[[TButton/ja|TButton]] ''Button1''''Button2''''Button3''を持つ新しいアプリケーションを作る。
* Additionally put a [[TSaveDialog]] and a [[TOpenDialog]] from the component palette ''Dialogs'' on the form.
+
* さらに、コンポーネントパレット''Dialogs''から[[TSaveDialog]][[TOpenDialog]]をとり、フォームに置く。
* Change Caption of ''Button1'' to "Fill memo".
+
* ''Button1''のキャプション「メモを記入」へ変える。
* In the event handler ''OnClick'' of ''Button1'' fill the memo with any text, as in the example [[TMemo#Insert lines directly|Insert lines directly]].
+
* ''Button1''''OnClick''イベントハンドラで、[[TMemo#Insert lines directly|Insert lines directly]]の例にあるように、何かのテキストで、memoを埋める。
* Change Caption of ''Button2'' to "Save memo".
+
* ''Button2''のキャプションを「メモを保存」と変える。
* Change Caption of ''Button3'' to "Load memo".
+
* ''Button3''のキャプションを「メモを開く」と変える。
* now modify the event handler ''OnClick'' of the buttons:
+
* これで、ボタンの''OnClick''イベントハンドラを変更できる。
  
 
<syntaxhighlight lang=pascal>
 
<syntaxhighlight lang=pascal>
Line 145: Line 144:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==See also==
+
==以下も参照のこと==
 
* [[doc:lcl/stdctrls/tmemo.html|TMemo doc]]
 
* [[doc:lcl/stdctrls/tmemo.html|TMemo doc]]
 
* [[RichMemo|TRichMemo]] - Like Delphi TRichEdit component: formatted text (color, size, etc.)
 
* [[RichMemo|TRichMemo]] - Like Delphi TRichEdit component: formatted text (color, size, etc.)
 
* [[TListBox]] - A scrollable list of strings
 
* [[TListBox]] - A scrollable list of strings
  
{{LCL Components}}
+
{{LCL Components/ja}}

Latest revision as of 06:49, 20 March 2024

Deutsch (de) English (en) suomi (fi) français (fr) 日本語 (ja) русский (ru)

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

TMemo tmemo.pngは複数行を編集できるコントロールである。コンポーネントパレットタブのStandardタブから利用できる。

使い方

TMemoを用いるにはformStandardコンポーネントパレットで選択しフォーム上でクリックすればよい。このテキストボックスで実行時に複数行のテキストを編集できる。

例えば、フォーム、Form1へTMemo Memo1を加えるとStringMemo1.Text:='これは1行のテキストです';と割り当てることができる。

また、myString:=Memo1.Text;として、保存されたテキストMemo1をソースの中のどこでも使うことができる。

複数行のテキスト、Memo1.Text:=' これは '+LineEnding+' 複数行の '+LineEnding+' テキスト '+LineEnding+' です ';を割り当てることも可能である。

TStringsもしくはTStringListを割り当てる

通常、TMemoにテキストを割り当てるには、TStringList、もしくはその親のTStringsを利用する。以下の例(form Form1とTMemo Memo1を用いて挿入されたTButton Button1イベントハンドラで)はこれを示している:

procedure TForm1.Button1Click(Sender: TObject);
var
  myStringList: TStringList;
begin
  myStringList:=TStringList.Create;               //StringListを作る
  myStringList.Add('This is the first line.');    //1行加える
  myStringList.Add('This is the second line.');
  myStringList.Add('This is the third line.');
  myStringList.Add('etc.');
  Memo1.Lines.Assign(myStringList);               //テキスト内容を割り当てる
  myStringList.Free;                              //StringListを解放
end;

直接行を挿入する

この例ようにメモの内容を直接加えることもできる:

procedure TForm1.Button1Click(Sender: TObject);
begin
  Memo1.Lines.Clear;                              //Memo1のすべての行を削除
  Memo1.Lines.Add('This is the first line.');     //1行加える。
  Memo1.Lines.Add('This is the second line.');
  Memo1.Lines.Add('This is the third line.');
  Memo1.Lines.Add('etc.');
end;

行を読む

特定の行に何が入っているがを知りたい場合には、直接myString:=Memo1.Lines[Index];で調べることができる。注意、TMemo.Linesはゼロから始まっている。即ち、最初の行は: myString:=Memo1.Lines[0];となる。

続く例はさらにTButton Button2を加えて、以下のように3つ目の行を表示している:

procedure TForm1.Button2Click(Sender: TObject);
begin
  ShowMessage(Memo1.Lines[2]);
end;

テキストを選択する

テキスト部分をマウスの左ボタンを押し続けるか、[Shift]キーを押すことで、マウスやキーボードでテキストを選択することができる。このテキストStringをこのように表示することができる:

procedure TForm1.Button2Click(Sender: TObject);
begin
  ShowMessage(Memo1.SelText); 
end;

テキストを検索する

以上の例とは対照的に、TMemoにある(String)を探し、その場所を返すこともできる: Position:=Memo1.SelStart;

以下の例ではmemoのなかにあるテキストを探し、さらに探している:

  • TEdit Edit1、TMemo Memo1TButton Button1Button2を持つ新しいアプリケーションを作る。
  • Uses節に LCLProcstrutils を加える。
  • Insert lines directly例のように、Button1OnClickイベントを何らかのテキストで埋める
  • ソーステキストエディタで以下の関数を(ドイツのLazarusフォーラム [1]に基づく)入力する:
// FindInMemo: 探す文字列が見つかった場所を返す
function FindInMemo(AMemo: TMemo; AString: String; StartPos: Integer): Integer;
begin
  Result := PosEx(AString, AMemo.Text, StartPos);
  if Result > 0 then
  begin
    AMemo.SelStart := UTF8Length(PChar(AMemo.Text), Result - 1);
    AMemo.SelLength := Length(AString);
    AMemo.SetFocus;
  end;
end;
  • ここで、Button2のイベントハンドラでOnClickに以下のコードを加える:
procedure TForm1.Button2Click(Sender: TObject);
const
  SearchStr: String = '';                     // 探す文字列
  SearchStart: Integer = 0;                   // 探す文字列の最後の場所
begin
  if SearchStr <> Edit1.Text then begin       // Falls sich der zu suchende String geändert hat
    SearchStart := 0;
    SearchStr := Edit1.Text;
  end;
  SearchStart := FindInMemo(Memo1, SearchStr, SearchStart + 1);

  if SearchStart > 0 then
    Caption := 'Found at position['+IntToStr(SearchStart)+']!'
  else
    Caption := 'No further finds!';
end;
  • 実行時にButton1でmemoを埋め、Edit1に探されるべきテキストを入れ、Button2でそれらを探す、探し続けることができる。

EM_SCROLLCARET

Windowsで用いられているように EM_SCROLLCARET のようなメッセージはLazarusでは使えないので、別法が必要である...

保存と読み込み

全く簡単に、TStringsクラスのメソッド、SaveToFileLoadFromFileを用いて、memoの内容を保存、読み込みできる。

以下の例でどのようにするかを示す:

  • TMemo Memo1と3つのボタン、TButton Button1Button2Button3を持つ新しいアプリケーションを作る。
  • さらに、コンポーネントパレットDialogsからTSaveDialogTOpenDialogをとり、フォームに置く。
  • Button1のキャプション「メモを記入」へ変える。
  • Button1OnClickイベントハンドラで、Insert lines directlyの例にあるように、何かのテキストで、memoを埋める。
  • Button2のキャプションを「メモを保存」と変える。
  • Button3のキャプションを「メモを開く」と変える。
  • これで、ボタンのOnClickイベントハンドラを変更できる。
procedure TForm1.Button2Click(Sender: TObject);
begin
  if SaveDialog1.Execute then
    Memo1.Lines.SaveToFile(SaveDialog1.FileName);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  if OpenDialog1.Execute then
    Memo1.Lines.LoadFromFile(OpenDialog1.FileName);
end;

以下も参照のこと


LCL Components
Component Tab Components
Standard TMainMenu • TPopupMenu • TButton • TLabel • TEdit • TMemo • TToggleBox • TCheckBox • TRadioButton • TListBox • TComboBox • TScrollBar • TGroupBox • TRadioGroup • TCheckGroup • TPanel • TFrame • TActionList
Additional TBitBtn/ja • TSpeedButton/ja • TStaticText/ja • TImage/ja • TShape/ja • TBevel/ja • TPaintBox/ja • TNotebook/ja • TLabeledEdit/ja • TSplitter/ja • TTrayIcon/ja • TControlBar/ja • TFlowPanel/ja • TMaskEdit/ja • TCheckListBox/ja • TScrollBox/ja • TApplicationProperties/ja • TStringGrid/ja • TDrawGrid/ja • TPairSplitter/ja • TColorBox/ja • TColorListBox/ja • TValueListEditor/ja
Common Controls TTrackBar • TProgressBar • TTreeView • TListView • TStatusBar • TToolBar • TCoolBar • TUpDown • TPageControl • TTabControl • THeaderControl • TImageList • TPopupNotifier • TDateTimePicker
Dialogs TOpenDialog • TSaveDialog • TSelectDirectoryDialog • TColorDialog • TFontDialog • TFindDialog • TReplaceDialog • TTaskDialog • TOpenPictureDialog • TSavePictureDialog • TCalendarDialog • TCalculatorDialog • TPrinterSetupDialog • TPrintDialog • TPageSetupDialog
Data Controls TDBNavigator/ja • TDBText/ja • TDBEdit/ja • TDBMemo/ja • TDBImage/ja • TDBListBox/ja • TDBLookupListBox/ja • TDBComboBox/ja • TDBLookupComboBox/ja • TDBCheckBox/ja • TDBRadioGroup/ja • TDBCalendar/ja • TDBGroupBox/ja • TDBGrid/ja • TDBDateTimePicker/ja
Data Access TDataSource/ja • TCSVDataSet/ja • TSdfDataSet/ja • TBufDataset/ja • TFixedFormatDataSet/ja • TDbf/ja • TMemDataset/ja
System TTimer • TIdleTimer • TLazComponentQueue • THTMLHelpDatabase • THTMLBrowserHelpViewer • TAsyncProcess • TProcessUTF8 • TProcess • TSimpleIPCClient • TSimpleIPCServer • TXMLConfig • TEventLog • TServiceManager • TCHMHelpDatabase • TLHelpConnector
Misc TColorButton • TSpinEdit • TFloatSpinEdit • TArrow • TCalendar • TEditButton • TFileNameEdit • TDirectoryEdit • TDateEdit • TTimeEdit • TCalcEdit • TFileListBox • TFilterComboBox • TComboBoxEx • TCheckComboBox • TButtonPanel • TShellTreeView • TShellListView • TXMLPropStorage • TINIPropStorage • TJSONPropStorage • TIDEDialogLayoutStorage • TMRUManager • TStrHolder
LazControls TCheckBoxThemed • TDividerBevel • TExtendedNotebook • TListFilterEdit • TListViewFilterEdit • TLvlGraphControl • TShortPathEdit • TSpinEditEx • TFloatSpinEditEx • TTreeFilterEdit • TExtendedTabControl •
RTTI TTIEdit • TTIComboBox • TTIButton • TTICheckBox • TTILabel • TTIGroupBox • TTIRadioGroup • TTICheckGroup • TTICheckListBox • TTIListBox • TTIMemo • TTICalendar • TTIImage • TTIFloatSpinEdit • TTISpinEdit • TTITrackBar • TTIProgressBar • TTIMaskEdit • TTIColorButton • TMultiPropertyLink • TTIPropertyGrid • TTIGrid
SQLdb TSQLQuery/ja • TSQLTransaction/ja • TSQLScript • TSQLConnector • TMSSQLConnection • TSybaseConnection • TPQConnection • TPQTEventMonitor • TOracleConnection • TODBCConnection • TMySQL40Connection • TMySQL41Connection • TMySQL50Connection • TMySQL51Connection • TMySQL55Connection • TMySQL56Connection • TMySQL57Connection • TSQLite3Connection/ja • TIBConnection • TFBAdmin • TFBEventMonitor • TSQLDBLibraryLoader
Pascal Script TPSScript • TPSScriptDebugger • TPSDllPlugin • TPSImport_Classes • TPSImport_DateUtils • TPSImport_ComObj • TPSImport_DB • TPSImport_Forms • TPSImport_Controls • TPSImport_StdCtrls • TPSCustomPlugin
SynEdit TSynEdit • TSynCompletion • TSynAutoComplete • TSynMacroRecorder • TSynExporterHTML • TSynPluginSyncroEdit • TSynPasSyn • TSynFreePascalSyn • TSynCppSyn • TSynJavaSyn • TSynPerlSyn • TSynHTMLSyn • TSynXMLSyn • TSynLFMSyn • TSynDiffSyn • TSynUNIXShellScriptSyn • TSynCssSyn • TSynPHPSyn • TSynTeXSyn • TSynSQLSyn • TSynPythonSyn • TSynVBSyn • TSynAnySyn • TSynMultiSyn • TSynBatSyn • TSynIniSyn • TSynPoSyn
Chart TChart • TListChartSource • TRandomChartSource • TUserDefinedChartSource • TCalculatedChartSource • TDbChartSource • TChartToolset • TChartAxisTransformations • TChartStyles • TChartLegendPanel • TChartNavScrollBar • TChartNavPanel • TIntervalChartSource • TDateTimeIntervalChartSource • TChartListBox • TChartExtentLink • TChartImageList
IPro TIpFileDataProvider • TIpHtmlDataProvider • TIpHttpDataProvider • TIpHtmlPanel
Virtual Controls TVirtualDrawTree • TVirtualStringTree • TVTHeaderPopupMenu