Difference between “strict private” and “protected” Access Modifiers in Delphi?

后端 未结 5 1927
野趣味
野趣味 2020-12-31 03:23

but I learn programming and after structured programming with Pascal language, I\'m beginning to learn about OOP with Delphi.

So, I don\'t really understand the diff

5条回答
  •  抹茶落季
    2020-12-31 03:46

    One case is missing in the other answers: private and even strict private fields of other instances can be accessed from code within their class:

    type
      TSO1516493= class
      strict private
        A: Integer;
      public
        procedure ChangeOther(Param: TSO1516493);
      end;
    
    { TSO1516493 }
    
    procedure TSO1516493.ChangeOther(Param: TSO1516493);
    begin
      Param.A := -1; // accessing a strict private variable in other instance !
    end;
    

    (This is the same behavior as in Java.)

提交回复
热议问题