Error while compiling on delphi: expected BEGIN but received UNIT

0

I try to compile and this error appears: expected BEGIN but received UNIT at line 9 follow the code.

Unit Unit1; 
interface
uses
Windows, Messages, SysUtils,
Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,
 ExtCtrls, ComCtrls, Spin;
const 
Caracteres : String = #0+#1+#13+#10+" " +'!@#$1,,£éÉËëÇçá 
ÁÀàéÉèãÃõõÏIyÿDO(D-' +I'}{":?x,./;[]\_-';
type TForml = class(TForm)
Buttonl: TButton;
Button2: TButton;
Panell: TPanel;
Pane12: TPanel;
ListBoxl: TListBox;
btnDel: TButton;
btnAdd: TButton;
Pane13: TPanel;
Pane14: TPanel;
Button3: TButton;
Button4: TButton;
ListBox2: TListBox;
Labell: TLabel;
Labe13: TLabel;
Pane15: TPanel;
Pane16: TPanel;
Labe14: TLabel;
LabelDir: TLabel;
Labe12: TLabel;
LabelArq: TLabel;
SpinEditl: TSpinEdit;
Label5: TLabel;
LabelFim: TLabel;
CheckBoxl: TCheckBox;
Labe16: TLabel;
SpinEdit2: TSpinEdit;
Beve12: TBevel;
CheckBox2: TCheckBox;
Pane17: TPanel;
Animatel: TAnimate;
Labe17: TLabel;
LabelTotal: TLabel;
Timerl: TTimer;
procedure ButtonlClick(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure btnAddClick(Sender: TObject);
procedure btnDelClick(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure TimerlTimer(Sender: TObject);
private ContinuaLista : Boolean;
contpalavra : Integer; Erros, ArquivoSaida : TStringList;
Extensao : String;
{ Private declarations } public
{ Public declarations } 
end;
var Forml: TForml;
implementation {$R *.DFM} procedure
TForml.ButtonlClick(Sender: TObject);
procedure ListaDir(Diretorio: String);
procedure VarreArquivo(Arquivo: String);
procedure VarreLinha(Linha: String);
procedure AdicionaPalavra(Palavra: String);
function RemoveCaracter(Palavra: String): String;
var Texto: String;
Caracter: Char;
n: Integer;
begin Texto := Palavra;

for n := 0 to length(Caracteres)-1 do begin caracter := Caracteres[n];

while Pos(Caracter, Texto) > 0 do delete(Texto, Pos(Caracter, Texto), 1);

end;
Result := Texto; 
end;
var N : Integer; bNovo : Boolean; Saida: String;
begin
bNovo := True;
if CheckBoxl.Checked then Saida := lowercase(Palavra)
else Saida := Palavra;
if (Saida = ") then exit;
// Apagando caracteres indesejaveis
if not CheckBox2.Checked then Saida := trim(R emoveCaracter(Saida));
if (Saida = ") or (length(Saida) <= SpinEdit2. Value) then exit;
for n := 0 to ArquivoSaida.Count-1 do if (ArquivoSaida.Strings[n] = Saida)
then begin bNovo := False;
break;
end;
if bNovo then begin ArquivoSaida.Add(Saida);
contpalavra := contpalavra+l;
end;
end;
var Palavra, sTemp : String; nTemp : Integer;
begin sTemp := Linha;
while (sTemp <> ") do begin if Extensao = 'INI' then begin nTemp pos ('=', 
sTemp) ;
if (nTemp = 0) then begin Application.ProcessMessages;
palavra := sTemp; sTemp ";
end else begin Palavra := trim(copy(sTemp, 0, nTemp-l));
delete(sTemp,l,nTemp);
end;
end +

'else begin nTemp pos('  sTemp) ; if (nTemp = 0) then begin 
Application.ProcessMessages; palavra := sTemp; sTemp end else begin Palavra 
:= trim(copy(sTemp, 0, nTemp)); delete(sTemp,l,nTemp); end; end; if 
(length(Palavra) <= SpinEditl.Value) then AdicionaPalavra(Palavra); end; 
end; 
var fArquivo: textfile; Linha: String;
begin try AssignFile(fArquivo, Arquivo);
Reset(fArquivo); while not Eof(fArquivo)
do begin Readln(fArquivo, Linha);
Application.ProcessMessages;
if (Linha <> ") then VarreLinha(Linha);
end;
CloseFile(fArquivo);
except on E : Exception do Erros.Add(Arquivo+' '+E.Message+' +E.ClassName);
 end; 
end;
var SR: TSearchRec;
Arquivo, sTemp: String; nTemp, N : Integer;
begin FindFirst(Diretorio+'\.', faAnyFile, SR); while not (Arquivo = 
SR.Name)
and ContinuaLista do begin if (SR.Attr = faDirectory)
or (SR.Attr = faDirectory+faHidden) or (SR.Attr = faDirectory+faSysFile)
or (SR.Attr = faDirectory+faSysFile+faHidden) then begin if (SR.Name <> '.')
 and (SR.Name <> '..') and ContinuaLista then begin
// Faz Recursividade em Diretórios
if ( (Sr.Name <> '.') and (Sr.Name <> then
try sTemp := concat(Diretorio,'\',Sr.Name);
LabelDir.Caption := sTemp;
ListaDir(sTemp);

except 
end;
Application.ProcessMessages;
end;
end
else begin // Pega os Arquivos

sTemp := concat(Diretorio,'\',Sr.Name);


LabelArq.Caption sTemp;
LabelDir.Caption Diretorio;
nTemp := Length(sTemp);

Extensao uppercase(copy(sTemp, nTemp-2,nTemp));
for n:= 0 to ListBox2.Items.Count -1 do if Extensao = 
ListBox2.Items.Strings[n]
then VarreArquivo(sTemp);
end;
Arquivo:= SR.Name;
FindNext(SR);
end;
end;
var n : Integer; begin contpalavra := 0; ArquivoSaida
:= TStringList.Create;
Erros := TStringList.Create;
Animatel.Active := True;
ContinuaLista := True;
for n := 0 to ListBoxl.Items.Count-1 do begin
ListaDir(ListBoxl.Items.Strings[n]);
end;
ArquivoSaida.SaveToFile
(ExtractFilePath(Application. ExeName)+'passwords.txt');
 Erros.SaveToFile(ExtractFilePath(Application. ExeName)+'Erros.txt');
Animatel.Active := False;
ArquivoSaida.Destroy;
Erros.Destroy;
LabelFim.Caption
end;
procedure TForml.Button2Click(Sender: TObject);

begin LabelFim.Caption 'Finalizando...';

Animatel.Active := False;
ContinuaLista := False;

end;

procedure TForml.btnAddClick(Sender: TObject);
var Caminho : String;

begin if InputQuery
 ('Insira um caminho','Caminho ex: C:, C:\ WINDOWS',Caminho) then

ListBoxl.Items.Add(Uppercase(Caminho));
end;

procedure TForml.btnDelClick(Sender: TObject);
begin
if (ListBoxl.Itemindex <> -1) then ListBoxl.Items. 
Delete(ListBoxl.Itemindex);
end;
procedure TForml.Button4Click(Sender: TObject);
var Caminho : String;
begin if InputQuery
('Insira um caminho','Caminho ex: C:\',Caminho) then 
ListBox2.Items.Add(Uppercase
(Caminho));
end;
end;
procedure TForml.Button3Click(Sender: TObject);
begin if (ListBox2.Itemindex <> -1) then ListBox2.Items. 
Delete(ListBox2.Itemindex);
end;
procedure TForml.TimerlTimer(Sender: TObject);
begin LabelTotal.Caption := inttostr(contpalavra);
end;
end.

I do not understand anything about delphi I tried to do the same in c ++ but it did not go as expected

    
asked by anonymous 05.10.2018 / 03:05

1 answer

2

First, in Delphi, all string is written as follows:

const Caracteres = 'seu conteudo aqui';

Note that it starts / ends with single quotation marks, if it is to concatenate, one should use the + operator, and each new set should also have single quotes, so this statement is incorrect:

const Caracteres : String = #0+#1+#13+#10+" " +'!@#$1,,£éÉËëÇçá ÁÀàéÉèãÃõõÏIyÿDO(D-' +I'}{":?x,./;[]\_-';

After the implementation comes the body of the procedures, which must have a begin and a end; that is absent, in case the IDE is doing until miracle presenting error.

The error in line 9 is the operator's failure to concatenate the string À é é É è Ï DO DO DO DO DO (((((((D D D D D D D D D D D D D D D < with the top line.

Notice how one of the functions that exists inside there is after adding a begin / end:

function RemoveCaracter(Palavra: String): String;
  var
    Texto: String;
    Caracter: Char;
    n: Integer;
  begin
    Texto := Palavra;

    for n := 0 to length(Caracteres) - 1 do
    begin
      Caracter := Caracteres[n];

      while Pos(Caracter, Texto) > 0 do
        delete(Texto, Pos(Caracter, Texto), 1);

    end;
    Result := Texto;
  end;

From line 174 above the code has very serious problems of construction that implies in the restoration. Already from line 174 onwards the code has only one error which is a end; that is lost on line 204.

Therefore, you should reformat all code by adding a begin / end to all procedures; then press CTRL + D as the IDE will help you rebuild;

Example of your quasi-functional code:

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs;

type
  TForm1 = class(TForm)
    Buttonl: TButton;
    Button2: TButton;
    Panell: TPanel;
    Pane12: TPanel;
    ListBoxl: TListBox;
    btnDel: TButton;
    btnAdd: TButton;
    Pane13: TPanel;
    Pane14: TPanel;
    Button3: TButton;
    Button4: TButton;
    ListBox2: TListBox;
    Labell: TLabel;
    Labe13: TLabel;
    Pane15: TPanel;
    Pane16: TPanel;
    Labe14: TLabel;
    LabelDir: TLabel;
    Labe12: TLabel;
    LabelArq: TLabel;
    SpinEditl: TSpinEdit;
    Label5: TLabel;
    LabelFim: TLabel;
    CheckBoxl: TCheckBox;
    Labe16: TLabel;
    SpinEdit2: TSpinEdit;
    Beve12: TBevel;
    CheckBox2: TCheckBox;
    Pane17: TPanel;
    Animatel: TAnimate;
    Labe17: TLabel;
    LabelTotal: TLabel;
    Timerl: TTimer;
    procedure ButtonlClick(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure btnAddClick(Sender: TObject);
    procedure btnDelClick(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure TimerlTimer(Sender: TObject);
  private
    ContinuaLista: Boolean;
    contpalavra: Integer;
    Erros, ArquivoSaida: TStringList;
    Extensao: String;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

const
  Caracteres: String = #0 + #1 + #13 + #10 + '" "!@#$1,,£éÉËëÇçáÁÀàéÉèãÃõõÏIyÿDO(D- +I}{":?x,./;[]\_-';

implementation

{$R *.dfm}

procedure TForml.Button2Click(Sender: TObject);
begin
  LabelFim.Caption 'Finalizando...';
  Animatel.Active := False;
  ContinuaLista := False;
end;

procedure TForml.btnAddClick(Sender: TObject);
var
  Caminho: String;
begin
  if InputQuery('Insira um caminho', 'Caminho ex: C:, C:\ WINDOWS', Caminho) then
    ListBoxl.Items.Add(Uppercase(Caminho));
end;

procedure TForml.btnDelClick(Sender: TObject);
begin
  if (ListBoxl.Itemindex <> -1) then
    ListBoxl.Items.Delete(ListBoxl.Itemindex);
end;

procedure TForml.Button4Click(Sender: TObject);
var
  Caminho: String;
begin
  if InputQuery('Insira um caminho', 'Caminho ex: C:\', Caminho) then
    ListBox2.Items.Add(Uppercase(Caminho));
end;

procedure TForml.Button3Click(Sender: TObject);
begin
  if (ListBox2.Itemindex <> -1) then
    ListBox2.Items.Delete(ListBox2.Itemindex);
end;

procedure TForml.TimerlTimer(Sender: TObject);
begin
  LabelTotal.Caption := inttostr(contpalavra);
end;

end.
    
05.10.2018 / 22:09