type
{$SCOPEDENUMS ON}
TRating = (undefined, Perfect, OK, Acceptable, NotGoodEnough, Bad, TotalShit);
TRatingHelper =
record helper
for TRating
procedure HandleIncompleteCase(Rating: TRating);
end;
procedure TRatingHelper.HandleIncompleteCase(Rating: TRating);
begin
raise EProgrammerNotFound.Create('
unhandled case for TRating: ' + TRttiEnumerationType.GetName(Rating));
end;
const
cRatingPositive = [TRating.Perfect, TRating.OK, TRating.Acceptable];
cRatingNegative = [TRating.NotGoodEnough, TRating.Bad, TRating.TotalShit];
procedure HandleRating(Rating: TRating);
begin
if Rating
in cRatingPositive
then begin
// Handle positive rating part 1
...
// Handle specific rating
case Rating
of
TRating.Perfect: ...;
TRating.OK: ...;
TRating.Acceptable: ...;
else
HandleIncompleteCase(Rating);
end;
// Handle positive rating part 2
...
end
else if Rating
in cRatingNegative
begin
// Handle negative rating part 1
...
// Handle specific rating
case Rating
of
TRating.NotGoodEnough: ...;
TRating.Bad: ...;
TRating.TotalShit: ...;
else
HandleIncompleteCase(Rating);
end;
// Handle negative rating part 2
...
end
else begin
// Handle undefined rating
...
end;
end;