Ajuda com editor de texto básico- Delphi xe8

31/03/2016

3

Olá, Estou seguindo um tutorial do help do delphi xe8 para criar um editor de texto básico e está dando uns erros.

Ei-lo:



[codeunit TextEditorUnit;

interface

uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.ScrollBox,
FMX.Memo, FMX.Controls.Presentation, FMX.StdCtrls, FMX.Menus, System.Actions,
FMX.ActnList;

type
TTexEditorForm = class(TForm)
ActionList1: TActionList;
StatusBar: TStatusBar;
Memo1: TMemo;
OpenFileDialog: TOpenDialog;
SaveFileDialog: TSaveDialog;
NewAction: TAction;
OpenAcition: TAction;
SaveAction: TAction;
SaveAsAcition: TAction;
ExitAction: TAction;
CutAction: TAction;
CopyAction: TAction;
PasteAction: TAction;
SelectAllAction: TAction;
UndoAction: TAction;
DeleteAction: TAction;
WordWrapAction: TAction;
Action1: TAction;
Action2: TAction;
Action3: TAction;
Action4: TAction;
Action5: TAction;
Action6: TAction;
Action7: TAction;
MainMenu1: TMainMenu;
FileMenu: TMenuItem;
EditMenu: TMenuItem;
FormatMenu: TMenuItem;
New: TMenuItem;
OpenMenu: TMenuItem;
Save: TMenuItem;
SaveAs: TMenuItem;
Exit: TMenuItem;
Cut: TMenuItem;
Copy: TMenuItem;
Paste: TMenuItem;
SelectAll: TMenuItem;
Undo: TMenuItem;
Delete: TMenuItem;
WordWrap: TMenuItem;
Action8: TAction;
Action9: TAction;
Action10: TAction;
Action11: TAction;
Action12: TAction;
Action13: TAction;
Action14: TAction;
Action15: TAction;
Action16: TAction;
Action17: TAction;
Action18: TAction;
Action19: TAction;
Action20: TAction;
Label3: TLabel;
Label1: TLabel;
Label2: TLabel;
Label4: TLabel;
procedure Memo1Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Memo1KeyUp(Sender: TObject; var Key: Word; var KeyChar: Char;
Shift: TShiftState);
procedure Memo1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Single);
procedure NewActionExecute(Sender: TObject);
procedure OpenAcitionExecute(Sender: TObject);
procedure SaveActionExecute(Sender: TObject);
procedure SaveAsAcitionExecute(Sender: TObject);
procedure ExitActionExecute(Sender: TObject);
procedure CutActionExecute(Sender: TObject);
procedure CopyActionExecute(Sender: TObject);
procedure PasteActionExecute(Sender: TObject);
procedure SelectAllActionExecute(Sender: TObject);
procedure UndoActionExecute(Sender: TObject);
procedure DeleteActionExecute(Sender: TObject);
procedure WordWrapActionExecute(Sender: TObject);
private
{ Private declarations }
CurrentFile: String;
procedure UpdateStatusbar;
public
{ Public declarations }
end;

var
TexEditorForm: TTexEditorForm;

implementation

{$R *.fmx}
{$R *.Windows.fmx MSWINDOWS}



procedure TTexEditorForm.CopyActionExecute(Sender: TObject);
begin
Memo1.CutToClipboard;

end;

procedure TTexEditorForm.CutActionExecute(Sender: TObject);
begin
Memo1.CutToClipboard;
UpdateStatusBar;
end;

procedure TTexEditorForm.DeleteActionExecute(Sender: TObject);

begin
if Memo1.SelLength > 0 then
Memo1.DeleteSelection
else




Memo1.DeleteFrom(Memo1.CaretPosition, 1, [TDeleteOption.MoveCaret]); <-- AQUI, TÁ DANDO O SEGUINTE ERRO DE COMPILAÇÃO:




[dcc32 Error] TextEditorUnit.pas(124): E2003 Undeclared identifier: 'TDeleteOption'.




UpdateStatusBar;

end;

procedure TTexEditorForm.ExitActionExecute(Sender: TObject);
begin
Application.Terminate;
end;

