Autor Beitrag
Raezor
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 54

Status:
Administrator des Mondes
BeitragVerfasst: Sa 17.03.07 15:59 
Habe auf meiner Folie:
Label5
Button1
.

Wenn ich nun auf button1 klicke, soll er zu dem caption des label5 die zahl 1 dazu addieren.
Das Label5 hat die caption 200.
Drücke ich nun auf den button1, soll die Caption des Label5 eine 201 zeigen.
Drücke ich nochmal auf den Button1, soll Label5 eine 202 zeigen...usw.
Wie geht das?


Moderiert von user profile iconUGrohne: Topic aus Sonstiges (Delphi) verschoben am Di 20.03.2007 um 12:06
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Sa 17.03.07 16:03 
Inc(i)

_________________
Blackheart666
Der Irrsinn ist bei Einzelnen etwas Seltenes, - aber bei Gruppen, Parteien, Völkern, Zeiten die Regel. (Friedrich Nietzsche)
Xabitire
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 114

Win Xp, Win Vista
D6 PE, D7 PE
BeitragVerfasst: Sa 17.03.07 16:04 
Wie wärs mit:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.Button1Click(Sender: TObject);
var anzahl: integer;
begin
  anzahl := strtoint(label5.caption);
  anzahl := anzahl + 1;
  label5.caption := inttostr(anzahl);
end;

end.


MFG

Blackbird8690
Raezor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 54

Status:
Administrator des Mondes
BeitragVerfasst: Sa 17.03.07 16:13 
@ Blackheart: kann man das essen?

@ blackbird: danke, funktioniert
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Sa 17.03.07 16:21 
Essen nicht, aber einiges an Code sparen.

_________________
Blackheart666
Der Irrsinn ist bei Einzelnen etwas Seltenes, - aber bei Gruppen, Parteien, Völkern, Zeiten die Regel. (Friedrich Nietzsche)
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Sa 17.03.07 16:41 
user profile iconblackbird8690 hat folgendes geschrieben:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.Button1Click(Sender: TObject);
var anzahl: integer;
begin
  anzahl := strtoint(label5.caption);
  anzahl := anzahl + 1;
  label5.caption := inttostr(anzahl);
end;


ist umständlich,
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.Button1Click(Sender: TObject);
var anzahl: integer;
begin
  anzahl := strtoint(label5.caption);
  inc(anzahl); //<--
  label5.caption := inttostr(anzahl);
end;

...ist einfach.

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
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 17.03.07 16:52 
Bei neuen Delphi-Versionen sollte jedoch bei beidem der gleiche Code rauskommen, da der Compiler das erste so optimiert, dass das selbe wie das in dem Fall bessere 2. rauskommt.
Bei alten Delphiversionen bin ich mir da nicht so sicher.

Wenn man den Befehl inc jedoch erstmal kennt, wirkt es IMHO aber auch übersichtlicher. :wink:

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
hathor
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Sa 17.03.07 18:18 
Zur Vereinfachung habe ich auch was beizutragen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
//Label5.Caption:= '200'; (designed)
procedure TForm1.Button1Click(Sender: TObject);
begin
Label5.Caption:= IntToStr(StrToInt(Label5.Caption)+1);
end;
Raezor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 54

Status:
Administrator des Mondes
BeitragVerfasst: So 18.03.07 07:30 
Ich wollte dies nun noch bei einem Shape1.Left verwenden, doch er sagt,
Inkompatible: Integer und TCaption.
was muss ich noch machen?
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: So 18.03.07 09:13 
Mal so geraten bei der Fragestellung.
ausblenden Delphi-Quelltext
1:
Shape1.Left:=StrToInt(Label5.Caption);					

_________________
Blackheart666
Der Irrsinn ist bei Einzelnen etwas Seltenes, - aber bei Gruppen, Parteien, Völkern, Zeiten die Regel. (Friedrich Nietzsche)
Raezor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 54

Status:
Administrator des Mondes
BeitragVerfasst: So 18.03.07 10:03 
danke erstmal, es geht.
Aber noch was:
Hier hat er ein paar probleme, wie würde es richtig lauten?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.Timer21Timer(Sender: TObject);
begin
if Label2.Caption < 0 then
 begin
  label2.Caption:= '700';

end;


Moderiert von user profile iconChristian S.: Code- durch Delphi-Tags ersetzt
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: So 18.03.07 10:12 
Vieleicht So
if StrToInt(Label2.Caption) <=0 then
aber auf so etwas müsste man eigentlich allein kommen.

_________________
Blackheart666
Der Irrsinn ist bei Einzelnen etwas Seltenes, - aber bei Gruppen, Parteien, Völkern, Zeiten die Regel. (Friedrich Nietzsche)
Raezor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 54

Status:
Administrator des Mondes
BeitragVerfasst: So 18.03.07 10:24 
ok
hatte keine lust, nachzudenken :wink:
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Di 20.03.07 00:37 
user profile iconRaezor hat folgendes geschrieben:
hatte keine lust, nachzudenken :wink:

:roll:
Carpe Diem :|

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.