Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Lazarus (IDE) (https://www.delphipraxis.net/81-lazarus-ide/)
-   -   Syntax Error: "BEGIN" expected but "end of file" found. (https://www.delphipraxis.net/175505-syntax-error-begin-expected-but-end-file-found.html)

sakomo 26. Jun 2013 16:52

Syntax Error: "BEGIN" expected but "end of file" found.
 
Hallo Zusammen,

Ich habe einen Latein Vokabeltrainer mit Lazarus programmiert und er sollte funktionieren. Wenn ich ihn alllerdings starten möchte kommt der Error aus dem Titel. Leider weiß ich nicht, was ich falsch gemacht habe.



Quelltext:


unit Unit1;



interface

uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
StdCtrls;

type

{ TForm1 }

TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
CheckBox1: TCheckBox;
Panel1: TPanel;
RadioGroup1: TRadioGroup;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;

const Max = 100;
var

Form1: TForm1;
Frage : Array[1..Max] of String;
Antwort: Array[1..Max, 1..3] of String;
Richtig: Array[1..Max] of Integer;
Nr : Integer;
Datei: TextFile;

implementation



{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
begin
if RadioGroup1.ItemIndex = Richtig[Nr]-1 then Panel1.Caption := 'Richtig!'
else Panel1.Caption := 'Falsch!'
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Nr := random (Max) +1;
Panel1.Caption := Frage[Nr] ;
RadioGroup1.Items[0] := Antwort[Nr,1];
RadioGroup1.Items[1] := Antwort[Nr,2];
RadioGroup1.Items[2] := Antwort[Nr,3];
if CheckBox1.Checked then RadioGroup1.ItemIndex := Richtig[Nr]-1
else RadioGroup1.ItemIndex := -1;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
close
end;

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer; Zeile: String;
begin
randomize;
AssignFile (Datei, 'DelphiVokabeln.txt');

Reset (Datei) ;
for i := 1 To Max do
begin
ReadLn (Datei, Frage[i]);
ReadLn (Datei, Antwort[i,1]);
ReadLn (Datei, Antwort[i,2]);
ReadLn (Datei, Antwort[i,3]);
ReadLn (Datei, Zeile);
Richtig[i] := StrToInt (Zeile);
end;
end;



end.

DeddyH 26. Jun 2013 17:03

AW: Syntax Error: "BEGIN" expected but "end of file" found.
 
Mal mit Delphi-Tags und Formatierung:
Delphi-Quellcode:
unit Unit1;

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
  StdCtrls;

type

{ TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    CheckBox1: TCheckBox;
    Panel1: TPanel;
    RadioGroup1: TRadioGroup;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
{ private declarations }
  public
{ public declarations }
  end;

const
  Max = 100;

var

  Form1: TForm1;
  Frage: Array [1 .. Max] of String;
  Antwort: Array [1 .. Max, 1 .. 3] of String;
  Richtig: Array [1 .. Max] of Integer;
  Nr: Integer;
  Datei: TextFile;

implementation

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
begin
  if RadioGroup1.ItemIndex = Richtig[Nr] - 1 then
    Panel1.Caption := 'Richtig!'
  else
    Panel1.Caption := 'Falsch!'
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Nr := random(Max) + 1;
  Panel1.Caption := Frage[Nr];
  RadioGroup1.Items[0] := Antwort[Nr, 1];
  RadioGroup1.Items[1] := Antwort[Nr, 2];
  RadioGroup1.Items[2] := Antwort[Nr, 3];
  if CheckBox1.Checked then
    RadioGroup1.ItemIndex := Richtig[Nr] - 1
  else
    RadioGroup1.ItemIndex := -1;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  close
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
  Zeile: String;
begin
  randomize;
  AssignFile(Datei, 'DelphiVokabeln.txt');

  Reset(Datei);
  for i := 1 To Max do
    begin
      ReadLn(Datei, Frage[i]);
      ReadLn(Datei, Antwort[i, 1]);
      ReadLn(Datei, Antwort[i, 2]);
      ReadLn(Datei, Antwort[i, 3]);
      ReadLn(Datei, Zeile);
      Richtig[i] := StrToInt(Zeile);
    end;
end;

end.
Auf den ersten Blick seh ich aber nichts, was die Fehlermeldung verursacht. Vielleicht ist die *.lpr gemeint?

sakomo 26. Jun 2013 17:09

AW: Syntax Error: "BEGIN" expected but "end of file" found.
 
Vielleicht sollte ich noch dazu sagen, dass der Fehler in der 1.Zeile beim 1.Wort liegt

p80286 26. Jun 2013 17:33

AW: Syntax Error: "BEGIN" expected but "end of file" found.
 
Zitat:

Zitat von sakomo (Beitrag 1219815)
Vielleicht sollte ich noch dazu sagen, dass der Fehler in der 1.Zeile beim 1.Wort liegt

Das ist eine schöne Information, dann ist es ggf. sinnvoll das ganze Projekt anzuhängen.

Gruß
K-H

DeddyH 26. Jun 2013 17:41

AW: Syntax Error: "BEGIN" expected but "end of file" found.
 
Coole Idee, da hätte ich auch drauf kommen können :zwinker:

sakomo 26. Jun 2013 17:56

AW: Syntax Error: "BEGIN" expected but "end of file" found.
 
tut mir leid ich habe es erst später gesehen:-D Aber was soll ich jetzt machen? ich muss morgen das projekt abgeben:(

DeddyH 26. Jun 2013 18:22

AW: Syntax Error: "BEGIN" expected but "end of file" found.
 
Pack es in ein Zip-Archiv und lad es hier hoch, dann schauen wir mal drüber.

uligerhardt 27. Jun 2013 07:53

AW: Syntax Error: "BEGIN" expected but "end of file" found.
 
Ich kenne mich mit Lazarus nicht weiter aus, aber fehlt da nicht ein
Delphi-Quellcode:
{$R *.lfm}
oder was ähnliches?

Memnarch 27. Jun 2013 09:15

AW: Syntax Error: "BEGIN" expected but "end of file" found.
 
Ich würde in Lazarus auch noch den Parser bestimmen(Willst du per Delphi-STyle oder ObjectPascal programmieren?)

Ich vermisse diese settings:

Delphi-Quellcode:
{$mode delphi}
oder

Delphi-Quellcode:
{$mode objfpc}
@uligerhardt: man kann sogar *.dfm nehmen ;)

sakomo 1. Jul 2013 06:08

AW: Syntax Error: "BEGIN" expected but "end of file" found.
 
Also ich habe es jetzt mit Delphi probiert und jetzt klappt soweit alles nur das jetzt die Datei nicht gefunden wird. Muss man die an eine bestimmte Stelle tun ( also iregendwo in den Delphi Ordner oder so)? :)


Alle Zeitangaben in WEZ +1. Es ist jetzt 10:23 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz