Autor Beitrag
MilKeeway
Hält's aus hier
Beiträge: 9



BeitragVerfasst: Sa 31.10.09 13:56 
Hallo!

Ich bin neu hier und bräuchte mal Hilfe.
Ich lerne seit 1 1/2 Monate mit Delphi zu programmieren und hab jetzt mal was ausprobiert.
Und zwar: Man kann am Anfang auswählen, mit Hilfe von RadioButtons, welches Geometrische Objekt berechnen will.
Danach erscheinen die Labelededit Felder, in denen gibt man nun die Zahlen ein und drückt dann auf Rechnen. Dann wird der ausgerechnete Wert im Volumen und Oberfläche Feld angegeben.

Nun hab ich das Problem, dass, wenn ich Quadratische Pyramide auswähle, Zahlen eingebe und dann auf den Button klicke, das Ergebnis immer 0 ist.

Was muss ich da den ändern?
Hier der Quellcode:
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:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    btnRechnen: TButton;
    rbtnWuerfel: TRadioButton;
    rbtnQuader: TRadioButton;
    rbntPyramideAllgemein: TRadioButton;
    lbla: TLabeledEdit;
    lblb: TLabeledEdit;
    lblh: TLabeledEdit;
    lblHa: TLabeledEdit;
    lblV: TLabeledEdit;
    lblO: TLabeledEdit;
    lblHb: TLabeledEdit;
    rbtnPyramideQuader: TRadioButton;
    procedure RadioButtonCLick(Sender: TObject);
    procedure btnRechnenClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.btnRechnenClick(Sender: TObject);
var a, b, h, ha, hb, Vol, Ober: double;
begin
  lblV.Visible:=true;
  lblO.Visible:=true;
  if rbtnQuader.Checked then
  begin
    try
   a:=strtofloat(lbla.Text);
    except
    Application.MessageBox('Nur Zahlen verwenden','Falsche Eingabe',16);
    lbla.SetFocus;
    exit;
    end;
    try b:=strtofloat(lblb.Text);
    except
    Application.MessageBox('Nur Zahlen verwenden','Falsche Eingabe',16);
    lblb.SetFocus;
    exit;
    end;
   try
   h:=strtofloat(lblh.Text);
   except
   Application.MessageBox('Nur Zahlen verwenden','Falsche Eingabe',16);
   lblh.SetFocus;
   exit;
   end;
   end;
   Vol:=a*b*h;
   Ober:=2*(a*b+a*h+b*h);
   lblV.Text:=floattostrF(Vol,fffixed,8,2);
   lblO.Text:=floattostrF(Ober,fffixed,8,2);
   begin
     if rbtnWuerfel.Checked then
    try
    a:=strtofloat(lbla.Text)
    except
       Application.MessageBox('Nur Zahlen verwenden','Falsche Eingabe',16);
       lbla.SetFocus;
       exit;
     end;
     Vol:=a*a*a;
     Ober:=6*a*a;
     lblV.Text:=floattostrF(Vol,fffixed,8,2);
     lblO.Text:=floattostrF(Ober,fffixed,8,2);
   begin
     if rbntPyramideAllgemein.Checked then
    begin
    try
   a:=strtofloat(lbla.Text);
    except
    Application.MessageBox('Nur Zahlen verwenden','Falsche Eingabe',16);
    lbla.SetFocus;
    exit;
    end;
    try b:=strtofloat(lblb.Text);
    except
    Application.MessageBox('Nur Zahlen verwenden','Falsche Eingabe',16);
    lblb.SetFocus;
    exit;
    end;
   try
   h:=strtofloat(lblh.Text);
   except
   Application.MessageBox('Nur Zahlen verwenden','Falsche Eingabe',16);
   lblh.SetFocus;
   exit;
   end;
   try
   ha:=strtofloat(lblha.Text);
   except
   Application.MessageBox('Nur Zahlen verwenden','Falsche Eingabe',16);
   lblha.SetFocus;
   exit;
   end;
   try
   hb:=strtofloat(lblhb.Text);
   except
   Application.MessageBox('Nur Zahlen verwenden','Falsche Eingabe',16);
   lblhb.SetFocus;
   exit;
   end;
   Vol:=1/3*a*b*h;
   Ober:=a*b+2*(a*ha/2)+2*(b*hb/2);
   lblV.Text:=floattostrF(Vol,fffixed,8,2);
   lblO.Text:=floattostrF(Ober,fffixed,8,2);
   begin
     if rbtnPyramideQuader.Checked then
      begin
    try
   a:=strtofloat(lbla.Text);
    except
    Application.MessageBox('Nur Zahlen verwenden','Falsche Eingabe',16);
    lbla.SetFocus;
    exit;
    end;
   try
   h:=strtofloat(lblh.Text);
   except
   Application.MessageBox('Nur Zahlen verwenden','Falsche Eingabe',16);
   lblh.SetFocus;
   exit;
   end;
   try
   ha:=strtofloat(lblha.Text);
   except
   Application.MessageBox('Nur Zahlen verwenden','Falsche Eingabe',16);
   lblha.SetFocus;
   exit;
   end;
   end;
   Vol:=1/3*a*a*h;
   Ober:=a*a+4*(a*ha);
   lblV.Text:=floattostrF(Vol,fffixed,8,2);
   lblO.Text:=floattostrF(Ober,fffixed,8,2);
      end;
      end;
      end;
      end;

end;





procedure TForm1.FormCreate(Sender: TObject);
begin
  lbla.Visible:=false;
  lblb.Visible:=false;
  lblh.Visible:=false;
  lblha.Visible:=false;
  lblhb.Visible:=false;
  lblV.Visible:=false;
  lblO.Visible:=false;
  btnRechnen.Visible:=false;
end;

procedure TForm1.RadioButtonCLick(Sender: TObject);
begin
if rbntPyramideAllgemein.Checked
then
begin
lbla.Visible:=true;
btnRechnen.Visible:=true;
lblha.Visible:=true;
lblhb.Visible:=true;
lblb.Visible:=true;
lblh.Visible:=true;
end;

if rbtnQuader.Checked then
begin lbla.Visible:=true;
      btnRechnen.Visible:=true;
      lblha.Visible:=false;
      lblhb.Visible:=false;
      lblh.Visible:=true;
      lblb.Visible:=true;
      end;
if rbtnWuerfel.Checked then
begin lbla.Visible:=true;
      btnRechnen.Visible:=true;
      lblha.Visible:=false;
      lblb.Visible:=false;
      lblh.Visible:=false;
      lblhb.Visible:=false;
      end;
if rbtnPyramideQuader.Checked then
begin lbla.Visible:=true;
      btnRechnen.Visible:=true;
      lblb.Visible:=false;
      lblhb.Visible:=false;
      lbla.Visible:=true;
      lblh.Visible:=true;
      lblha.Visible:=true;
end;

end;
end.


Hoffe ihr könnt mir helfen. Schon mal ein Thx :D

EDIT: Hab das Problem schon gefunden. Hatte das end; vergessen.
Xion
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
EE-Maler
Beiträge: 1952
Erhaltene Danke: 128

Windows XP
Delphi (2005, SmartInspect), SQL, Lua, Java (Eclipse), C++ (Visual Studio 2010, Qt Creator), Python (Blender), Prolog (SWIProlog), Haskell (ghci)
BeitragVerfasst: Mo 02.11.09 21:15 
Hi,

rücke mal ordentlicher ein, dann übersiehst du das auch nicht ;)

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure
begin
   if
   else
       begin
           try
           except
           end;
       end;
end;


dann blickt man halbwegs was los ist. Lieber ein Leerzeichen zu viel als zu wenig ;) Sonst halt Teile auslagern

_________________
a broken heart is like a broken window - it'll never heal
In einem gut regierten Land ist Armut eine Schande, in einem schlecht regierten Reichtum. (Konfuzius)