Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2000-03

Bug in compiler ??

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Marc Weustink

Or is it as designed ? (I hope not)

AFAIK is the following the same:

   //- 1 ----------
     M.X;
     M.Y;
   //- 2 ----------
     with M do
     begin
       X;
       Y;
     end;
   //--------------

However if X and Y are private or protected, you can access them in the second form, the first results in a compiler error (as I expected):

marc:~/fpc/lazarus/examples$ ppc386 test3
Target OS: Linux for i386
Compiling test3.pp
test3.pp(13,6) Error: Cannot access a private field of an object here
test3.pp(13,6) Warning: Variable M does not seem to be initialized
test3.pp(14,6) Error: Cannot access a protected field of an object here
test3.pp(22,4) Fatal: There were 2 errors compiling module, stopping

Marc

// ---- test3.pp ----------------------
program test3;
//{$mode objfpc}
{$mode delphi}
uses test3a;
var
   M: TMyObject;
begin
   M.X;
   M.Y;
   with M do
   begin
     X;
     Y;
   end;
end.
// ---- test3a.pp ----------------------
unit test3a;
//{$mode objfpc}
{$mode delphi}
interface
type
   TMyObject = class
   private
     procedure X;
   protected
     procedure Y;
   public
   end;
implementation
procedure TMyObject.X;
begin
end;
procedure TMyObject.Y;
begin
end;
end.

Reply by email