Recent

Author Topic: Completion Box: no protected inherited content when using pointer to object  (Read 581 times)

furious programming

  • Hero Member
  • *****
  • Posts: 858
One program unit declares an object (good old object, not a class) containing protected fields. This is the base object type from which others can inherit. For example:

Code: Pascal  [Select][+][-]
  1. unit Base;
  2.  
  3. {$mode ObjFPC}{$H+}
  4.  
  5. interface
  6.  
  7. type
  8.   PBase = ^TBase;
  9.   TBase = object
  10.   protected
  11.     X: Integer;
  12.     Y: Integer;
  13.   end;
  14.  
  15. implementation
  16.  
  17. end.

In another unit there is a declaration of another object that inherits from this base one. In addition to the data type, there is also a procedure that takes a pointer to the final object and modifies the object's data — there is access to all fields, including inherited ones. For example:

Code: Pascal  [Select][+][-]
  1. unit Something;
  2.  
  3. {$mode ObjFPC}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Base;
  9.  
  10. type
  11.   PSomething = ^TSomething;
  12.   TSomething = object(TBase)
  13.   protected
  14.     A: Integer;
  15.     B: Integer;
  16.   end;
  17.  
  18.   procedure DoSomething(ASomething: PSomething);
  19.  
  20. implementation
  21.  
  22. procedure DoSomething(ASomething: PSomething);
  23. begin
  24.   // direct modification of inherited fields
  25.   ASomething^.X := 10;
  26.   ASomething^.Y := 20;
  27.  
  28.   // modification of non-inherited object fields
  29.   ASomething^.A := 50;
  30.   ASomething^.B := 100;
  31. end;
  32.  
  33. end.

The structure of the code is correct, it compiles without any errors and works properly.

The problem is that the Completion Box window does not suggest inherited content. In this case, it shows only non-inherited content, i.e. fields A and B, while fields X and Y, although access to them is provided (thanks to the protected section), are not listed — see the attachment.

IMO this is a bug because in the DoSomething routine I have the ability to directly access all the inherited protected content, so the Completion Box should also contain all the protected content that the final object inherits. Am I right?

In the second attachment is a test project, you can check it yourself.
« Last Edit: December 17, 2022, 12:08:26 pm by furious programming »
Lazarus 3.2 with FPC 3.2.2, Windows 10 — all 64-bit

Working solo on an acrade, action/adventure game in retro style (pixelart), programming the engine and shell from scratch, using Free Pascal and SDL. Release planned in 2026.

 

TinyPortal © 2005-2018