Autor Beitrag
lanzelot
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: So 06.03.05 23:09 
Hallo zusammen

ich bin einen Taschenrechner am programmieren. die Zahlen gebe ich nicht über die tastatur sonder über buttons ein.
zu meinem Problem:

wie kann ich einen punkt zu einer Zahl in einem Edit Feld hinzufügen.
Beispiel: Ich habe die zahl 123 und möchte ein Komma hinzufügen um die Zahl 123,45 zu schreiben.

Ich habe es so versucht:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
var zahl: real;
begin
zahl := strtofloat(edit1.Text);
zahl := zahl,;
edit1.Text :=floattostr(z);
end;


ich habe sehr wenig programmierkenntnisse und bin sehr froh, wenn mir jemand weiter helfen kann. Danke

Gruss Lanzelot

Moderiert von user profile iconraziel: Delphi-Tags hinzugefügt.
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: So 06.03.05 23:10 
poste doch mal den code den du bereits hast. am besten komplett

_________________
es gibt leute, die sind genetisch nicht zum programmieren geschaffen.
in der regel haben diese leute die regel...
lanzelot Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: Mo 07.03.05 11:35 
Bis jetzt habe ich das einfügen von der neuen Zahl so gelöst:
ich lese die zahl aus, multipliziere sie mit 10 und addiere die gewünschte zahl.

Beispiel:
ich möchte 51 schreiben. drücke ich den button 5. danach lese ich 5 heraus, multipliziere mit 10, habe also 50 und addiere noch 1 dazu. nun schiebe ich die zahl wieder ins selbe edit1 zurück.

Dies geht aber nur bei zahlen ohne Komma. Ich stelle mir vor, dass es eine viel einfachere Art gibt. die sollte ungefähr so aussehen:

Text auslesen, am Text eine zahl oder ein Komma hinzufügen, Text zurückschieben.

Ich habe das Programm hinzugefügt. der Button mit dem Komma habe ich Rot eingefärbt.
edit2 dient nur dazu, um den ersten Wert abzuspeichern. im edit3 wird das operationszeichen gespeichert (+=1, -=2, *=3, /=4)





ausblenden volle Höhe 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:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
unit untrech4;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    Button7: TButton;
    Button8: TButton;
    Button9: TButton;
    Button10: TButton;
    Button11: TButton;
    Button12: TButton;
    Button13: TButton;
    Button14: TButton;
    Button15: TButton;
    Button16: TButton;
    Edit1: TEdit;
    Button17: TButton;
    Edit2: TEdit;
    Label1: TLabel;
    Edit3: TEdit;
    Label2: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Button9Click(Sender: TObject);
    procedure Button10Click(Sender: TObject);
    procedure Button12Click(Sender: TObject);
    procedure Button13Click(Sender: TObject);
    procedure Button14Click(Sender: TObject);
    procedure Button15Click(Sender: TObject);
    procedure Button17Click(Sender: TObject);
    procedure Button11Click(Sender: TObject);
    procedure Button16Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var  z: real;
begin
z := strtofloat(edit1.Text);
z := (z*10)+1;
edit1.Text :=floattostr (z);
end;

procedure TForm1.Button2Click(Sender: TObject);
var  z: real;
begin
z := strtofloat(edit1.Text);
z := (z*10)+2;
edit1.Text :=floattostr (z);

end;

procedure TForm1.Button3Click(Sender: TObject);
var  z: real;
begin
z := strtofloat(edit1.Text);
z := (z*10)+3;
edit1.Text :=floattostr (z);
end;

procedure TForm1.Button4Click(Sender: TObject);
var  z: real;
begin
z := strtofloat(edit1.Text);
z := (z*10)+4;
edit1.Text :=floattostr (z);
end;

procedure TForm1.Button5Click(Sender: TObject);
var  z: real;
begin
z := strtofloat(edit1.Text);
z := (z*10)+5;
edit1.Text :=floattostr (z);

end;

procedure TForm1.Button6Click(Sender: TObject);
var  z: real;
begin
z := strtofloat(edit1.Text);
z := (z*10)+6;
edit1.Text :=floattostr (z);

end;

procedure TForm1.Button7Click(Sender: TObject);
var  z: real;
begin
z := strtofloat(edit1.Text);
z := (z*10)+7;
edit1.Text :=floattostr (z);

end;

procedure TForm1.Button8Click(Sender: TObject);
var  z: real;
begin
z := strtofloat(edit1.Text);
z := (z*10)+8;
edit1.Text :=floattostr (z);
end;

procedure TForm1.Button9Click(Sender: TObject);
var  z: real;
begin
z := strtofloat(edit1.Text);
z := (z*10)+9;
edit1.Text :=floattostr (z);

end;

procedure TForm1.Button10Click(Sender: TObject);
var  z: real;
begin
z := strtofloat(edit1.Text);
z := (z*10)+0;
edit1.Text :=floattostr (z);
end;

//addition
procedure TForm1.Button12Click(Sender: TObject);
var e, i, n: real;
begin
n:= 0;
e:= strtofloat(edit1.text);
i:=1;
edit1.Text:= floattostr(n);
edit2.Text:= floattostr(i);
edit3.Text:= floattostr(e);

end;
//subtraktion
procedure TForm1.Button13Click(Sender: TObject);
var e, i, n: real;
begin
n:= 0;
e:= strtofloat(edit1.text);
i:=2;
edit1.Text:= floattostr(n);
edit2.Text:= floattostr(i);
edit3.Text:= floattostr(e);
end;

//multiplikation
procedure TForm1.Button14Click(Sender: TObject);
var e, i, n: real;
begin
n:= 0;
e:= strtofloat(edit1.text);
i:=3;
edit1.Text:= floattostr(n);
edit2.Text:= floattostr(i);
edit3.Text:= floattostr(e);
end;

//division
procedure TForm1.Button15Click(Sender: TObject);
var e, i, n: real;
begin
n:= 0;
e:= strtofloat(edit1.text);
i:=4;
edit1.Text:= floattostr(n);
edit2.Text:= floattostr(i);
edit3.Text:= floattostr(e);

end;
//gleich
procedure TForm1.Button17Click(Sender: TObject);
var e,i,f,r:real;
begin
f:= strtofloat(edit1.Text);
i:= strtofloat(edit2.Text);
e:= strtofloat(edit3.Text);

if i=1 then
r:= e+f;
edit1.Text:=floattostr(r);

if i=2 then
r:= e-f;
edit1.Text:=floattostr(r);

if i=3 then
r:= e*f;
edit1.Text:=floattostr(r);

if i=4 then
r:= e/f;
edit1.Text:=floattostr(r);


end;

procedure TForm1.Button11Click(Sender: TObject);
var  z: real;
begin

z := strtofloat(edit1.Text);
z := z,;
edit1.Text :=floattostr '(z)';
end;

procedure TForm1.Button16Click(Sender: TObject);
var n:real;
begin
n:=0;
edit1.Text:= floattostr(n);
edit2.Text:= floattostr(n);
edit3.Text:= floattostr(n);
end;

end.


Moderiert von user profile iconChristian S.: Delphi-Tags hinzugefügt.
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Mo 07.03.05 12:00 
Titel: Einfacher : Komma und ... in einem edit hinzufügen
Hallo,

der Umweg über strtofloat/floattostr ist nicht erforderlich, so ist es einfacher:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.Button1Click(Sender: TObject);  
  //var  z: real;  
begin  
  //z := strtofloat(edit1.Text);  
  //z := (z*10)+1;  
  //edit1.Text :=floattostr (z);
  edit1.Text := edit1.Text + '1';  
end;


So kannst Du auch ein Komma anfügen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.Button11Click(Sender: TObject);  
begin
  edit1.Text :=edit1.Text + ',';
end;


MfG
Lannes

Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt.
lanzelot Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: Mo 07.03.05 12:52 
Vielen Dank, hat geklappt :lol: man muss eben wissen, wie diese ganzen Befehle heissen...

MFG Lanzelot