+ -
当前位置:首页 → 问答吧 → 定义一个属性为什么会错??

定义一个属性为什么会错??

时间:2011-10-29

来源:互联网

unit B;

interface

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

type
  TForm2 = class(TForm)
  btn1: TButton;
  edt1: TEdit;
  procedure btn1Click(Sender: TObject);

  private
  { Private declarations }
  strName: string;
  function GetstrName: string;
  procedure SetstrName(const value: string);

  public
  { Public declarations }
  property proName: string read strName write strName;
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}


function TForm2.GetstrName: string;
begin
  result := strName;
end;

procedure TForm2.SetstrName(const value: string);
begin
  if (value = strName) then
  begin
  Exit;
  end
  else
  begin
  strName= value; //这里为什么会错??
  end;

end;

initialization

// strname:='this default';

end.

作者: xonln   发布时间: 2011-10-29

缺少 冒号??

作者: okmnjizc   发布时间: 2011-10-29

strName= value; 改为
strName := value;

作者: Robin95314852   发布时间: 2011-10-29

作者: hongss   发布时间: 2011-10-29