Recent

Author Topic: The variant part of the record is always public  (Read 795 times)

ASerge

  • Hero Member
  • *****
  • Posts: 2290
The variant part of the record is always public
« on: June 15, 2024, 04:45:35 pm »
Code: Pascal  [Select][+][-]
  1. {$MODE OBJFPC}
  2. {$MODESWITCH ADVANCEDRECORDS}
  3.  
  4. type
  5.   TRec = record
  6.   strict private
  7.     case Selector: Byte of
  8.       1: (PartInt: Integer);
  9.       2: (PartBool: Boolean);
  10.   end;
  11.  
  12. var
  13.   R: TRec;
  14. begin
  15.   //R.Selector := 1; // project1.lpr(15,5) Error: identifier idents no member "Selector"
  16.   R.PartInt := 55; // No error
  17. end.
Please test this in the latest version of Delphi, is it the same in it?

Thaddy

  • Hero Member
  • *****
  • Posts: 15214
  • Censorship about opinions does not belong here.
Re: The variant part of the record is always public
« Reply #1 on: June 16, 2024, 08:54:47 am »
Delphi 11 errors as it should.
Of course the national anthem of the U.S.A. was written by Jimi Hendrix, didn't you know that?

ASerge

  • Hero Member
  • *****
  • Posts: 2290

 

TinyPortal © 2005-2018