Delphi ошибка e2029

I don’t see any syntax error, my code compiles clean without the finalization section. Here is the last few lines of the unit.

function boolAsTF(b:boolean): string; inline;
begin
  if b then result := 'T' else result := 'F';
end;

finalization
  SyncMgr.Free;
end.

Stefan Glienke's user avatar

asked Jan 11, 2018 at 15:43

Gary Walker's user avatar

9

If you use a finalization section, you must also use an initialization section.

I accidentally hit this again, and remember this being hard to figure out the first time. So I thought I would document it here to help the next guy.

Kudos to MartynA who answered in a comment about as fast I I did when I knew I was going to answer it immediately.

answered Jan 11, 2018 at 15:44

Gary Walker's user avatar

Gary WalkerGary Walker

8,7713 gold badges18 silver badges41 bronze badges

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
procedure min1;//              òóò îøèáêà
const n=10;
var
b,c,d,m,i,min:integer;
a: array [1..n] of integer;
dat,res:textFile;
begin
for i := b to c do
if a[i]<d then
begin
min:=a[i]
end;
writeln(res,min);
end;
 
procedure min2;
const n=10;
var
b,c,d,m,i,min:integer;
a: array [1..n] of integer;
dat,res:textFile;
begin
for I := 2 to c do
if a[i]<d then
begin
d:=a[i];
end;
writeln(res,min);
end;
 
procedure TForm1.Button1Click(Sender: TObject);
const n=10;
var
b,c,d,m,i,min:integer;
a: array [1..n] of integer;
dat,res:textFile;
begin
assignfile(dat,'dat.txt');
assignfile(res,'res.txt');
readln(dat,m);//êîëè÷åñòâî ýëåìåíòîâ â ìàññèâå
c:=0;
b:=0;
for i := 1 to m do
begin
readln(dat,a[i]);
if b=0 then
begin
if a[i] mod 5 =0 then
begin
b:=i;//ïåðâîå ÷èñëî êðàòíîå ïÿòè
end;
//end;
if a[i]>0 then
begin
c:=i;//ïîñëåäíåå ïîëîæèòåëüíîå ÷èñëî
end;
//end;
d:=a[b];
end;
if c=0 then//íè îäíîãî ïîëîæèòåëüíîãî
begin
writeln(res,'v massive net pologitelnbIx 4isel');
Halt;
end;
//end;
if b>c then
begin
writeln(res,'v massive est pologitelnbIe 4isla,no oni naxod9ts9 polse 4isla kratnogo p9ti');
Halt;
end;
if b<=c then
begin
min1;
end;
if b=0 then
begin
min2;
end;
closefile(dat);
closefile(res);
end;
end;

10-150 Okolokompa Форум

(@dom)

Honorable Member

Присоединился: 4 года назад

Записи: 200

Создатель темы 13/03/2020 1:39 пп  

Я новичок. В моей программе возникли такие ошибки:

[dcc32 Error] Project2.dpr(36): E2029 ‘;’ expected but ‘.’ found

[dcc32 Error] Project2.dpr(38): E2029 Declaration expected but end of file found

Вот программа, которую я написал:

program masquerader; //program name

Var //Declaring variables

Salary:integer; //Declared Salary as integer

procedure Sleep(milliseconds: Cardinal); stdcall;//Added sleep as a procedure for delay

Begin //Begins the program

Writeln('Enter Your Salary please user...'); //Outputs line Enter Your salary please user...
Readln(Salary); //Recieves the value and declares the integer value to salary
Writeln('Processing your input...'); //Outputs line to Let the user know its being processed
Sleep(4000); //4 second delay
Writeln('Done!');
If (Salary>=5000) AND (Salary<=8000) Then //Conditions are being test for the requirements for each section
Writeln('Thanks for your Input file should be ready in a second'); // Outputs this line to let the user know it is ready in a second
Writeln('Congratulations!,You are eligible to play in poison'); //Outputs the section that matches the user's salary(5000-8000)
If (Salary>=3000) AND (Salary<=5000) Then //Conditions are being test for the requirements for each section
Writeln('Thanks for your Input file should be ready in a second'); // Outputs this line to let the user know it is ready in a second
Writeln('Congratulations!,You are eligible to play in Blue devils');//Outputs the section that matches the user's salary(3000-5000)
If (Salary<3000) Then //Conditions are being test for the requirements for each section
Writeln('Thanks for your Input file should be ready in a second'); // Outputs this line to let the user know it is ready in a second
Writeln('Congratulations!,You are eligible to play in The poor man section');//Outputs the section that matches the user's salary(x<=3000)
Writeln('Written by Timothy Adams');
Writeln('Fatima College 4-1');
Readln; //Declares the end of the read line

End. //End of program

ОТВЕТ:

Есть ряд проблем с вашим кодом.

Вы объявляете новую функцию Sleep(), не сообщая компилятору, где находится ее реализация. Таким образом, компилятор думает весь ваш код между begin и end является реализацией. Вот почему вы получаете ошибки, потому что вы завершаете реализацию функции end. вместо end;

Кроме того, блоки кода Delphi не определяются отступом, как вы предполагаете. Вам нужно использовать явные begin/ end операторы для группировки операторов вместе.

Попробуйте этот код:

program masquerader; //program name

uses
Windows;

Var //Declaring variables
Salary:integer; //Declared Salary as integer

//procedure Sleep(milliseconds: Cardinal); stdcall; external 'kernel32.dll'; //Added sleep as a procedure for delay

Begin //Begins the program

Writeln('Enter Your Salary please user...'); //Outputs line Enter Your salary please user...
Readln(Salary); //Recieves the value and declares the integer value to salary Writeln('Processing your input...'); //Outputs line to Let the user know its being processed
Sleep(4000); //4 second delay
Writeln('Done!');