procedure TTexEditorForm.FormCreate(Sender: TObject);
begin
Memo1.Lines.Add('');
UpdateStatusBar;

end;


procedure TTexEditorForm.Memo1KeyUp(Sender: TObject; var Key: Word;
var KeyChar: Char; Shift: TShiftState);
begin
UpdateStatusBar;
end;

procedure TTexEditorForm.Memo1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Single);
begin
UpdateStatusBar;
end;

procedure TTexEditorForm.NewActionExecute(Sender: TObject);
Var
UserResponse: Integer;

begin

if not Memo1.Text.IsEmpty then
begin
UserResponse := MessageDlg(
'This will clear the current document. Do you want to continue?',
TMsgDlgType.mtInformation, mbYesNo, 0);
if UserResponse = mrYes then
begin
Memo1.Text := '';
Memo1.Lines.Add(''); // Initialize the memo line count to "1".
UpdateStatusBar;
CurrentFile := ''; // New files have no file name until saved.
end;
end;


end;

procedure TTexEditorForm.OpenAcitionExecute(Sender: TObject);

var
FileName: String;

begin
if OpenFileDialog.Execute = True then
begin
FileName := OpenFileDialog.FileName;
if FileExists(FileName) then
begin
Memo1.Lines.LoadFromFile(FileName);
CurrentFile := FileName;
Caption := 'Text Editor - ' + ExtractFileName(FileName);
end;
end;

end;

procedure TTexEditorForm.PasteActionExecute(Sender: TObject);
begin
Memo1.PasteFromClipboard;
UpdateStatusBar;
end;

procedure TTexEditorForm.SaveActionExecute(Sender: TObject);

begin
if CurrentFile = '' then
SaveAction.Execute()
else
Memo1.Lines.SaveToFile(CurrentFile);


end;

procedure TTexEditorForm.SaveAsAcitionExecute(Sender: TObject);
Var
FileName: String;
UserResponse: TmodalResult;

begin
begin
if SaveFileDialog.Execute = True then
begin
FileName := SaveFileDialog.FileName;
if FileExists(FileName) then
begin
UserResponse := MessageDlg(
'File already exists. Do you want to overwrite?',
TMsgDlgType.mtInformation, mbYesNo, 0);
if UserResponse = mrNo then

Exit; <----- E AQUI, MESMO NO EDITOR DE CÓDIGOS, ESTÁ APARECENDO UMA SETA COLORIDA CURVADA PRA BAIXO. COPIEI E COLEI. TÁ DANDO O SEGUINTE ERRO DE COMPILAÇÃO:


[dcc32 Error] TextEditorUnit.pas(230): E2014 Statement expected, but expression of type 'TMenuItem' found.



end;
Memo1.Lines.SaveToFile(FileName);
CurrentFile := FileName;
Caption := 'Text Editor - ' + ExtractFileName(FileName);
end;
end;

end;

procedure TTexEditorForm.SelectAllActionExecute(Sender: TObject);
begin
Memo1.SelectAll;
UpdateStatusBar;

end;

procedure TTexEditorForm.UndoActionExecute(Sender: TObject);
begin
Memo1.UnDo;
UpdateStatusBar;
end;

procedure TTexEditorForm.UpdateStatusbar;
begin
Label1.Text := 'L:' + (Memo1.CaretPosition.Line + 1).ToString;
Label2.Text := 'C:' + (Memo1.CaretPosition.Pos + 1). ToString;
Label3.Text := 'Lines:' + Memo1.lines.Count.ToString;
end;

procedure TTexEditorForm.WordWrapActionExecute(Sender: TObject);
begin
Memo1.WordWrap := not Memo1.WordWrap;
WordWrapAction.Checked := Memo1.WordWrap;
UpdateStatusBar;

end;

end.][/code]

Detalhe: No tutorial, o Memo tá com o nome de "Editor", mas o Delphi não está deixando mudar, então, onde estava aparecendo "Editor", no tutorial, estou colocando "Memo1".

Se alguém puder dar uma ajuda agradeço.

