Autor Beitrag
1Class
Hält's aus hier
Beiträge: 8



BeitragVerfasst: Mi 21.05.08 14:16 
Hey Leute
ich möcht zum Einstieg was mir die fehlende Seite mit dem Satzt des Pythagoras ausrechnet.
Nun habe ich schon gleich am Anfang ein Problem mit den Variablen.

Ich habe euch das Projekt mal angehängt.



Mfg
Einloggen, um Attachments anzusehen!
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mi 21.05.08 14:18 
Hallo und :welcome: in der Entwickler-Ecke

Poste doch einfach die passenden Teile aus deinem Quellcode und erläutere, wo es hakt. Das komplette Projekt durchgucken wird hier kaum jemand machen. ;-)

_________________
We are, we were and will not be.
1Class Threadstarter
Hält's aus hier
Beiträge: 8



BeitragVerfasst: Mi 21.05.08 14:26 
Dankeschön :)

Das hier ist die Stelle:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.Button1Click(Sender: TObject);
var sa, sb, sc: string;
begin
sa:= txt_SeiteA.Text
sb:= txt_SeiteB.Text
sc:= txt_SeiteC.Text
end;
end.



Er bleibt bei der sb Variable stehen undOperator oder Semikolon fehlt :)


Mfg

Moderiert von user profile iconAXMD: Delphi-Tags hinzugefügt
ZeitGeist87
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1593
Erhaltene Danke: 20

Win95-Win10
Delphi 10 Seattle, Rad Studio 2007, Delphi 7 Prof., C++, WSH, Turbo Pascal, PHP, Delphi X2
BeitragVerfasst: Mi 21.05.08 14:26 
Hallo!

