You can't do what you want, that is unless there is an underlying structure, may be hidden, that expresses the full range.
Any other thing would not be an enum.
I fear you don't grasp that a third party provided enum also has indices starting from 0. Concatinating with you own enum that also starts from index 0 leads to duplicates or makes the resulting enum worthless because one of the enums
must shift their values
. Do you understand that part? I am not veering away from your original idea, I am merely pointing out it can not be done in a meaningful way.
suppose my enum is:
myenum = (one,two,three);
And some
external code provides an enum
theirenum = (four, five,six);
how would you merge them without loosing their value or changing their meaning?
Because Ord(one) = 0 and ord(four) is also 0, you can't make that 4, because then the meaning of the enum has changed and code would not work as expected. E.g., toggling a switch based on enum, what I use a lot for IoT. will fail if the external enum would be merged into your own. one <> four but both originally are Ord(one) = 0 and ord(four) = 0.
It would toggle the wrong switch. Enums, by definition, do not allow duplicates.
That leaves two solutions:
Use sets where the full enum is known.
Or create an overlay like so:
type
myenum = (one,two,three);
theirenum = (four,five,six);
var
ours:myenum;
theirs: theirenum absolute ours;
begin
writeln(Ord(two) = Ord(five));// correct
// writeln(two = five); // error
end.
That at least leaves the original ordinal values intact so you do not create accidents.
Another example:
{$mode objfpc}{$scopedenums on}
uses typinfo,rtti;
type
myenum = (one,two,three);
theirenum = (four,five,six);
// what is asked is myenum+theirenum := combinedenum as expression
// if that were possible the index would change and
// the original meaning is lost.
// so we redefine it with the same names.
combinedenum = (one,two,three,four,five,six);
var
ours:myenum;
theirs: theirenum absolute ours;
begin
writeln(ord(myenum.two)); // 1
writeln(ord(theirenum.five)); // 1
writeln(ord(combinedenum.five));// 4 // <--meaning is lost, index is now 4.
end.
That is why it is a bad idea. Renders enums useless.
The primary goal of enums is to provide an
index based on readable names.