![]() |
Delphi-Version: 7
Zahlensystem Oktal fehler
Hey Leute,
hab n kleines Problem...irgendwie spinn ich solangsam, weil ich den ganzen Morgen schon an diesem Blöden Prog. sitze -.- Hier Mein Quellcode:
Delphi-Quellcode:
Zur Frage: Wenn ich auf "play" drücke, kommen folgende Fehlermeldungen:
unit Unit1;
interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, math, StrUtils; type TForm1 = class(TForm) Eingabefeld: TEdit; Button1: TButton; Label1: TLabel; Button2: TButton; RadioGroup1: TRadioGroup; RadioGroup2: TRadioGroup; Ausgabefeld: TEdit; Button3: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; BinArray: Array [1..16] of Integer; // Aus Internet erworben laenge: Integer; Zahl: Integer; BolPruef : Boolean; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin close; end; procedure TForm1.Button2Click(Sender: TObject); function FOctToDec(FWert: String): String; function FBinToHex(FWert: String): String; function FDecToBin(FWert: String): String; var h,d,b,x,a,y,i:Integer; c:extended; s:string; begin {Hexadezimal in Dezimal} if (Radiogroup1.ItemIndex=1) and (Radiogroup2.itemindex=0) then begin h:=strtoint('$' + Eingabefeld.Text); //Umwandlung von h in Integer, Methode mit Dollarzeichen aus Internet erworben. Ausgabefeld.Text:=inttostr(h); //Ausgabe von h end; {Dezimal in Hexadezimal} if (Radiogroup1.itemindex=0) and (Radiogroup2.itemindex=1) then begin d:=strtoint(Eingabefeld.text); //Umwandlung von d in Integer Ausgabefeld.text:=Format('%x',[d]); //Ausgabe von d, Methode mit Format(...) aus Internet erworben. end; {Dezimal in Binär} if (Radiogroup1.itemindex=0) and (Radiogroup2.ItemIndex=2) then begin Ausgabefeld.Text:=''; //Löschen Des Textes Im Ausgabefeld,sonst kommt das Ergebnis der darauffolgenden Rechnung dazu b:=strtoint(Eingabefeld.text); //Umwandlung von b in Integer For x:= 1 to 16 do //Formel für Umrechnung aus Internet erworben, wären nie drauf gekommen. Begin BinArray[x]:= b mod 2; b := b div 2; Ausgabefeld.Text:= InttoStr(BinArray[x])+Ausgabefeld.text; If b = 0 Then break; end; end; {Binär in Dezimal} if (Radiogroup1.itemindex=2) and (Radiogroup2.ItemIndex=0) then begin s:=reversestring(Eingabefeld.text); //Drehen des Eingabestrings a:= Length(s); //Ermittlung der Länge des Eingabetextes/Eingabestrings c:= 0; //c wird auf 0 deklariert For y:= 1 to a do begin c := c+ Strtoint(s[y]) * power(2 , (-1 + y) ); end; Ausgabefeld.Text:= FloattoStr(c); //Ausgabe von c end; {Oktal in...} if Radiogroup1.ItemIndex=3 then begin for i := 1 to Length(Eingabefeld.Text) do BolPruef := Eingabefeld.Text[i] in ['0'..'7']; //Eingabe Überprüfen, Bolpruef aus Internet erworben if BolPruef = True then begin if Radiogroup1.ItemIndex=0 then Ausgabefeld.text := FOctToDec(Eingabefeld.Text); //Umwandlung von Oktal in Dezimal if Radiogroup1.ItemIndex=1 then Ausgabefeld.text := FBinToHex(FDecToBin(FOctToDec(Eingabefeld.Text))); //Erst Umwandlung von Oktal in Dezimal, dann von Dezimal in Binär, und schließlich von Bimär in Hexadezimal if Radiogroup1.ItemIndex=2 then Ausgabefeld.text := FDecToBin(FOctToDec(Eingabefeld.Text)); //Erst Umwandlung von Oktal in Dezimal, dann von Dezimal in Hexadezimal if Radiogroup1.ItemIndex=3 then Ausgabefeld.text := Eingabefeld.Text; end else application.messagebox('Wert nicht Oktal','Oktalsystem',MB_OK); //Fehlermeldung, wenn Inhalt vom Eingabefeld nicht dem Oktalzaflensystem entspricht end; end; procedure TForm1.Button3Click(Sender: TObject); begin Eingabefeld.text:=''; Ausgabefeld.text:=''; end; end. [Error] Unit1.pas(108): ';' expected but '.' found [Error] Unit1.pas(113): ';' expected but '.' found [Error] Unit1.pas(116): Declaration expected but end of file found [Error] Unit1.pas(21): Unsatisfied forward or external declaration: 'TForm1.Button3Click' Was mach ich falsch?? Danke im Vorraus, Gruß Michael Achso zur Information: Ist ein Projekt für Informatik.. Deswegen die Bemerkungen ;) |
AW: Zahlensystem Oktal fehler
Delphi-Quellcode:
Du "öffnest" damit 3 untergeordnete Funktionen und deklarierst (also
function FOctToDec(FWert: String): String;
function FBinToHex(FWert: String): String; function FDecToBin(FWert: String): String;
Delphi-Quellcode:
sie nicht.
begin ... end;
Nach dem
Delphi-Quellcode:
deiner Methode, also das vor
end;
Delphi-Quellcode:
, welches aber eigentlich das END von der letzen Funktion ist, erwartet Delphi nun die Funktions-Rümpfe der restlichen beiden Funktionen und der übergeordneten Methode.
procedure TForm1.Button3Clic
aber statt einem ![]()
Delphi-Quellcode:
) kommt bei dir nun schon die nächste Methode.
var
Es fehlt also was und demnach meckert Delphi, oder du hast eben zuviele Funktionen offen. :stupid: |
AW: Zahlensystem Oktal fehler
Ahha...danke...probier ich gleich mal aus ;)
|
AW: Zahlensystem Oktal fehler
Weniger Kommentare, Aufteilung in sinnvoll benannte Routinen und formatierter Quellcode. Dann siehst du das schon auf den ersten Blick, wenn du überhaupt den Fehler machst.
|
AW: Zahlensystem Oktal fehler
Ich habe mir mal die Arbeit gemacht und den Code sauber formatiert, damit du siehst, wie du es demnächst auch machen solltest, um Überblick zu behalten :wink:
Delphi-Quellcode:
Ist doch schon gleich viel besser lesbar, oder? :wink:
procedure TForm1.Button2Click(Sender: TObject);
function FOctToDec(FWert: string): string; function FBinToHex(FWert: string): string; function FDecToBin(FWert: string): string; var h, d, b, x, a, y, i: Integer; c: extended; s: string; begin { Hexadezimal in Dezimal } if (Radiogroup1.ItemIndex = 1) and (Radiogroup2.ItemIndex = 0) then begin // Umwandlung von h in Integer, Methode mit Dollarzeichen aus Internet erworben. h := StrToInt('$' + Eingabefeld.Text); // Ausgabe von h Ausgabefeld.Text := IntToStr(h); end; { Dezimal in Hexadezimal } if (Radiogroup1.ItemIndex = 0) and (Radiogroup2.ItemIndex = 1) then begin // Umwandlung von d in Integer d := StrToInt(Eingabefeld.text); // Ausgabe von d, Methode mit Format(...) aus Internet erworben. Ausgabefeld.Text := Format('%x', [d]); end; { Dezimal in Binär } if (Radiogroup1.ItemIndex = 0) and (Radiogroup2.ItemIndex = 2) then begin // Löschen Des Textes Im Ausgabefeld, sonst kommt das Ergebnis der darauffolgenden Rechnung dazu Ausgabefeld.Text := ''; // Umwandlung von b in Integer b := StrToInt(Eingabefeld.text); for x:= 1 to 16 do begin // Formel für Umrechnung aus Internet erworben, wären nie drauf gekommen. BinArray[x] := b mod 2; b := b div 2; Ausgabefeld.Text := IntToStr(BinArray[x]) + Ausgabefeld.Text; if b = 0 then break; end; end; { Binär in Dezimal } if (Radiogroup1.ItemIndex = 2) and (Radiogroup2.ItemIndex = 0) then begin // Drehen des Eingabestrings s := ReverseString(Eingabefeld.Text); // Ermittlung der Länge des Eingabetextes/Eingabestrings a := Length(s); // c wird auf 0 deklariert c := 0; for y := 1 to a do begin c := c + StrToInt(s[y]) * Power(2, (-1 + y)); end; // Ausgabe von c Ausgabefeld.Text := FloatToStr(c); end; { Oktal in... } if Radiogroup1.ItemIndex = 3 then begin for i := 1 to Length(Eingabefeld.Text) do // Eingabe Überprüfen, Bolpruef aus Internet erworben BolPruef := Eingabefeld.Text[i] in ['0'..'7']; if BolPruef then begin // Umwandlung von Oktal in Dezimal if Radiogroup1.ItemIndex = 0 then Ausgabefeld.text := FOctToDec(Eingabefeld.Text); // Erst Umwandlung von Oktal in Dezimal, dann von Dezimal in Binär, und schließlich von Bimär in Hexadezimal if Radiogroup1.ItemIndex = 1 then Ausgabefeld.text := FBinToHex(FDecToBin(FOctToDec(Eingabefeld.Text))); // Erst Umwandlung von Oktal in Dezimal, dann von Dezimal in Hexadezimal if Radiogroup1.ItemIndex = 2 then Ausgabefeld.text := FDecToBin(FOctToDec(Eingabefeld.Text)); if Radiogroup1.ItemIndex = 3 then Ausgabefeld.text := Eingabefeld.Text; end else // Fehlermeldung, wenn Inhalt vom Eingabefeld nicht dem Oktalzahlensystem entspricht Application.Messagebox('Wert nicht Oktal', 'Oktalsystem', MB_OK); end; end; procedure TForm1.Button3Click(Sender: TObject); begin Eingabefeld.Text := ''; Ausgabefeld.Text := ''; end; [edit] Es hat sich eingebürgert bzw. ist im Delphi-StyleGuide vorgeschrieben, dass
[edit2] Übrigens ist in den verschachtelten Funktionen das anführende 'F' sehr verwirrend. Man hält sie zunächst für Felder (Variablen in Objekten). |
Alle Zeitangaben in WEZ +1. Es ist jetzt 13:23 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz