Strongly typed ids

Hi,
I was reading this article

Is it possible to do something similar with records in Oxygene ?

Thanks,
John

StronglyTypesIdsConsoleApplication.zip (629.4 KB)

When OrderId is a record the error is

E: Type mismatch, cannot find operator to evaluate “OrderId” = “OrderId” [/Users/JohnMoshakis/Documents/develop/Island/StronglyTypesIdsConsoleApplication/Program.pas (20)]
It works ok for a class

I’ll have a look; this should work fine, just as in C#.

that said, simply:

type
  OrderID = public type Guid;

should give you an incompatible (without explicit cast) type alias to Guid that shoukld achieve much the same, without all the manual code?

1 Like

It is possible to cast in a mapping ?

  Latitude = public type Double;
  Longitude = public type Double;
  
  
  LocationCoordinate2D = public class mapped to CoreLocation.CLLocationCoordinate2D
  
  public
    property lat: Latitude read mapped.latitude write mapped.latitude;

I can do this

property lat: Latitude read mapped.latitude as Latitude write mapped.latitude;
property long : Longitude read mapped.longitude as Longitude write mapped.longitude;

But then Im not sure what to do with the write ?

MappedConsoleApplication.zip (7.4 KB)

I take ti the write doesnt compile as shown? it might need an explicit cast, eg

property lat: Latitude 
  read mapped.latitude as Latitude 
  write begin
    mapped.latitude := value as Double;
  end;