//对TSomeObject类的MyString属性进行封装例子。
TSomeObject = class
private
FMyString: String;
function GetMyString: String;
procedure SetMyString(aVal: String);
published
property MyString: String read GetMyString Write SetMyString;
end;
implementation
{$R *.dfm}
function TSomeObject.GetMyString: String;
begin
//此处可添加限制条件(如:权限验证以及默认处理等等);
if FMyString = '' then
Result := '空!'
else
Result := FMyString;
end;
procedure TSomeObject.SetMyString(const aVal: String);
begin
//此处可添加限制条件(如:赋值合法性检查等等);
if aVal = '' then
ShowMessage('不能为空!')
else
FMyString := aVal;
end;
end.