Autor Beitrag
Adrian
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 314



BeitragVerfasst: So 23.03.03 23:06 
Hallo,

meine Frage ist zwar schon ein paarmal in ähnlicher Form im Forum aufgetaucht, aber bislang haben meine Versuche dazu noch keinen Erfolg gezeitigt. Den folgenden Code-Auszug benutze ich im Beispiel:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
procedure TForm1.Button1Click(Sender: TObject);
begin
  n:=0;
  repeat
    Application.ProcessMessages;
    inc(n,1);
    Edit1.Text:=IntToStr(n);
  until n>=500000;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Edit1.Text:='Angehalten bei '+IntToStr(n);
end;

Eigentlich sollte ich mit Button2 die Zählschleife von Button1 abbrechen können, aber leider wird Button2Click erst ausgeführt, wenn der Zählerstand von 50000 erreicht ist. Wenn das mit Applicati-on.ProcessMessages erreichbar ist, wie? Wenn nicht, was muß ich statt dessen benutzen?

Gruß,

Adrian
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: So 23.03.03 23:13 
Versuch es mal so:
ausblenden Quelltext
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:
var
  Form1: TForm1;
  n : Integer;
  bCounting : Boolean = TRUE;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  n:=0;
  repeat
    if bCounting = False then break;
    Application.ProcessMessages;
    inc(n);
    Edit1.Text:=IntToStr(n);
  until n>=500000;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  bCounting := FALSE;
  Caption:='Angehalten bei '+IntToStr(n);
end;
hitstec
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 295



BeitragVerfasst: So 23.03.03 23:13 
Also du willst die Repeat-Schleife beenden?
Dann deklariere einen globalen Boolean-Wert, etwa bStop;

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
var bStop: Boolean;

procedure TForm1.Button1Click(Sender: TObject); 
begin 
  n:=0; 
  bStop:=false;
  repeat 
    Application.ProcessMessages; 
    inc(n,1); 
    Edit1.Text:=IntToStr(n); 
  until (n>=500000) or (bStop); 
end; 

procedure TForm1.Button2Click(Sender: TObject); 
begin 
  Edit1.Text:='Angehalten bei '+IntToStr(n); 
  bStop:=true;
end;
MSCH
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1448
Erhaltene Danke: 3

W7 64
XE2, SQL, DevExpress, DevArt, Oracle, SQLServer
BeitragVerfasst: Sa 29.03.03 23:06 
Hmm, merkwürdige Konstruktionen. Ich würd einfach einen Thread schreiben, der einen Wert hochzählt und bei X beendet wird.
Im Ersten Fall (Button Start) Thread losjagen.... im Zweiten Fall (Button Stop) Thread terminieren.
Den Wert des Threads (dessen Zähler) wid dann über eine variable ausgewertet.
grez
MSch