Boujour,
J'ai un petit problème de contrôle d'un thread
Le but du thread est de faire une petite attente de 2 secondes entre chaque envoie de message
Si le thread est en cours on envoie un message : "!!! Flooding !!!"
Thread:
Form :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 unit AntiFlood; interface uses SysUtils, Windows, Classes; type TFlood = class(TThread) protected procedure Execute; override; end; implementation procedure TFlood.Execute; begin while not Terminated do begin Sleep(2000); Terminate; FreeOnTerminate := False; end; end; end.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 procedure TForm1.Edit1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); begin if (Flood <> nil) and (not Flood.CheckTerminated) and (Key = Vk_Return) then begin Listbox1.Items.BeginUpdate; Listbox1.Items.Add('!!! Flooding !!!'); Listbox1.Items.EndUpdate; Exit; end; if (Key = Vk_Return) then begin Flood := TFlood.Create(True); Flood.FreeOnTerminate := True; Flood.Resume; Listbox1.Items.BeginUpdate; Listbox1.Items.Add(Edit1.Text); Listbox1.Items.EndUpdate; end end;
Merci pour aide
Partager