Ich bin mal so frei

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:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    GroupBox1: TGroupBox;
    Button1: TButton;
    XPManifest1: TXPManifest;
    txt_SeiteA: TEdit;
    txt_SeiteC: TEdit;
    txt_SeiteB: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    procedure txt_SeiteAKeyPress(Sender: TObject; var Key: Char);
    procedure txt_SeiteBKeyPress(Sender: TObject; var Key: Char);
    procedure txt_SeiteCKeyPress(Sender: TObject; var Key: Char);
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.txt_SeiteAKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = '.' then 
    Key := ','; 
  if NOT (Key in [#8, '0'..'9', ',']) then 
    Key := #0;
end;

procedure TForm1.txt_SeiteBKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = '.' then
    Key := ',';
  if NOT (Key in [#8, '0'..'9', ',']) then
    Key := #0;
end;

procedure TForm1.txt_SeiteCKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = '.' then 
    Key := ',';
  if NOT (Key in [#8, '0'..'9', ',']) then
    Key := #0;
end;

procedure TForm1.Button1Click(Sender: TObject);
var sa, sb, sc: string;
begin
sa:= txt_SeiteA.Text;
sb:= txt_SeiteB.Text;
sc:= txt_SeiteC.Text;
end;

end.


Wie ist die Formel des Pythagoras?

ausblenden Quelltext
1:
a² + b² = c²					

_________________
Wer Provokationen, Ironie, Sarkasmus oder Zynismus herauslesen kann soll sie ignorieren um den Inhalt meiner Beiträge ungetrübt erfassen zu können.
baka0815
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 489
Erhaltene Danke: 14

Win 10, Win 8, Debian GNU/Linux
Delphi 10.1 Berlin, Java, C#
BeitragVerfasst: Mi 21.05.08 14:28 
Du solltest dir angewöhnen, hinter jede abgeschlossene Quelltextzeile ein Semikolon (;) zu setzen, auch wenn dies in Delphi vor "end." nicht benötigt wird, so doch am Ende von allen anderen :)
1Class Threadstarter
Hält's aus hier
Beiträge: 8



BeitragVerfasst: Mi 21.05.08 14:28 
Was man manchmal für Dumme Fehler macht, unglaublich :D
Danke dir ;)

Ja das ist ist die Formel.

//Edit Ich bin das an VB gewöhnt. Da muss man das nicht machen.

Mfg
ZeitGeist87
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1593
Erhaltene Danke: 20

Win95-Win10
Delphi 10 Seattle, Rad Studio 2007, Delphi 7 Prof., C++, WSH, Turbo Pascal, PHP, Delphi X2
BeitragVerfasst: Mi 21.05.08 14:30 
user profile icon1Class hat folgendes geschrieben:
Was man manchmal für Dumme Fehler macht, unglaublich :D
Danke dir ;)

Ja das ist ist die Formel.

//Edit Ich bin das an VB gewöhnt. Da muss man das nicht machen.

Mfg


Das es die Formel ist, weiß ich ^^

Ich wusste aber auch nicht wirklich, was dein Problem ist.
Kommst du jetzt weiter oder hast du immer noch das Problem, die fehlende Seite auszurechnen?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TForm1.txt_SeiteBKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = '.' then
    Key := ',';
  if NOT (Key in [#8, '0'..'9', ',']) then
    Key := #0;
end;

procedure TForm1.txt_SeiteCKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = '.' then 
    Key := ',';
  if NOT (Key in [#8, '0'..'9', ',']) then
    Key := #0;
end;


Würde ich das Programm in der Arbeit ausführen, würde ich eine Fehlermeldung bekommen.
Schuld daran ist das Dezimaltrennzeichen.
Dieses ist abhängig vom jeweils eingestellten Ländercode ;-)

Das nur nebenbei!

LG
Stefan

_________________
Wer Provokationen, Ironie, Sarkasmus oder Zynismus herauslesen kann soll sie ignorieren um den Inhalt meiner Beiträge ungetrübt erfassen zu können.
1Class Threadstarter
Hält's aus hier
Beiträge: 8



BeitragVerfasst: Mi 21.05.08 14:35 
Okay habe gerade ein neues Problem :D

Ich möchte das jetzt hiermit ausrechnen:

txt_SeiteC.Text:= sqr(strtofloat(sa*sa + sb*sb))

Doch ein Fehler wird ausgegeben das Operator nicht auf Operandentyp anwendbar ist:)


Ps: Sorry Leute für diese kleinen Probleme. Doch jeder fängt mal klein an ;)

Mfg
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mi 21.05.08 14:40 
StrToFloat wandelt dir wie der Name schon sagt einen String in eine Gleitkommazahl um. Mit Strings kannst du aber nicht rechnen. heißt: Du musst jeden String einzeln in eine Zahl umwandeln mit StrToFloat und dann damit rechnen:
ausblenden Delphi-Quelltext
1:
strtofloat(sa) * strtofloat(sa)					
usw.
ZeitGeist87
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1593
Erhaltene Danke: 20

Win95-Win10
Delphi 10 Seattle, Rad Studio 2007, Delphi 7 Prof., C++, WSH, Turbo Pascal, PHP, Delphi X2
BeitragVerfasst: Mi 21.05.08 14:40 
user profile icon1Class hat folgendes geschrieben:
Okay habe gerade ein neues Problem :D

Ich möchte das jetzt hiermit ausrechnen:

txt_SeiteC.Text:= sqr(strtofloat(sa*sa + sb*sb))

Doch ein Fehler wird ausgegeben das Operator nicht auf Operandentyp anwendbar ist:)


Ps: Sorry Leute für diese kleinen Probleme. Doch jeder fängt mal klein an ;)

Mfg


Kein Problem.

Du musst strToFloat auf jede deiner Stringvariable anwenden. Also:

ausblenden Delphi-Quelltext
1:
txt_SeiteC.Text:= FloatToStr(sqr(strtofloat(sa) * strtofloat(sa) + strtofloat(sb)*strtofloat(sb)));					


Hoff, ich hab mich jetzt nicht vertan ;-)

_________________
Wer Provokationen, Ironie, Sarkasmus oder Zynismus herauslesen kann soll sie ignorieren um den Inhalt meiner Beiträge ungetrübt erfassen zu können.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mi 21.05.08 14:44 
Doch, du hast das sqr nicht korrigiert, dieses ist aber square, also das Quadrat der Zahl. ;-)
Richtig hier ist sqrt, square root, also die Quadratwurzel.

Es geht also auch so:
ausblenden Delphi-Quelltext
1:
txt_SeiteC.Text:= FloatToStr(Sqrt(Sqr(StrToFloat(sa)) + Sqr(StrToFloat(sb))));					
Vorteil: Es wird nur einmal die Konvertierung des Strings in eine Zahl durchgeführt. ;-)
ZeitGeist87
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1593
Erhaltene Danke: 20

Win95-Win10
Delphi 10 Seattle, Rad Studio 2007, Delphi 7 Prof., C++, WSH, Turbo Pascal, PHP, Delphi X2
BeitragVerfasst: Mi 21.05.08 14:45 
user profile iconjaenicke hat folgendes geschrieben:
Doch, du hast das sqr nicht korrigiert, dieses ist aber square, also das Quadrat der Zahl. ;-)
Richtig hier ist sqrt, square root, also die Quadratwurzel.

Es geht also auch so:
ausblenden Delphi-Quelltext
1:
txt_SeiteC.Text:= FloatToStr(Sqrt(Sqr(StrToFloat(sa)) + Sqr(StrToFloat(sb))));					
Vorteil: Es wird nur einmal die Konvertierung des Strings in eine Zahl durchgeführt. ;-)


:P

Aber Recht hat er ;-)

_________________
Wer Provokationen, Ironie, Sarkasmus oder Zynismus herauslesen kann soll sie ignorieren um den Inhalt meiner Beiträge ungetrübt erfassen zu können.
1Class Threadstarter
Hält's aus hier
Beiträge: 8



