I am attempting to create an enumeration that I will use in my app. A user can select from this enumeration as a list of possible values. I want to organize these values in this enumeration into categories because there are going to be alot of them. I was thinking about using a naming convention to denote this like group1_itemname.
But this might make maintenance tough should I want to re-categorize the item later and the item is used in code already.
I am using the Service Builder to generate the interface file. I thought about using the attributes within the Service Builder, but I’m not sure how. . .
The above image shows what I was thinking. Where my elementname would be a “Friendly Display Value” and the location would be the “Category”
This article says the Attributes are not supported, but that was in 2012. Has it changed??
I’m not sure if this is a good way of doing this or if there is a better way. I’m new to the use of attributes in general and haven’t been able to find a lot of information for delphi.
type
[ROCustom('enum1_name', 'Insert Helpdesk')]
[ROCustom('enum1_group', 'group1')]
[ROCustom('enum2_name', 'Update Helpdesk')]
[ROCustom('enum2_group', 'group2')]
NewEnum = (enum1, enum2);
procedure TForm86.Button1Click(Sender: TObject);
var
enum: TRTTIObject;
dict: TDictionary<String, String>;
s, k: string;
i: integer;
begin
enum := RORTTI_FindRTTIObject(TypeInfo(NewEnum));
dict := RORTTI_GetCustomAttributes(enum);
for i := 0 to ord(High(NewEnum)) do begin
s := ROGetEnumName(TypeInfo(NewEnum), i,'');
if dict.TryGetValue(s+'_name', k) then Memo1.Lines.Add(Format('[%s], name = %s',[s, k]));
if dict.TryGetValue(s+'_group', k) then Memo1.Lines.Add(Format('[%s], group = %s',[s, k]));
end;
dict.Free;
end;
Note: this will work only in Delphi XE3+ and in Code-First mode only: