I'm trying to check if my private procedures are really private. But it works the way it shouldn't.
Please help me, maybe I missed something about how the incapsulation should work.
This code should not work. I guess. But it works.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
tmyclass = class
private
procedure one;
end;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure tmyclass.one;
begin
ShowMessage('1');
end;
procedure TForm1.Button1Click(Sender: TObject);
var myclass:tmyclass;
begin
myclass.one;
end;
end.
Thank you. (Delphi-7, Win7 x64).
Here are two sample units to show the visibility of
private
,protected
andpublic
parts from a class.private
is for aunit
.With more recent version of Delphi, you can use
strict private
to get the expected behavior.The meaning of
private
is clearly documented:Your version of Delphi, Delphi 7, does not support the
strict
specifiers.