Autor Beitrag
CABALxx
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 174


D7 Ent
BeitragVerfasst: Mi 03.03.04 18:57 
Hallo
ich habe ein Programm mit einer repeat anweisung darin geschrieben, und es lässt sich auch einwandtfrei compilieren nur wenn ich dann den Button klicke ( in dessen Procedure die repeat anweisung steht ) dann hängt sich das Programm auf:



ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure TForm1.Button1Click(Sender: TObject);
var a , b: integer ;
begin

repeat
begin
a := pos('Mithrandir', Memo1.Text );
Label2.Caption := IntToStr(a);
b := StrToInt(Label1.Caption);
end;
until (a > 0or (b = 15 )
...........//hier kommen dann die anweisungen die zutreffen sollen wenn die repeat schleife verlassen wird
//also eine der beiden bedingungen erfüllt worden ist....


das Programm besitzt ein Memo mit einem text darin, und einen Timer , der im Label1 Secunden zählt:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Zeit := Zeit + 1;
Label1.Caption := IntToStr(Zeit);
end;


nur es hängt sich wie gesagt auf.....
ausserdem kann es sein das auch wenn eine der beiden bedingungen für die repeat anweisung erfüllt worden ist, nichts passiert , also nicht die anweisungen unter der schleife ausgeführt werden :?: :? ( ist nur eine böse vorahnung )
danke schonmal für die hilfe bin ehrlich gesagt ratlos woran das wieder mal liegt :oops:


Zuletzt bearbeitet von CABALxx am Mi 03.03.04 19:59, insgesamt 2-mal bearbeitet
Sven
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 314


D6 Ent, K3 Pro (patched)
BeitragVerfasst: Mi 03.03.04 19:04 
Nur der Ordnung halber, den begin/end-Block zwischen repeat/until kannst Du weglassen.

Ansonsten sehe ich keinen Fehler. Hast Du den Timer auch eingeschaltet?

_________________
MDK 9.1, Kernel 2.4.21, KDE 3.1 Kylix 3 Pro (patched), nutze aber auch Windows
CABALxx Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 174


D7 Ent
BeitragVerfasst: Mi 03.03.04 19:06 
joa der timer ist an, den schalte ich mit nem andern button an un der läuft ja auch einwandtfrei
kann man ja ganz gut am Label sehn wenn der da zählt.....

ist nur ne kleine frage: kann es daran liegen das sich der Inhalt von Memo1 etwa alle 2,5 Secunden ändert ???
tomtom62
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 278

WIN 2000, XP prof
D5 prof.
BeitragVerfasst: Mi 03.03.04 19:14 
Zuerst einmal solltest Du mal prüfen, ob diese Bedingungen wirklich erfüllt werden können.

Es muss also entweder 'Mithrandir' im Memotext stehen oder es sollen 15 Sekunden vergehen. In jedem Fall ist es aber wohl so, dass das Programm alle Rechenzeit verbraucht, es muss noch ein

ausblenden Delphi-Quelltext
1:
Application.ProcessMessages					


irgendwo stehen, weil sonst für 15 Sekunden nichts mehr geht.

Die Frage, die sich für mich stellt ist: Warum muss das Programm 15 Sekunden warten ?. Nach dem Klick kannst Du sowieso keine Eingabe mehr machen, weil das Programm wegen fehlender Prozessorzeit die Eingabe nicht abfragen kann..

Problematisch ist auch, dass Du scheinbar nirgendwo Zeit auf 0 setzst.
Sven
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 314


D6 Ent, K3 Pro (patched)
BeitragVerfasst: Mi 03.03.04 19:16 
Das liegt wohl daran, daß Variablen bei Borland automatisch mit 0, NIL usw. initialisiert werden 8)

_________________
MDK 9.1, Kernel 2.4.21, KDE 3.1 Kylix 3 Pro (patched), nutze aber auch Windows
tomtom62
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 278

WIN 2000, XP prof
D5 prof.
BeitragVerfasst: Mi 03.03.04 19:18 
Das ist wohl richtig, aber was ist beim zweiten Durchlauf ? :wink:
tomtom62
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 278

WIN 2000, XP prof
D5 prof.
BeitragVerfasst: Mi 03.03.04 19:28 
CABALxx hat folgendes geschrieben:
joa der timer ist an, den schalte ich mit nem andern button an un der läuft ja auch einwandtfrei
kann man ja ganz gut am Label sehn wenn der da zählt.....

ist nur ne kleine frage: kann es daran liegen das sich der Inhalt von Memo1 etwa alle 2,5 Secunden ändert ???


Und Du bist sicher, dass sich der Memotext ändert ?

Ich würde die Schleife ändern auf

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
Ablauf: boolean;

ablauf:=false;
Zeit:=0;

while ablauf=false do
begin 

Application.ProcessMessages;

a := pos('Mithrandir', Memo1.Text ); 

Label2.Caption := IntToStr(a); 

if a > 0 then ablauf:=true;
b := StrToInt(Label1.Caption); 

if b > 15 then ablauf:=true;

end;


Eventuell gingen die Abbruchbedingungen auch kürzer:

ausblenden Delphi-Quelltext
1:
  ablauf:= (b > 15)					
CABALxx Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 174


D7 Ent
BeitragVerfasst: Mi 03.03.04 19:58 
Einwandtfrei
das funktioniert ja optimal :D :D :D :D

ist auch eine wesentlich durchschaubarere Lösung

vielen dank :)
echt klasse :D


wegen den Fragen zu dem Programm :
das ist ein Teil von einem Quiz

und das 15 Secunden warten , ist die Zeit die man hat um die Frage mit zu beantworten andern falls , also falls man 15 sec oder länger braucht kommt ne meldung das die richtige antwort 'Mithrandir' gewesen wäre :wink:


tomtom62 hat folgendes geschrieben:

Problematisch ist auch, dass Du scheinbar nirgendwo Zeit auf 0 setzst.


joa das Programm hats nicht gestört.... lol :lol: