Enumerated types

Is there any way in which I can use enumerated types from the Data Modeler?  Suppose I want to use an enumerated type TVehicleType = (vtBicycle, vtMotorCycle, vtCar, vtTruck), mapped to a Char(1) field in the database; 'B', 'M', 'C', 'T'.

For obvious reasons, if I declare a Char(1) field in the Data Modeler, this field will be generated as a String property.  Ideally, I would somehow like to generated a property of type TVehicleType.

Unfortunately I have not been able to find any documentation on this other than the Enumerated attribute in the TMS Aurelius Help.  I did however find an old post on this subject, but in the answer the questions was raised of how to define the enumerated values (ref. https://www.tmssoftware.com/site/forum/forum_posts.asp?TID=4029&KW=enumeration&PID=14629&title=export-to-aurelius-enumerator#14629)

Do you think it's feasible to define a Domain (e.g. ENUM_VEHICLE, mapping to Char(1)) and then use scripts to add the TVehicleType declaration to the resulting source code as well exporting the property as TVehicleType?

If so, could you provide some sample script of how to approach this? I am using a SQLite database but at later stages may also want to use such an approach for SQLServer.

Thanks in advance!  Regards, Mark

Hi Mark,

Sorry for the delay in answering. The easiest approach is just declare your enumerated types in a separated unit (for example, "Entities.EnumeratedTypes", and then use the script to change the type of the field/property to the enumerated you want. For example:



procedure OnColumnGenerated(Args: TColumnGeneratedArgs);             
begin                                                             
  if Args.DBField.FieldName = 'VehicleType' then               
  begin
    Args.Prop.PropertyType := TCodeTypeReference.Create('TVehicleType');
    Args.Field.FieldType := TCodeTypeReference.Create('TVehicleType');
  end;
end;


procedure OnUnitGenerated(Args: TUnitGeneratedArgs);
begin
  Args.CodeUnit.InterfaceUnits.Add(TCodeUsedUnit.Create('Entities.EnumeratedTypes'));
end;