I'm trying to make a convenient function to convert a System.Classes.TShiftState
into a user-readable string. To make it easier, I've made a subroutine to perform common code, to make the function more compact.
The problem is, I cannot figure out how to pass one of the TShiftState
enum types into this subroutine. I tried Byte
, Integer
, and Cardinal
but I keep getting Incompatible types: 'Byte' and 'Enumeration'
(or whichever type I was trying). Hovering over one of them only shows $1
where the type would usually be.
function ShiftStateStr(const Shift: TShiftState): String;
procedure A(const Sh: Byte; const Str: String);
begin
if Sh in Shift then
Result:= Result + StrLen(Str, Length(Str)+1)
else
Result:= Result + StrLen('', Length(Str)+1);
end;
begin
Result:= '';
A(ssShift, 'Shift');
A(ssAlt, 'Alt');
A(ssCtrl, 'Ctrl');
A(ssLeft, 'Left');
A(ssRight, 'Right');
A(ssMiddle, 'Middle');
A(ssDouble, 'Double');
A(ssTouch, 'Touch');
A(ssPen, 'Pen');
A(ssCommand, 'Cmd');
A(System.Classes.ssHorizontal, 'Horz');
end;
NOTE:
StrLen
is a separate function which pads a string with spaces of a given length.
TShiftState
is defined in System.Classes
like so:
type
TShiftState = set of (ssShift, ssAlt, ssCtrl,
ssLeft, ssRight, ssMiddle, ssDouble, ssTouch, ssPen, ssCommand, ssHorizontal);
How can I properly pass this into the A
subroutine?
StrLen
is a name used for a function that returns the length of a null terminated character array. Usestr.PadLeft(n)
instead. – Wilkinsss
in front of them. Like I said, more human-readable :P – BulaCommand
is shortened toCmd
, andHorizontal
toHorz
, etc. – BulaTypeInfo()
? There is no named type for the values that make up theTShiftState
set. The enumeration is anonymous. – Lipoprotein