Autor Beitrag
GericasS
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 540

Windows Vista Home Premium
D2010, VisualStudio2008
BeitragVerfasst: Sa 26.07.08 20:41 
Hey Leute,

ich steh im Moment ein wenig neben mir nach dem langen Urlaub, ich hab folgendes Problem.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
var
  Form1: TForm1;
  wert : Integer ;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
i,zahl : Integer ;
begin
 zahl := StrToIntDef(edit1.Text,0);
 wert := wert+zahl ;
 Label1.Caption := IntToStr(wert);
end;

end.


Ich addiere immer die Variable "zahl" zu der globalen Variable "wert". Wie kann ich es anstellen dass ich diesen Vorgang höchstens 5 mal hintereinander durchführen kann. Ich hab dabei an eine for Schleife gedacht mit einer globalen Zähler Variable nur wie setzte ich das richtig um ?

:roll: es ist wirklich lang her dass ich was gemacht habe :wink:

LG

GericasS

_________________
Alexander N.
Neue Bewaffnung Amilo xi2428 T9300
jakobwenzel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: Sa 26.07.08 20:48 
Du brauchst keine Schleife, sondern du musst mitzählen, wie oft der Button schon gedrückt wurde, und dann bei zu hoher Anzahl einfach nichts machen und am Besten den Button deaktivieren.

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
Hidden
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2242
Erhaltene Danke: 55

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: Sa 26.07.08 21:16 
Wenns wirklich nur ums Beschränken geht, prüf doch einfach auf den Wert, den die Variable hat?

_________________
Centaur spears can block many spells, but no one tries to block if they see that the spell is a certain shade of green. For this purpose it is useful to know some green stunning hexes. (HPMoR)
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Sa 26.07.08 21:24 
Button.Tag auf 5 setzen. Bei jedem Klick auf den Button dann dec(Button.Tag) und if Button.Tag > 0 then...

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
GericasS Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 540

Windows Vista Home Premium
D2010, VisualStudio2008
BeitragVerfasst: So 27.07.08 07:37 
ausblenden Delphi-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:
26:
v
var
  Form1: TForm1;
  wert,i : Integer ;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
zahl : Integer ;
begin
 inc(i);
 zahl := StrToIntDef(edit1.Text,0);
 wert := wert+zahl ;
 Label1.Caption := IntToStr(wert);
 if i = 5 then
 begin
 showmessage('Ende');
 ...do something
 i := 0 ;
 end;
end;

end.



so hab ichs jetzt gelöst, ist das eher unpraktisch oder gut so ?

LG

GericasS

PS : das ist doch GTA Place seine Möglichkeit nur anderstrum oder ?

_________________
Alexander N.
Neue Bewaffnung Amilo xi2428 T9300
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: So 27.07.08 07:42 
Das geht, aber du könntest dir die Variable I sparen, wenn du auf den Tag-Wert vom Button zugreifst.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Hidden
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2242
Erhaltene Danke: 55

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: So 27.07.08 07:42 
Hi,

Erstmal: i ist für eine globale Zählvariable ein sehr unglücklicher Name; nimm lieber was selbsaterklärendes, dann belegst du dir auch nicht den Bezeichner i für die Unit und alle, die sie einbinden ;)

Statt Inc(i); nimmst du dann am besten auch gleich'Inc((Sender as TComponent).Tag);'

mfG,

_________________
Centaur spears can block many spells, but no one tries to block if they see that the spell is a certain shade of green. For this purpose it is useful to know some green stunning hexes. (HPMoR)
Grenzgaenger
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: So 27.07.08 09:23 
du weisst ja, dass du hier 'ne falsche logik drin hast, da deine zaehlung und ausgabe immer erfolgt.