Sign in Join
Wiki copytemporary

Asynchronous Calls/ja: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
1+**日本語版メニュー**
2+---
3+[[Main Page/ja|メインページ]] \- [[Lazarus Documentation/ja|Lazarus Documentation日本語版]] \- [[Japanese Localization Notes|翻訳ノート]] \- [[Bug Tracking/ja|日本語障害情報]]
4+
5+## Contents
6+
7+ * 1 問題について
8+ * 2 解決方法
9+ * 3 例
10+ * 4 関連項目
11+
112## 問題について
213
3-あるイベントを処理する必要があっても、その場ですぐには処理を実行できない場合があります。例えば、オブジェクトを free しなければいけないのに、後ほど親オブジェクトなどからそのオブジェクトを参照される可能性がある場合です。
14+あるイベントを処理する必要があっても、その場ですぐには処理を実行できない場合があります。例えば、オブジェクトを free しなければいけないのに、後ほど親オブジェクトなどからそのオブジェクトを参照される可能性がある場合です。
415
516## 解決方法
617
7-Application.[[doc:lcl/forms/tapplication.queueasynccall.html|QueueAsyncCall]] メソッドを使用してください。
8-
9-[[doc:lcl/forms/tdataevent.html|TDataEvent]]` = procedure (Data: PtrInt) of object;`\
10-\
11-`procedure `[[doc:lcl/forms/tapplication.queueasynccall.html|QueueAsyncCall]]`(AMethod: TDataEvent; Data: PtrInt);`\
18+Application.[QueueAsyncCall](<http://lazarus-ccr.sourceforge.net/docs/lcl/forms/tapplication.queueasynccall.html> "doc:lcl/forms/tapplication.queueasynccall.html") メソッドを使用してください。
19+```
20+[TDataEvent](<http://lazarus-ccr.sourceforge.net/docs/lcl/forms/tdataevent.html> "doc:lcl/forms/tdataevent.html") = procedure (Data: PtrInt) of object;
21+
22+ procedure [QueueAsyncCall](<http://lazarus-ccr.sourceforge.net/docs/lcl/forms/tapplication.queueasynccall.html> "doc:lcl/forms/tapplication.queueasynccall.html")(AMethod: TDataEvent; Data: PtrInt);
23+```
1224
13-これは、任意のメソッドを「キュー」(待ち行列)に入れ、主イベントループ(訳注 : ユーザプログラムの中にあって、ウィンドウシステムから送られてくるイベントを処理するループ。Lazarus等 では隠蔽されている)の中で、他のイベントの処理が全て終わった後で実行するようにします。その際、メソッドに任意のパラメタを渡すことができます。上の例では、free する時点では親の実行が終了していますから、free しようとしているオブジェクトへの参照は消滅しており、安全に free することができるわけです。
25+これは、任意のメソッドを「キュー」(待ち行列)に入れ、主イベントループ(訳注 : ユーザプログラムの中にあって、ウィンドウシステムから送られてくるイベントを処理するループ。Lazarus等 では隠蔽されている)の中で、他のイベントの処理が全て終わった後で実行するようにします。その際、メソッドに任意のパラメタを渡すことができます。上の例では、free する時点では親の実行が終了していますから、free しようとしているオブジェクトへの参照は消滅しており、安全に free することができるわけです。
1426
15-これは [[doc:lcl/forms/tapplication.releasecomponent.html|ReleaseComponent]] の、よりジェネリックなヴァージョンであり、ReleaseComponent もこのメソッドを呼んでいることにご注意ください。
27+これは [ReleaseComponent](<http://lazarus-ccr.sourceforge.net/docs/lcl/forms/tapplication.releasecomponent.html> "doc:lcl/forms/tapplication.releasecomponent.html") の、よりジェネリックなヴァージョンであり、ReleaseComponent もこのメソッドを呼んでいることにご注意ください。
1628
1729## 例
1830
19-次のプログラムは [[doc:lcl/forms/tapplication.queueasynccall.html|QueueAsyncCall]] の使い方を示しています。 CallButton を押すと、'Click 1', 'Click 2' そして 'Async 1' が LogListBox に追加されます。注目すべきところは、Async メソッドは、CallButtonClick イベントが終了した後に実行される、という点です。
20-
21-``` pascal
31+次のプログラムは [QueueAsyncCall](<http://lazarus-ccr.sourceforge.net/docs/lcl/forms/tapplication.queueasynccall.html> "doc:lcl/forms/tapplication.queueasynccall.html") の使い方を示しています。 CallButton を押すと、'Click 1', 'Click 2' そして 'Async 1' が LogListBox に追加されます。注目すべきところは、Async メソッドは、CallButtonClick イベントが終了した後に実行される、という点です。
32+```
2233unit TestQueueAsyncCall;
23-
24-{$mode objfpc}{$H+}
25-
26-interface
27-
28-uses
29- Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, Buttons,
30- StdCtrls;
31-
32-type
33-
34- { TQueueAsyncCallForm }
35-
36- TQueueAsyncCallForm = class(TForm)
37- CallButton: TButton;
38- LogListBox: TListBox;
39- procedure CallButtonClick(Sender: TObject);
40- private
41- { private declarations }
42- FCounter: PtrInt;
43- procedure Async(Data: PtrInt);
44- public
45- { public declarations }
46- end;
47-
48-var
49- QueueAsyncCallForm: TQueueAsyncCallForm;
50-
51-implementation
52-
53-{$R *.lfm}
54-
55-{ TQueueAsyncCallForm }
56-
57-procedure TQueueAsyncCallForm.CallButtonClick(Sender: TObject);
58-begin
59- LogListBox.Items.Add('Click 1');
60- FCounter := FCounter+1;
61- Application.QueueAsyncCall(@Async,FCounter);
62- LogListBox.Items.Add('Click 2');
63-end;
64-
65-procedure TQueueAsyncCallForm.Async(Data: PtrInt);
66-begin
67- LogListBox.Items.Add('Async '+ IntToStr(Data));
68-end;
69-
70-end.
71-
34+
35+ {$mode objfpc}{$H+}
36+
37+ interface
38+
39+ uses
40+ Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, Buttons,
41+ StdCtrls;
42+
43+ type
44+
45+ { TQueueAsyncCallForm }
46+
47+ TQueueAsyncCallForm = class(TForm)
48+ CallButton: TButton;
49+ LogListBox: TListBox;
50+ procedure CallButtonClick(Sender: TObject);
51+ private
52+ { private declarations }
53+ FCounter: PtrInt;
54+ procedure Async(Data: PtrInt);
55+ public
56+ { public declarations }
57+ end;
58+
59+ var
60+ QueueAsyncCallForm: TQueueAsyncCallForm;
61+
62+ implementation
63+
64+ {$R *.lfm}
65+
66+ { TQueueAsyncCallForm }
67+
68+ procedure TQueueAsyncCallForm.CallButtonClick(Sender: TObject);
69+ begin
70+ LogListBox.Items.Add('Click 1');
71+ FCounter := FCounter+1;
72+ Application.QueueAsyncCall(@Async,FCounter);
73+ LogListBox.Items.Add('Click 2');
74+ end;
75+
76+ procedure TQueueAsyncCallForm.Async(Data: PtrInt);
77+ begin
78+ LogListBox.Items.Add('Async '+ IntToStr(Data));
79+ end;
80+
81+ end.
7282```
7383
7484## 関連項目
7585
76-- [New 0.9.26 features. Part 1. SendMessage and PostMessage](http://lazarus-dev.blogspot.com/2008/01/new-0926-features-part-1-sendmessage.html)
77-- [[Main Loop Hooks]]
78-- [[Multithreaded Application Tutorial/ja|マルチスレッドアプリケーションチュートリアル]]
86+ * [New 0.9.26 features. Part 1. SendMessage and PostMessage](<http://lazarus-dev.blogspot.com/2008/01/new-0926-features-part-1-sendmessage.html>)
87+ * [[Main Loop Hooks]]
88+ * [[Multithreaded Application Tutorial/ja|マルチスレッドアプリケーションチュートリアル]]
7989
8090---
81-*From the Free Pascal wiki, page "Asynchronous Calls/ja", as it stood on 2020-02-09 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
91+*From the Free Pascal wiki, page "Asynchronous Calls/ja", as the Internet Archive kept it on 2023-03-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history