Sign in Join
Wiki copytemporary

Asynchronous Calls/fr: what changed

Revision 3 to 4. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
1-## Contents
2-
3- * 1 Position du problème
4- * 2 Solution
5- * 3 Exemple
6- * 4 Voir aussi
7-
81# Position du problème
92
10-Quand vous manipulez certains événements, vous avez besoin de faire quelque chose, mais vous ne pouvez le faire correctement. Exemple : vous devez libérer un objet, mais il est ou sera référencé quelque part dans le parent (ou son parent etc.) plus tard.
3+Quand vous manipulez certains événements, vous avez besoin de faire quelque chose, mais vous ne pouvez le faire correctement. Exemple : vous devez libérer un objet, mais il est ou sera référencé quelque part dans le parent (ou son parent etc.) plus tard.
114
125# Solution
136
14-Appeler Application.[QueueAsyncCall](<http://lazarus-ccr.sourceforge.net/docs/lcl/forms/tapplication.queueasynccall.html> "doc:lcl/forms/tapplication.queueasynccall.html"):
15-```
16-[TDataEvent](<http://lazarus-ccr.sourceforge.net/docs/lcl/forms/tdataevent.html> "doc:lcl/forms/tdataevent.html") = procedure (Data: PtrInt) of object;
17-
18- procedure [QueueAsyncCall](<http://lazarus-ccr.sourceforge.net/docs/lcl/forms/tapplication.queueasynccall.html> "doc:lcl/forms/tapplication.queueasynccall.html")(AMethod: TDataEvent; Data: PtrInt);
19-```
7+Appeler Application.[[doc:lcl/forms/tapplication.queueasynccall.html|QueueAsyncCall]]:
208
21-Cela placera en file d'attente la méthode donnée avec le paramètre donné pour execution dans la boucle principale des événements, quand tous les autres événements auront été traités. Dans l'exemple du dessus, la référence à l'objet que vous vouliez libérer est partie, depuis le parent d'alors a fini son exécution et l'objet que vous vouliez libérer peut l'être de manière sûre.
9+[[doc:lcl/forms/tdataevent.html|TDataEvent]]` = procedure (Data: PtrInt) of object;`\
2210
23-Remarquez qu'il y a une version plus générique de [ReleaseComponent](<http://lazarus-ccr.sourceforge.net/docs/lcl/forms/tapplication.releasecomponent.html> "doc:lcl/forms/tapplication.releasecomponent.html"), et ReleaseComponent appele cette méthode.
11+`procedure `[[doc:lcl/forms/tapplication.queueasynccall.html|QueueAsyncCall]]`(AMethod: TDataEvent; Data: PtrInt);`\
2412
13+Cela placera en file d'attente la méthode donnée avec le paramètre donné pour execution dans la boucle principale des événements, quand tous les autres événements auront été traités. Dans l'exemple du dessus, la référence à l'objet que vous vouliez libérer est partie, depuis le parent d'alors a fini son exécution et l'objet que vous vouliez libérer peut l'être de manière sûre.
14+
15+Remarquez qu'il y a une version plus générique de [[doc:lcl/forms/tapplication.releasecomponent.html|ReleaseComponent]], et ReleaseComponent appele cette méthode.
16+
2517# Exemple
2618
27-Le programme suivant montre l'utilisation de [QueueAsyncCall](<http://lazarus-ccr.sourceforge.net/docs/lcl/forms/tapplication.queueasynccall.html> "doc:lcl/forms/tapplication.queueasynccall.html"). Si vous pressez sur le CallButton, 'Click 1', 'Click 2' et 'Async 1' sont ajoutés dans le LogListBox. Remarquez que l'appel Async est seulement exécuté après que l'événement CallButtonClick s'est terminé.
28-```
19+Le programme suivant montre l'utilisation de [[doc:lcl/forms/tapplication.queueasynccall.html|QueueAsyncCall]]. Si vous pressez sur le CallButton, 'Click 1', 'Click 2' et 'Async 1' sont ajoutés dans le LogListBox. Remarquez que l'appel Async est seulement exécuté après que l'événement CallButtonClick s'est terminé.
20+
21+``` pascal
2922unit TestQueueAsyncCall;
30-
31- {$mode objfpc}{$H+}
32-
33- interface
34-
35- uses
36- Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, Buttons,
37- StdCtrls;
38-
39- type
40-
41- { TQueueAsyncCallForm }
42-
43- TQueueAsyncCallForm = class(TForm)
44- CallButton: TButton;
45- LogListBox: TListBox;
46- procedure CallButtonClick(Sender: TObject);
47- private
48- { private declarations }
49- FCounter: PtrInt;
50- procedure Async(Data: PtrInt);
51- public
52- { public declarations }
53- end;
54-
55- var
56- QueueAsyncCallForm: TQueueAsyncCallForm;
57-
58- implementation
59-
60- {$R *.lfm}
61-
62- { TQueueAsyncCallForm }
63-
64- procedure TQueueAsyncCallForm.CallButtonClick(Sender: TObject);
65- begin
66- LogListBox.Items.Add('Click 1');
67- FCounter := FCounter+1;
68- Application.QueueAsyncCall(@Async,FCounter);
69- LogListBox.Items.Add('Click 2');
70- end;
71-
72- procedure TQueueAsyncCallForm.Async(Data: PtrInt);
73- begin
74- LogListBox.Items.Add('Async '+ IntToStr(Data));
75- end;
76-
77- end.
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.
7871```
7972
8073# Voir aussi
8174
82- * [Fonctionnalité ajoutée dans la 0.9.26. Partie 1. SendMessage et PostMessage](<http://lazarus-dev.blogspot.com/2008/01/new-0926-features-part-1-sendmessage.html>)
83- * [[Main Loop Hooks/fr|Crochet (_hooks_) dans la boucle principale]]
84- * [[Multithreaded Application Tutorial/fr|Tutoriel sur les application Multithreadées]]
75+- [Fonctionnalité ajoutée dans la 0.9.26. Partie 1. SendMessage et PostMessage](http://lazarus-dev.blogspot.com/2008/01/new-0926-features-part-1-sendmessage.html)
76+- [[Main Loop Hooks/fr|Crochet (hooks) dans la boucle principale]]
77+- [[Multithreaded Application Tutorial/fr|Tutoriel sur les application Multithreadées]]
8578
8679---
87-*From the Free Pascal wiki, page "Asynchronous Calls/fr", as the Internet Archive kept it on 2022-11-29. 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).*
80+*From the Free Pascal wiki, page "Asynchronous Calls/fr", 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).*

Back to history