Delphi没有友元,因为同一个Unit的,是可以访问别的类的Private或者Protected变量的,也就是默认就友元了。要让同一个Unit的不友元,就要用到strict。
比如同一个Unit里
TA = class
private
p1: Integer;
protected
p2: Integer;
strict private
p3: Integer;
strict protected
p4: Integer;
end;
TB = class
procedure showTA(a: TA);
end;
procedure TB.showTA(a: TA);
begin
showmessage(inttostr(a.p1));//ok
showmessage(inttostr(a.p2));//ok
showmessage(inttostr(a.p3));//error
showmessage(inttostr(a.p4));//error
end;
没有评论:
发表评论