Blog

All Blog Posts  |  Next Post  |  Previous Post

FNC Physics Components in TMS Analytics & Physics 3.3

Monday, February 7, 2022


TMS Analytics & Physics library is a set of classes that provide functionality for building powerful math and engineering applications with Delphi IDE. In the new version 3.3 of the library, we introduced special FNC physics components to take advantage of Delphi’s rapid application development.
In this article, we’ll consider the base concepts of the FNC physics components and provide information on how to work with units of measurement. 
Let’s consider the following FNC physics components:

  • TFNCUnitProvider – creates a physics environment for the application; contains information about registered physics entities and provides units of measurement to other physics components.
  • TFNCUnitConverter – provides properties and functionality to convert physical values measured in two different units.

To begin an FNC physics application we first need to put a TFNCUnitProvider component on the form. The component has the following published properties:

  • Quantities (TQuantityCollection) – a collection of registered physical quantities.
  • Prefixes (TPrefixCollection) – a collection of registered prefixes that can be used to create units with multiplier factors (like kilo-, milli-, and so on).
  • Units (TUnitCollection) – a collection of registered units of measurement that can be used to create complicated derived units.

When you put a TFNCUnitProvider on the form in design-time, it automatically finds all registered quantities, prefixes, and units. The collections of these items are not editable, they only provide information about available physical entities. When an item is selected in a collection, its properties are shown in the Object Inspector.
In the picture below, you can see a collection of physical quantities:

 TMS Software Delphi  Components

Any quantity has the following properties:

  • Name (string) – the name of the quantity.
  • Symbol (string) – a common symbol for the quantity designation.
  • Dimension (string) – physical dimension of the quantity.

As an example, we showed the ‘Area’ quantity. Its physical dimension is ‘L^2’ – squared length. More information about physical dimensions can be found in the documentation for the library.
Analogously, you can view information about all registered unit prefixes, as shown in the picture below.

 TMS Software Delphi  Components

A prefix provides the following properties:

  • Name (string) – the name of the prefix.
  • Symbol (string) – symbol, identifying the prefix in composite units.
  • Value (real) – the multiplier factor of the prefix.

And finally, you can view all available units of measurements.

 TMS Software Delphi  Components

Any unit provides the following properties:

  • Name (string) – the name of the unit.
  • Symbol (string) – the symbol of the unit that is used to identify this unit for conversion algorithm and other manipulations.
  • Dimension (string) – physical dimension of the unit.

The unit provider component supplies the physical entities to other components, for example, to the TFNCUnitConverter. This component is intended to convert physical values measured in two different units and has the following properties:

  • Provider (TFNCUnitProvider) – a unit provider.
  • Unit1 (TUnitProperty) – the first unit of measurement for conversion.
  • Unit2 (TUnitProperty) – the second unit of measurement for conversion.
  • Value1 (real) – the first value, measured in the first unit of measurement.
  • Value2 (real) – the second value, measured in the second unit of measurement.
  • Valid (boolean) – read-only value defining if all input items are valid for conversion.
  • Error (string) – read-only text of an error that occurred during conversion.
  • IntervalConversion (boolean) – defines if making the interval conversion or not.

First of all, you need to assign the ‘Provider’ property to set up the physical environment for unit conversion. Next, you have to assign the units for the conversion. The ‘TUnitProperty’ class has several published properties:
  • Symbol (string) – the symbol of the unit.
  • Name (string) – the name of the unit.
  • Dimension (string) – physical dimension of the unit.
  • Valid (boolean) – read-only value defining if the symbol of the unit is valid.
  • Error (string) – read-only text of an error that occurred when parsing the symbol.

The only property you can modify is the ‘Symbol’. When you set a new value of the symbol, all other properties changed according to the input. If the input is not correct, the ‘Error’ property is assigned as shown in the picture below.

TMS Software Delphi  Components

Conversion between two units of measurement can be done only if the units have the same physical dimension. When you assign the units to a converter component, it compares the dimensions and, if the units are not compatible, assigns the ‘Error’ property as shown in the following picture.

TMS Software Delphi  Components

When the units are assigned and are valid for conversion, you can change the ‘Value1’ and ‘Value2’. When the first value is assigned, the component converts the value from the first unit of measurement to the second one and assigns the second value. In the picture below, we showed the conversion of 10000 square millimeters to squared feet.

 TMS Software Delphi  Components

You also can change the unit symbol and see how the converted value changes. As an example, here is the conversion of 10000 square millimeters to square inches.

 TMS Software Delphi  Components

The last property of the TFNCUnitConverter we have to mention is ‘IntervalConversion’. It switches the component between two modes of conversion. By default, the value of the property is ‘False’, and we have so-called value conversion, when it is ‘True’, we have the interval conversion. Let’s consider the difference between the modes for temperature units of measurement.

TMS Software Delphi  Components  

In the picture above, we showed two conversions of temperature from Celsius degrees to Fahrenheit degrees. In the first case, the value conversion was used, and we see that 30°C = 86°F. On the other side, when we do interval conversion, we see another result 30°C = 54°F.
Now we can create a simple unit conversion application. We added four TEdit components on the form – two for units and two for values, and one button with the following click handler:

procedure TForm1.Button1Click(Sender: TObject);
var
  v1, v2: real;
begin
  FNCUnitConverter1.Unit1.Symbol:= '';
  FNCUnitConverter1.Unit2.Symbol:= '';
  v1:= StrToFloat(Edit1.Text);
  FNCUnitConverter1.Unit1.Symbol:= Edit2.Text;
  FNCUnitConverter1.Unit2.Symbol:= Edit3.Text;
  FNCUnitConverter1.Value1:= v1;
  if FNCUnitConverter1.Valid then
  begin
    v2:= FNCUnitConverter1.Value2;
    Edit4.Text:= FloatToStr(v2);
  end
  else
    Edit4.Text:= FNCUnitConverter1.Error;
end;

The resulting unit conversion application in run-time is shown in the picture below.

TMS Software Delphi  Components
 
The source code of the demo project for the article can be downloaded from here . To start developing your FNC engineering and math application you need the latest versions of TMS Analytics & Physics and TMS FNC Chart products.



Masiha Zemarai




This blog post has not received any comments yet.



Add a new comment

You will receive a confirmation mail with a link to validate your comment, please use a valid email address.
All fields are required.



All Blog Posts  |  Next Post  |  Previous Post