Valew!
Responder

Posts

31/03/2016

Rafael Bosco

Ok, mas que erro ocorre? e em que momento?
Responder

31/03/2016

P2

Memo1.DeleteFrom(Memo1.CaretPosition, 1, [TDeleteOption.MoveCaret]); <-- AQUI, TÁ DANDO O SEGUINTE ERRO DE COMPILAÇÃO:




[dcc32 Error] TextEditorUnit.pas(124): E2003 Undeclared identifier: 'TDeleteOption'.
Responder
Adicione FMX.Memo.Types na uses do form:

Link do help:
http://docwiki.embarcadero.com/Libraries/XE8/en/FMX.Memo.Types.TDeleteOption
Responder
Adicione FMX.Memo.Types na uses do form:

Link do help:
http://docwiki.embarcadero.com/Libraries/XE8/en/FMX.Memo.Types.TDeleteOption



Olá amigo; Olá amigos. Realmente colocando o FMX... resolveu alguns erros, mas continua sem querer executar.

Eis os códigos e erros de compilação:


unit TextEditorUnit;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.ScrollBox,
  FMX.Memo, FMX.Controls.Presentation, FMX.StdCtrls, FMX.Menus, System.Actions,
  FMX.ActnList, FMX.Memo.Types;

type
  TTexEditorForm = class(TForm)
    ActionList1: TActionList;
    StatusBar: TStatusBar;
    Memo1: TMemo;
    OpenFileDialog: TOpenDialog;
    SaveFileDialog: TSaveDialog;
    NewAction: TAction;
    OpenAcition: TAction;
    SaveAction: TAction;
    SaveAsAcition: TAction;
    ExitAction: TAction;
    CutAction: TAction;
    CopyAction: TAction;
    PasteAction: TAction;
    SelectAllAction: TAction;
    UndoAction: TAction;
    DeleteAction: TAction;
    WordWrapAction: TAction;
    Action1: TAction;
    Action2: TAction;
    Action3: TAction;
    Action4: TAction;
    Action5: TAction;
    Action6: TAction;
    Action7: TAction;
    MainMenu1: TMainMenu;
    FileMenu: TMenuItem;
    EditMenu: TMenuItem;
    FormatMenu: TMenuItem;
    New: TMenuItem;
    OpenMenu: TMenuItem;
    Save: TMenuItem;
    SaveAs: TMenuItem;
    Exit: TMenuItem;
    Cut: TMenuItem;
    Copy: TMenuItem;
    Paste: TMenuItem;
    SelectAll: TMenuItem;
    Undo: TMenuItem;
    Delete: TMenuItem;
    WordWrap: TMenuItem;
    Action8: TAction;
    Action9: TAction;
    Action10: TAction;
    Action11: TAction;
    Action12: TAction;
    Action13: TAction;
    Action14: TAction;
    Action15: TAction;
    Action16: TAction;
    Action17: TAction;
    Action18: TAction;
    Action19: TAction;
    Action20: TAction;
    Label3: TLabel;
    Label1: TLabel;
    Label2: TLabel;
    Label4: TLabel;
    procedure Memo1Change(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Memo1KeyUp(Sender: TObject; var Key: Word; var KeyChar: Char;
      Shift: TShiftState);
    procedure Memo1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Single);
    procedure NewActionExecute(Sender: TObject);
    procedure OpenAcitionExecute(Sender: TObject);
    procedure SaveActionExecute(Sender: TObject);
    procedure SaveAsAcitionExecute(Sender: TObject);
    procedure ExitActionExecute(Sender: TObject);
    procedure CutActionExecute(Sender: TObject);
    procedure CopyActionExecute(Sender: TObject);
    procedure PasteActionExecute(Sender: TObject);
    procedure SelectAllActionExecute(Sender: TObject);
    procedure UndoActionExecute(Sender: TObject);
    procedure DeleteActionExecute(Sender: TObject);
    procedure WordWrapActionExecute(Sender: TObject);
  private
    { Private declarations }
    CurrentFile: String;
    procedure UpdateStatusbar;
  public
    { Public declarations }
  end;

