[fpc-devel] Variant Records and Duplicate Identifiers

Maciej Izak hnb.code at gmail.com
Fri Apr 22 10:05:12 CEST 2016


2016-04-21 8:00 GMT+02:00 <kevin at kdx.me>:

> type
>   maritalStates = (single, married, widowed, divorced);
>
>   TPerson = record
>     name: record
>       first, middle, last: string;
>     end;
>     sex: (male, female);
>     dob: TDateTime;
>     case maritalStatus: maritalStates of
>       single: ( );
>       married, widowed: (marriageDate: TDateTime);
>       divorced: (marriageDate, divorceDate: TDateTime;
>         isFirstDivorce: boolean)
>   end;
>
> So the question then becomes: is the wiki in error, or is there something
> I'm missing? Furthermore, if the wiki is in fact wrong, and this is a
> limitation, is there any inherent reason why? It seems to me like this
> should be possible, it's certainly a very useful thing to have.
>

That is 100% bad example. You can't have two fields with the same name even
for that kind of record with "case" part. Correct example:

=== begin code ===
type
  TMaritalStates = (single, married, widowed, divorced);

  TPerson = record
    name: record
      first, middle, last: string;
    end;
    sex: (male, female);
    dob: TDateTime;
    case maritalStatus: TMaritalStates of
      single: ();
      married,widowed,divorced: (
        marriageDate: TDateTime;
        case TMaritalStates of
          widowed: (
            widowedDate: TDateTime);
          divorced: (
            divorceDate: TDateTime;
            isFirstDivorce: boolean)
        );
  end;
=== end code ===

-- 
Best regards,
Maciej Izak
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20160422/a9a08103/attachment.html>


More information about the fpc-devel mailing list