Delphi错误:Equals.Caption:=;表达预期,但';'发现

时间:2017-04-16 18:31:19

标签: delphi

我遵循了这个:http://delphi.wikia.com/wiki/Simple_Calculator_Tutorial

这是我在Delphi中的代码:

unit Unit3;

interface

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

type
  TForm3 = class(TForm)
    Addition: TButton;
    Subtraction: TButton;
    Multiplication: TButton;
    Division: TButton;
    One: TButton;
    Two: TButton;
    Three: TButton;
    Four: TButton;
    Five: TButton;
    Six: TButton;
    Seven: TButton;
    Eight: TButton;
    Nine: TButton;
    Zero: TButton;
    Decimal: TButton;
    Enter: TButton;
    ClearValue: TButton;
    Panel1: TPanel;
    Negative: TButton;
    Reset: TButton;
    NumberEdit: TEdit;
    Equals: TLabel;
    procedure NegativeClick(Sender: TObject);
    procedure AdditionClick(Sender: TObject);
    procedure SubtractionClick(Sender: TObject);
    procedure MultiplicationClick(Sender: TObject);
    procedure DivisionClick(Sender: TObject);
    procedure EnterClick(Sender: TObject);
    procedure ClearValueClick(Sender: TObject);
    procedure ResetClick(Sender: TObject);
    procedure NumberEditChange(Sender: TObject);
    procedure NumberButtonClick (Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form3: TForm3;

implementation

{$R *.DFM}

var
  FNumber : real;
  Math : string;    

procedure TForm3.NumberButtonClick(Sender: TObject);
begin
  NumberEdit.Text := NumberEdit.Text + (Sender as TButton).Caption;
end;    

procedure TForm3.NegativeClick(Sender: TObject);
var
  OriginalNumber: real;
  TextNumber: string;
begin
  OriginalNumber := -(StrToFloat(NumberEdit.Text));
  TextNumber := FormatFloat('0.##########', OriginalNumber);
  NumberEdit.Text := TextNumber
end;    

procedure TForm3.AdditionClick(Sender: TObject);
begin
  Math := 'Add';
  FNumber := StrToFloat(NumberEdit.Text);
  NumberEdit.Clear;
end;

procedure TForm3.SubtractionClick(Sender: TObject);
begin
  Math := 'Subtract';
  FNumber := StrToFloat(NumberEdit.Text);
  NumberEdit.Clear;
end;

procedure TForm3.MultiplicationClick(Sender: TObject);
begin
  Math := 'Multiply';
  FNumber := StrToFloat(NumberEdit.Text);
  NumberEdit.Clear;
end;

procedure TForm3.DivisionClick(Sender: TObject);
begin
  Math := 'Divide';
  FNumber := StrToFloat(NumberEdit.Text);
  NumberEdit.Clear;
end;    

procedure TForm3.EnterClick(Sender: TObject);
var
  Answer, SNumber : real;
  Text : string;    
begin
  SNumber := StrToFloat(NumberEdit.Text);    
  begin
    if Math = 'Add' then
      Answer := FNumber + SNumber;
    Text := FormatFloat('0.#####', Answer);
    Equals.Caption := '= ' + Text;
    NumberEdit.Clear;
  end;

  begin
    if Math = 'Subtract' then
      Answer := FNumber - SNumber;
    Text := FormatFloat('0.#####', Answer);
    Equals.Caption := '= ' + Text;
    NumberEdit.Clear;
  end;

  begin
    if Math = 'Multiply' then
      Answer := FNumber * SNumber;
    Text := FormatFloat('0.#####', Answer);
    Equals.Caption := '= ' + Text;
    NumberEdit.Clear;
  end;

  begin
    if Math = 'Divide' then
      Answer := FNumber / SNumber;
    Text := FormatFloat('0.#####', Answer);
    Equals.Caption := '= ' + Text;
    NumberEdit.Clear;    
  end;

end;

procedure TForm3.ClearValueClick(Sender: TObject);
begin
  NumberEdit.Clear;
end;   

procedure TForm3.ResetClick(Sender: TObject);
begin
  Equals.Caption := ;
  NumberEdit.Clear;
  FNumber := 0;
  SNumber := 0;
  Math := 'Default';
end;

end.

这是我收到的错误的屏幕截图:

This Screenshot Errors

1 个答案:

答案 0 :(得分:5)

错误行说明了一切:它需要一个表达式,但它会找到一个分号。

这一行:

Equals.Caption := ;

不是有效的声明。您必须为Caption分配一个字符串(一个表达式,产生一个字符串,也可以只是一个字符串文字)。它可以是空字符串'',例如

Equals.Caption := '';

我看到您使用的原始代码也有此错误。好吧,似乎是一个拼写错误,可能是因为他们使用突出显示HTML <b><i>等HTML标记来标记代码。