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>