What I want to achieve is just like the dummy code:
type
CommandSetOne = (Command1, Command2, Command3);
CommandSetTwo = (Command4, Command5, Command6);
TRobot = class
procedure RegisterCommands(anyEnumerationType : TRttiEnumerationType);
procedure ExecuteCommands(anEnumeration : theEnumerationType);
end;
Which I may have multiple set of command, and any command in command set is replaceable.
TRobot has a procedure can take a enumeration type as parameter, and he will save this type, use this type for the ExecuteCommands procedure.
About passing any enumeration type as parameter, I found out a way to do that is to use TRttiEnumerationType, in the call side it should looks like:
var
rttiContext : TRttiContext;
typeref : TRttiType;
RobotA : TRobot;
begin
rttiContext := TRttiContext.Create();
RobotA := TRobot.Create();
RobotA.RegisterCommands(rttiContext.GetType(TypeInfo(CommandSetOne)));
end;
but I got stuck on passing a Command like Command1. I have tried Variant for theEnumerationType but seems I can not pass Command1 to this.
I know if I use something like TStringList for this is a much easier way to do what I want, but I would like to have a check by delphi at complies time in case I mistype some command(use TstringList I can add code to check at runtime)
so the real problem is:
which type should I use for theEnumerationType?
if it's not possible to to this, any other solution to use Enumeration?
or any solution can provide a complies time check as well as a flexible structure?
EDIT:
thanks for David suggested, I should use both Rtti things, so to make it clear, I add the implementation for RegisterCommands
implementation
procedure TRobot.RegisterCommands(anyEnumerationType : TRttiEnumerationType);
begin
theEnumerationType := anyEnumerationType;
end;
procedure TRobot.ExecuteCommands (anyEnumerationValueoftheType : ???);
begin
//do something with the command
end;
so what should fit for any enumeration value for the type?
for example, if I use CommandSetOne in RegisterCommands, how can delphi accept Command1 or Command2 or Command3?
more specifically, can delphi limit the room only for Command1 or Command2 or Command3? means if I put Command4 it give me an compile error?