Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enumeration inheritance delphi

I am looking to inherite a enumaration in other one:

for example:

Type TMyTypeKind = (TTypeKind, enBoolean, enPath);
like image 523
user558126 Avatar asked Nov 29 '22 15:11

user558126


2 Answers

You can not. Compiler does not know how to interpret this. From the wiki :

An enumerated type defines an ordered set of values by simply listing identifiers that denote these values. The values have no inherent meaning.

like image 193
RBA Avatar answered Dec 05 '22 04:12

RBA


Something similar is possible in the reverse order. If you know all the possible values, define it as a base type and declare subrange types of it. The subranges will be assignement compatible with the base type and with each other. It may or may not be a benefit.

type
 TEnumAll = (enFirst, enSecond, enThird, enFourth, enFifth);
 TEnumLower = enFirst..enThird;
 TEnumMore = enFirst..enFourth;
procedure TForm1.Test1;
var
  All: TEnumAll;
  Lower: TEnumLower;
begin
  for All := Low(TEnumAll) to High(TEnumAll) do begin
   Lower := All;
  end;
  for Lower := Low(TEnumLower) to High(TEnumLower) do begin
    All := Lower;
  end;
end;
like image 40
malom Avatar answered Dec 05 '22 04:12

malom