Error: Expected but found

4. '.' expected but ';' found

Pôvodný zdrojový kód

unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Edit1: TEdit;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var n: integer;
begin
n:= StrToInt(Edit1.Text);
if n mod 2 = 0 then begin
Label1.Caption:= 'Parne cislo'
end
else begin
Label1.Caption:= 'Neparne cislo'
end;
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Label1.Caption:= 'Pocet cislic: ' + IntToStr(length(Edit1.Text));
end;

procedure TForm1.Button3Click(Sender: TObject);
var n, pocet: integer;
begin
n:= StrToInt(Edit1.Text);
pocet:= 0;
while n>0 do begin
if (n mod 10) mod 10 = 1 then inc(pocet);
n:= n div 10;
end;

Label1.Caption:= 'Pocet jednotiek v cisle: ' + IntToStr(pocet);
end;

{

[Error] Unit1.pas(43): '.' expected but ';' found

--------------------------------------------------------------------------------

Očakávala sa . ale našla ;

PREČO?

Chybu spôsobilo end, ktoré je pred miestom objavenia chyby navyše. Prekladač
očakával koniec unitu a teda end s bodkou, nie s bodkočiarkou.

RIEŠENIE

Zistíme, ktoré end je navyše a odstránime ho. V našom prípade ide o end
na konci procedúry Button1Click.

Upravený zdrojový kód

--------------------------------------------------------------------------------

procedure TForm1.Button1Click(Sender: TObject);
var n: integer;
begin
n:= StrToInt(Edit1.Text);
if n mod 2 = 0 then begin
Label1.Caption:= 'Parne cislo'
end
else begin
Label1.Caption:= 'Neparne cislo'
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Label1.Caption:= 'Pocet cislic: ' + IntToStr(length(Edit1.Text));
end;

procedure TForm1.Button3Click(Sender: TObject);
var n, pocet: integer;
begin
n:= StrToInt(Edit1.Text);
pocet:= 0;
while n>0 do begin
if (n mod 10) mod 10 = 1 then inc(pocet);
n:= n div 10;
end;
Label1.Caption:= 'Pocet jednotiek v cisle: ' + IntToStr(pocet);
end;

--------------------------------------------------------------------------------

}

end.


Stiahnuť vzorový príklad (zdrojové kódy v Delphi)