BeitragVerfasst: Mi 21.05.08 14:48 
Boa Leute ihr seid die Besten. So schnell Hilfe bekommen :)
Danke
Wenn es weitere Probleme gibt melde ich mich ;)^^

//Edit Na wenn wir schon dabei sind, wie kann man die Fehlermeldung abfangen
oder unterdrücken, die auftaucht wenn man nichts eingibt?


Mfg :)
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Mi 21.05.08 14:57 
Hi!
Schau mal nach den Funktionen StrToFloatDef() und TryStrToFloat(). Entweder in der DoH oder hier im Forum solltest Du dazu genügend Infos finden.
€: Wenn Du zuvor bereits Falscheingaben verhinderst, reicht es wohl zu prüfen, ob der Text <> '' ist und entsprechend zu reagieren. ;)

Cheers,
Marc
1Class Threadstarter
Hält's aus hier
Beiträge: 8



BeitragVerfasst: Mi 21.05.08 16:04 
Ich verzweifel.
Ich habe herrausgefunden das TryStrToFloat einen BOOLschen Wert ausgibt.
Doch wie arbeite ich damit weiter?

Wenn ich das mit Text <> klappt auch nichts^^

if txt_SeiteA.Text:= <> = true then
begin
txt_SeiteC.Text:= FloatToStr(Sqrt(Sqr(StrToFloat(sa)) + Sqr(StrToFloat(sc))));
end;


Mfg
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mi 21.05.08 16:05 
delphi.about.com/lib...blrtlTryStrToInt.htm
Ein kleines Beispiel. ;-)
Der Rückgabewert gibt an, ob die Umwandlung erfolgreich war oder nicht.
1Class Threadstarter
Hält's aus hier
Beiträge: 8



BeitragVerfasst: Mi 21.05.08 16:26 
Egal wie ich es mache, kommen immer neue Fehler dazu.

Naja lassen wir das mal. Danke euch allen.


:)
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Mi 21.05.08 16:36 
user profile icon1Class hat folgendes geschrieben:
Ich verzweifel.
[...]
Wenn ich das mit Text <> klappt auch nichts^^

if txt_SeiteA.Text:= <> = true then
begin
txt_SeiteC.Text:= FloatToStr(Sqrt(Sqr(StrToFloat(sa)) + Sqr(StrToFloat(sc))));
end;

Dein Konstrukt vergiss besser einmal. ;)
Bedingung, dass eine Berechnung durchgeführt werden kann, ist einerseits die korrekte Eingabe einer Zahl und andererseits, dass überhaupt etwas eingegeben wurde.
Nun gibt es für dieses Problem mehere Lösungsansätze. Deiner schaut im Moment so aus, dass jedes Zeichen geprüft und entsprechend eingetragen wird. Heiß im konkreten nur 0-9, Komma und Punkt lassen sich eingeben. By the way, zu beachten wäre hier noch, dass lediglich ein Kommata oder Punkt akzeptiert wird!
Um nun auch die zweite Bedingung zu erschlagen, reicht eine einfache IF-Abfrage.
ausblenden Delphi-Quelltext
1:
2:
If (txt_SeiteA.text <> '') then 
 txt_SeiteC.Text:= FloatToStr( Sqrt(Sqr(StrToFloat(sa)) + Sqr(StrToFloat(sc))) );

Die zweite Variante zur Lösung des Problems wäre es die eingebene Zahl zusätzlich mit den TryStrToFloat() zu überprüfen. Ist (IF) dies True, so wird berrechnet, ansonsten (ELSE) nicht.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
var zahl: Real;
begin
 IF TryStrToFloat(eingegebenzahl,zahl) then
  txt_SeiteC.Text:= FloatToStr( Sqrt(Sqr(StrToFloat(sa)) + Sqr(StrToFloat(sc))) );


Cheers,
Marc


Zuletzt bearbeitet von Marc. am Mi 21.05.08 16:53, insgesamt 1-mal bearbeitet
1Class Threadstarter
Hält's aus hier
Beiträge: 8



BeitragVerfasst: Mi 21.05.08 16:50 
Jetzt bekomme ich das::D
Es gibt keine überladene Version von 'TryStrToFloat', die man mit diesen Argumenten aufrufen kann
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Mi 21.05.08 16:58 
Ich hab das Beispiel oben korrigiert!
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
var
 zahl: extended;
begin
 if TryStrToFloat(Text, Zahl) then // Text ist entsprechend zu ersetzen
    {berrechne mit Zahl!} else
   Showmessage('Bitte geben Sie eine korrekte Zahl ein!);
end;

Gibt TryStrToFloat True zurück, schreibt es die Float-Zahl in die als zweiten Parameter angegeben Zahl. :P
So sollte es nun funktionieren. ;)