var
  TexEditorForm: TTexEditorForm;

implementation

{$R *.fmx}
{$R *.Windows.fmx MSWINDOWS}



procedure TTexEditorForm.CopyActionExecute(Sender: TObject);
begin
  Memo1.CutToClipboard;

end;

procedure TTexEditorForm.CutActionExecute(Sender: TObject);
begin
  Memo1.CutToClipboard;
  UpdateStatusBar;
end;

procedure TTexEditorForm.DeleteActionExecute(Sender: TObject);

begin
  if Memo1.SelLength > 0 then
    Memo1.DeleteSelection
  else
    Memo1.DeleteFrom(Memo1.CaretPosition, 1, [TDeleteOption.MoveCaret]);
  UpdateStatusBar;

end;

procedure TTexEditorForm.ExitActionExecute(Sender: TObject);
begin
  Application.Terminate;
end;

procedure TTexEditorForm.FormCreate(Sender: TObject);
begin
   Memo1.Lines.Add('');
  UpdateStatusBar;

end;


procedure TTexEditorForm.Memo1KeyUp(Sender: TObject; var Key: Word;
  var KeyChar: Char; Shift: TShiftState);
begin
  UpdateStatusBar;
end;

procedure TTexEditorForm.Memo1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Single);
begin
  UpdateStatusBar;
end;

procedure TTexEditorForm.NewActionExecute(Sender: TObject);
Var
UserResponse: Integer;

begin

    if not Memo1.Text.IsEmpty then
  begin
    UserResponse := MessageDlg(
      'This will clear the current document. Do you want to continue?',
      TMsgDlgType.mtInformation, mbYesNo, 0);
    if UserResponse = mrYes then
    begin
      Memo1.Text := '';
      Memo1.Lines.Add(''); // Initialize the memo line count to "1".
      UpdateStatusBar;
      CurrentFile := ''; // New files have no file name until saved.
    end;
  end;


end;

procedure TTexEditorForm.OpenAcitionExecute(Sender: TObject);

var
  FileName: String;

begin
    if OpenFileDialog.Execute = True then
  begin
    FileName := OpenFileDialog.FileName;
    if FileExists(FileName) then
    begin
      Memo1.Lines.LoadFromFile(FileName);
      CurrentFile := FileName;
      Caption := 'Text Editor - ' + ExtractFileName(FileName);
    end;
  end;

end;

procedure TTexEditorForm.PasteActionExecute(Sender: TObject);
begin
     Memo1.PasteFromClipboard;
  UpdateStatusBar;
end;

procedure TTexEditorForm.SaveActionExecute(Sender: TObject);

begin
    if CurrentFile = '' then
    SaveAction.Execute()
  else
    Memo1.Lines.SaveToFile(CurrentFile);


end;

procedure TTexEditorForm.SaveAsAcitionExecute(Sender: TObject);
Var
  FileName: String;
  UserResponse: TmodalResult;



  begin
    begin
  if SaveFileDialog.Execute = True then
  begin
    FileName := SaveFileDialog.FileName;
    if FileExists(FileName) then
    begin
      UserResponse := MessageDlg(
        'File already exists. Do you want to overwrite?',
        TMsgDlgType.mtInformation, mbYesNo, 0);
      if UserResponse = mrNo then
      Exit;

      end;
    Memo1.Lines.SaveToFile(FileName);
    CurrentFile := FileName;
    Caption := 'Text Editor - ' + ExtractFileName(FileName);
  end;
end;

end;

procedure TTexEditorForm.SelectAllActionExecute(Sender: TObject);
begin
  Memo1.SelectAll;
  UpdateStatusBar;

end;

procedure TTexEditorForm.UndoActionExecute(Sender: TObject);
begin
   Memo1.UnDo;
  UpdateStatusBar;
end;

procedure TTexEditorForm.UpdateStatusbar;
begin
  Label1.Text := 'L:' + (Memo1.CaretPosition.Line + 1).ToString;
  Label2.Text := 'C:' + (Memo1.CaretPosition.Pos + 1). ToString;
  Label3.Text := 'Lines:' + Memo1.lines.Count.ToString;
