您的位置:首页 > 编程语言 > Delphi

delphi property

2015-11-05 13:02 471 查看

unit Test;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, HGEWinCtrl, StdCtrls;

type

TForm1 = class(TForm)

lbl1: TLabel;

btn1: TButton;

procedure btn1Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

TMyClass = Class

private

B1 : string;

function GetField1: string;

procedure SetField1(AField: string);

public

property A1: string read GetField1 write SetField1;

end;

var

Form1: TForm1;

MyClass : TMyClass;

implementation

{$R *.dfm}

function TMyClass.GetField1: string;

begin

result := B1;

end;

procedure TMyClass.SetField1(AField: string);

begin

B1 := AField;

end;

procedure TForm1.btn1Click(Sender: TObject);

begin

MyClass := TMyClass.Create;

MyClass.A1 := '1111111111'; //赋值会调用SetField1代码段

lbl1.Caption := MyClass.A1;

end;

end.

<script src="https://code.csdn.net/snippets/F1u4Z40656T9395613M8.js"></script>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: