Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Compiler/Delphi    [ Add a report in this area ]  
Report #:  106283   Status: Closed
Bug in variant part of record when declared private
Project:  Delphi Build #:  2009, ... XE2
Version:    16.4 Submitted By:   Naji Mouawad
Report Type:  Basic functionality failure Date Reported:  6/8/2012 1:18:17 PM
Severity:    Serious / Highly visible problem Last Updated: 9/5/2012 7:48:42 PM
Platform:    All platforms Internal Tracking #:   28925
Resolution: Fixed (Resolution Comments) Resolved in Build: : 17.0.4625.53395
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: None
Description
When a Record contains a variant part marked as private the following two problems occur:
1 -- the editor is no longer able to jump from the declaration of methods to their implementation and vice versa (ctrl shift up/down no longer works) and
2 -- the compiler does not honor the private directive and shows the elements of the variant part as though they were public.

Steps to Reproduce:
1. Create a command line project, copy and paste this code in it:
{===========start of project content===========}
program RecordBug;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils,
  RecordBugUnit in 'RecordBugUnit.pas';

var BR : Buggyrecord;

begin
  //This should not work since (i: integer) this part of the record was marked as private:
  BR.i := 13;
  Writeln('BR.i = ', BR.i);
  Readln;
end.
{==============End of project content =======}

2. Add a new unit to the project, save it as 'RecordBugUnit'

3. Copy and paste the following inside the unit.
{=========== start of RecordBugUnit content===}
unit RecordBugUnit;
interface
Type
  BuggyRecord = packed Record
  private
    function  GetEncodedData     : Integer  ;
    procedure SetEncodedData    (const Value : Integer  );
  public
    procedure New          ;
    procedure NewString    ;
  private
   case integer of
     0 : (
          __EncodedData     : Integer ;
         );
     2 : (
          case integer of
           1 : (pstr : PString)     ;
           2 : (i    : Integer)     ;
        )
  End;

implementation

function BuggyRecord.GetEncodedData: Integer;
begin
  Result := __EncodedData;
end;

procedure BuggyRecord.SetEncodedData(const Value: Integer);
begin
   __EncodedData := Value;
end;

procedure BuggyRecord.New;
begin
  __EncodedData := 0;
end;

procedure BuggyRecord.NewString;
begin
  System.New(pStr);
  pStr^ := '';
end;

end.
{=================End of RecordBugUnit===}

4. Save and compile the project.

To reproduce the bug in the editor do this:

1. Open the RecordBugUnit
   a. Position the cursor on the declaration of the function GetEncodedData.
   b. hit ctrl + shift + down. You will see that nothing happens.
2. Scroll down to the implementations section
   a. Position the cursor on any of the methods
      headings.
   b. hit ctrl + shift + up. You will see that nothing happens.
3. Now go back to the declaration of the record
   and comment out the Private directive preceding the variant part of the record.
4. Repeat steps 1 and 2 to see that ctrl+shift+up/down works as expected.

2. To reproduce the visibility bug, compile and run the program. Make sure the private directive before the variant part is uncommented. The program will compile and run as if the field i is public and not private.
Workarounds
None.
Attachment
RecordBug.zip
Comments

Tomohiro Takahashi at 6/8/2012 9:07:35 PM -
> Build No: Delphi XE2 vers
What build no of Delphi XE2 do you use, for example Update 4(16.0.4429.46931)?

and, could you please attach sample project to reproduce/confirm your issue?

Naji Mouawad at 6/9/2012 12:34:47 PM -
Thank you for asking, Tomihiro:

Delphi Build: XE2 Version 16.0.4429.46931

I will zip and attach the project. I thought I could do it through this comment but I try to attach it to my post. If I can't do that, I will attach it in a reply to the post.

Naji

Naji Mouawad at 6/9/2012 1:17:25 PM -
Ok, I've managed to attach the files to the ticket. Please let me know if you need anything else.

Tomohiro Takahashi at 6/9/2012 9:39:10 PM -
Is this a regression in Delphi XE2 ?
What about previous versions of Delphi?

Naji Mouawad at 6/11/2012 11:37:57 AM -
It's not a regression, Tomohiro. The problem exists in identical fashion in Delphi 2009. I've uploaded the same project but for 2009 and you can verify the same two issues exists in 2009 as well.

Tomohiro Takahashi at 6/12/2012 7:09:01 AM -
This report was opened with valid Internal Tracking Number.
Thanks.

Server Response from: ETNACODE01