If (Salary>=5000) AND (Salary<=8000) Then //Conditions are being test for the requirements for each section
Begin
Writeln('Thanks for your Input file should be ready in a second'); // Outputs this line to let the user know it is ready in a second
Writeln('Congratulations!,You are eligible to play in poison'); //Outputs the section that matches the user's salary(5000-8000)
End;

If (Salary>=3000) AND (Salary<=5000) Then //Conditions are being test for the requirements for each section
Begin
Writeln('Thanks for your Input file should be ready in a second'); // Outputs this line to let the user know it is ready in a second
Writeln('Congratulations!,You are eligible to play in Blue devils');//Outputs the section that matches the user's salary(3000-5000)
End;

If (Salary<3000) Then //Conditions are being test for the requirements for each section
Begin
Writeln('Thanks for your Input file should be ready in a second'); // Outputs this line to let the user know it is ready in a second
Writeln('Congratulations!,You are eligible to play in The poor man section');//Outputs the section that matches the user's salary(x<=3000)
End;

Writeln('Written by Timothy Adams');
Writeln('Fatima College 4-1');
Readln; //Declares the end of the read line

End. //End of program

Кстати, ваш код не обрабатывает Salary выше 8000.

procedure eraseSubstr(const pos:vector; var text:string; const pattern:string);
var
  len, iter, end_, endPos:Integer;
  t:string;
begin
  t:=text;

  len:=Length(pattern);
  if (Length(pos) < 2) then
  begin
    Delete(t, pos[0], length);
  end;

end;

Ошибка возникает на функции Delete.

Ошибка — [dcc32 Error] Functions.pas(58): E2029 '(' expected but ')' found
Может, кто-то с подобным сталкивался? Прошу помочь.

Привет, ребята, у меня возникла ошибка, от которой я не могу избавиться ..

Я добавил две пользовательские процедуры в свой код delphi и прочитал, что вы можете нажать crtl+shift+c, чтобы автоматически сгенерировать функции, что я и сделал.

Однако сейчас моя проблема в том, что мне не нужны были автоматически сгенерированные файлы, поэтому я удалил их после выполнения команды. Теперь мой код больше не работает из-за этой ошибки, которую я получаю:

E2029 Ожидается объявление, но найден конец файла

Ожидается ИНИЦИАЛИЗАЦИЯ, но получен конец файла в строке 520 (520: 1)

Как я могу исправить свой код? Удаление или добавление «конца» в конце файла мне не помогает. Есть ли способ узнать, где что-то не хватает в моем коде? (Я мог бы опубликовать свой код delphi, но его длина в 500 строк, я не думаю, что это имеет смысл.

Код обновления:

unit Benutzerverwaltung_U;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.ComCtrls,
  Vcl.StdCtrls,
  Vcl.WinXCtrls, Vcl.CheckLst, System.Actions, Vcl.ActnList, Vcl.Menus,
  System.StrUtils,
  Data.DB, Vcl.Grids, Vcl.DBGrids, Vcl.DBCtrls, FireDAC.Stan.Intf,
  FireDAC.Stan.Option, FireDAC.Stan.Param, FireDAC.Stan.Error, FireDAC.DatS,
  FireDAC.Phys.Intf, FireDAC.DApt.Intf, FireDAC.Comp.DataSet,
  FireDAC.Comp.Client;

type
  TForm1 = class(TForm)

другие кнопки и тд …

    procedure SwapValues(var Zahl1, Zahl2: Integer); //new
    procedure SelectionSort(Sender: TObject);  // new
    procedure Button11Click(Sender: TObject); //new

  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }

    workerModel: record
      VorName: string[40];
      NachName: string[40];
      Age: Integer;
      Schließen: string[30];
      Admin: TToggleSwitchState;
      DatenSehen: TToggleSwitchState;
      Gender: string[20];

    end;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses Sonderrechte_U, CheckedItem_U, Unit1, BenutzerEdit_u;


procedure TForm1.SwapValues(var Zahl1, Zahl2: Integer);
var
  h: Integer;
begin
  h := Zahl1;
  Zahl1 := Zahl2;
  Zahl2 := h;
end;

procedure TForm1.SelectionSort(Sender: TObject);
var
  i, j, min: Integer;
var
  sortArray, Data: Array of string;

begin

  for i := 1 to Form1.ListBox1.Items.Count - 1 do
  // i muss wahrscheinlich 0 sein?
  begin
    min := i;
    for j := i + 1 to Form1.ListBox1.Items.Count do
      if (Data[j] < Data[min]) then
        min := j;
    SwapValues(i, min);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Form2 := TForm2.Create(Self);
  try
    Form2.ShowModal;
  finally
    Form2.Free;
  end;

end;

// больше кода

procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
var
  l: Integer;
  t: String;
begin
  with ListBox1 do
  begin
    Canvas.FillRect(Rect);
    t := Items[Index];
    l := Rect.Right - Canvas.TextWidth(t) - 1;
    Canvas.TextOut(l, Rect.Top, t);
  end;
end;

procedure TForm1.SearchBox1Change(Sender: TObject);

var
  i: Integer;

begin
  // SearchBox1.Parent := ListBox1;

  ListBox1.Items.BeginUpdate;

  try
    for i := 0 to ListBox1.Items.Count - 1 do
      ListBox1.Selected[i] := ContainsText(ListBox1.Items[i], SearchBox1.Text);

  finally
    ListBox1.Items.EndUpdate;


end;
// end;


// this is the end of the file

Понравилась статья? Поделить с друзьями:
  • Delphi вывести сообщение об ошибке
  • Delphi shellexecute коды ошибок
  • Delphi privileged instruction ошибка
  • Delphi idftp обработка ошибок
  • Delphi getlasterror текст ошибки