Error compiling in Delphi: expected BEGIN but Received UNIT

Asked

Viewed 142 times

0

I try to compile and this error appears: expected BEGIN but Received UNIT at line 9 follows 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 don’t understand anything of Delphi I tried to do the same in c++ but it didn’t turn out as expected

  • This Unit is very complicated, I can see that can give error right in the constant statement if it is exactly as you pasted... to correct this line, change to Caracteres : String = #0+#1+#13+#10+' ' +'!@#$1,,£éÉËëÇçáÁÀàéÉèãÃõõÏIyÿDO(D-' +'I}{":?x,./;[]\_-'; ...

1 answer

2


First, at Delphi, all string to be written as follows:

const Caracteres = 'seu conteudo aqui';

Note that starts/ends with single quotes, if concatenating, the operator must be used + each new set also with simple 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 procedures, which must possess a beginand a end; that is absent , in case the IDE is doing even miracle presenting you error.

The error on line 9 is the missing operator to concatenate the string Áààéèãõõïiyã¿DO(D-' +I'}{":? x,./;[]_-'; with the top line.

Note how one of the functions inside 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 construction problems that implies 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 to all procedures a Begin/end; then press CTRL+D that the IDE will help you rebuild;

Example of its nearly 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.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.