Bascy
Bascy

Reputation: 2089

Delphi framework for IS units and conversions

We need a generic framework that will allow our application to do all kinds of conversions between the base units of the International System of Units and the derived units. It should i.e. be possible to add values with unit "meter" to values with unit "kilometer", and it should be able to determine what the unit of an expression is.

So if we calculate the product of a speed (m/s) and a time (h:mm:ss) then it should be able to determine that the resulting unit is distance (m).

Does anybody know if such a library is available somewhere, commercially or open source?

Upvotes: 1

Views: 369

Answers (1)

Ken White
Ken White

Reputation: 125651

There's no way to do it directly that I've seen.

You have to convert one type into the other (or both into a common type), perform your operation, and then convert the results back.

Delphi (since 2007, at least) comes with the ConvUnit unit that has classes that will do this type thing, and there's a sample app that demonstrates called ConvertIt. YOu can do your own custom conversion types, which makes it pretty flexible.

There's more info in the Delphi documentation wiki.

ConvertIt sample screen image

Upvotes: 2

Related Questions