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

Windows Vista Home Premium
D2010, VisualStudio2008
BeitragVerfasst: Mo 01.10.07 07:30 
Hey,

ich hab heute mal versucht mit Random Zahlen zu rechnen. Die zufällige Zahl auszugeben hat auch super funktioniert. Dann wollte ich diese "zufällige" Zahl mit einer bestimmten addieren über ein edit Feld

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TForm1.FormCreate(Sender: TObject);
begin
  randomize ;
  label1.caption := IntToStr(random(100)) ;
end;

procedure TForm1.Edit1Change(Sender: TObject);
var zahl1, zahl2, summe : Integer ;
begin
  zahl2 := StrToInt(edit1.text) ;
  summe := zahl1(label1.caption) + zahl2 ;
  Label2.Caption := IntToStr(summe) ;
end;

end.


Ich denke mal das Problem liegt daran das er beim Random IntToStr rechnet und somit schon seinen String hat, aber bei der zahl2 erst in einen Integer Wert umwandelt, kann ich i-wie
noch ein StrToInt bei der Random Zahl einfügen, so das er die zahlen zusammenrechnen kann
Ansonsten gibt er mit dauerhaft die Meldung Operator oder Semikolon fehlt an dieser Stelle
ausblenden Delphi-Quelltext
1:
summe := zahl1(label1.caption) + zahl2 ;					

?

Grüße

GericasS

_________________
Alexander N.
Neue Bewaffnung Amilo xi2428 T9300
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mo 01.10.07 07:41 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.Edit1Change(Sender: TObject);
var zahl1, zahl2, summe : Integer ;
begin
  zahl1 := StrToInt(label1.caption) ;
  zahl2 := StrToInt(edit1.text) ;
  summe := Zahl1 + zahl2 ;
  Label2.Caption := IntToStr(summe) ;
end;


Du musst schon den Datentyp umwandeln, wenn Du mit dem String rechnen wolltest.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
GericasS Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 540

Windows Vista Home Premium
D2010, VisualStudio2008
BeitragVerfasst: Mo 01.10.07 07:48 
Danke für die super schnelle Hilfe. Darauf hatte ich gar nicht geachtet !

Grüße

GericasS

_________________
Alexander N.
Neue Bewaffnung Amilo xi2428 T9300