end;

procedure TTexEditorForm.WordWrapActionExecute(Sender: TObject);
begin
   Memo1.WordWrap := not Memo1.WordWrap;
  WordWrapAction.Checked := Memo1.WordWrap;
  UpdateStatusBar;

end;

end.





Os erros de compilação:


[dcc32 Error] TextEditorUnit.pas(230): E2014 Statement expected, but expression of type 'TMenuItem' found. <-- SE REFERE À LINHA 232


[dcc32 Error] TextEditorUnit.pas(70): E2065 Unsatisfied forward or external declaration: 'TTexEditorForm.Memo1Change'. <-- LINHA 6


[dcc32 Fatal Error] TextEditor.dpr(6): F2063 Could not compile used unit 'TextEditorUnit.pas'.




Valeu
Responder
Sobre este erro:

[dcc32 Error] TextEditorUnit.pas(70): E2065 Unsatisfied forward or external declaration: 'TTexEditorForm.Memo1Change'.


Exclua esta linha:

procedure Memo1Change(Sender: TObject);


Sobre este erro:

[dcc32 Error] TextEditorUnit.pas(230): E2014 Statement expected, but expression of type 'TMenuItem' found. 


Altere sua procedure para que fique assim:

procedure TTexEditorForm.SaveAsAcitionExecute(Sender: TObject);
Var
  FileName: String;
  UserResponse: TmodalResult;
begin
  if SaveFileDialog.Execute = True then
  begin
    FileName := SaveFileDialog.FileName;

    if FileExists(FileName) then
    begin
      UserResponse := MessageDlg('File already exists. Do you want to overwrite?',
        TMsgDlgType.mtInformation, mbYesNo, 0);
      if UserResponse = mrNo then
        Exit;
    end;

    Memo1.Lines.SaveToFile(FileName);
    CurrentFile := FileName;
    Caption := 'Text Editor - ' + ExtractFileName(FileName);
  end;
end;
Responder
Olá, irmão. realmente resolveu um dos erros deletando a linha abaixo, mas não executa. Ainda está dando dois erros.

Este está apontando para Exit e tem uma setinha vermelha, curvada para baixo, logo depois da palavra referida (Exit):


[dcc32 Error] TextEditorUnit.pas(226): E2014 Statement expected, but expression of type 'TMenuItem' found


Você, ou alguém, sabe o que é isso?


Mais esse:


[code[dcc32 Fatal Error] TextEditor.dpr(6): F2063 Could not compile used unit 'TextEditorUnit.pas'][/code]


Se alguém puder ajudar agradeço.

Valew.



Sobre este erro:

[dcc32 Error] TextEditorUnit.pas(70): E2065 Unsatisfied forward or external declaration: 'TTexEditorForm.Memo1Change'.


Exclua esta linha:

procedure Memo1Change(Sender: TObject);


Sobre este erro:

[dcc32 Error] TextEditorUnit.pas(230): E2014 Statement expected, but expression of type 'TMenuItem' found. 


Altere sua procedure para que fique assim:

procedure TTexEditorForm.SaveAsAcitionExecute(Sender: TObject);
Var
  FileName: String;
  UserResponse: TmodalResult;
begin
  if SaveFileDialog.Execute = True then
  begin
    FileName := SaveFileDialog.FileName;

    if FileExists(FileName) then
    begin
      UserResponse := MessageDlg('File already exists. Do you want to overwrite?',
        TMsgDlgType.mtInformation, mbYesNo, 0);
      if UserResponse = mrNo then
        Exit;
    end;

    Memo1.Lines.SaveToFile(FileName);
    CurrentFile := FileName;
    Caption := 'Text Editor - ' + ExtractFileName(FileName);
  end;
end;
Responder
Creio que o código fonte esteja correto e desconfio que você tenha um item do seu menu com o mesmo nome que o comando Exit,
causando assim inconsistência no momento da compilação.

Se for isso, altere o nome do seu item do menu de Exit para Exit1 para diferenciar do comando Exit.
Responder