fbpx

Search

MathTranslator Object in Applications

The global MathTranslator object extends the computational capabilities of TechEditor. With it, you can carry out algebraic, trigonometric, matrix, differential, integral, symbolic calculations and work with units of measurement.

The MathTranslator object is used in TechEditor applications to perform "embedded" calculations. This object works with text and can be used as a unit converter (for example, to allow users of your applications to enter data in convenient units of measurement).

Methods of MathTranslator

procedure Clear;

The Clear method restarts MathTranslator (deletes all previously created variables, functions, etc.). It is recommended before performing a standalone calculation loop.

Example:

begin
MathTranslator.Clear;
end;

procedure Add(Expression: string);

The Add method adds a new mathematical Expression to the MathTranslator object. An expression can contain a variable or function definition or a mathematical formula:

begin
MathTranslator.Add('a:=10'); // Add real variable 'a' with value 10.0 MathTranslator.Add('b:=20'); // Add real variable 'b' with value 20.0 MathTranslator.Add('c:=a+b'); // Add real variable 'c' with value 30.0 end;

Expression evaluation

function Calculate(Expression: string): Double;

The Calculate method evaluates Expression and returns a numeric result:

var
X: Double;
begin
MathTranslator.Add('a=10'); MathTranslator.Add('b=20'); X := MathTranslator.Calculate('a+b'); // X=30 here
end;

function CalculateStr(Expression: string): string;

The CalculateStr method is similar to the Calculate method, but returns a text string. It is recommended for outputting a numeric value, for example, directly to a report:

var
Msg: string;
begin Msg := MathTranslator.CalculateStr('10+20-50');
ShowMessage('Result: ' + Msg);
end;

Units of Measurement

Basic rules:

  1. Dot is used as decimal separator: 60.2, -70.90
  2. Units of measurement are separated from the numerical value of a physical quantity by a space: 45.5 psi, 120.8 dm
  3. Units of measurement are written in Latin letters (prefixes are allowed): N, MPa, mm, kg.
  4. Physical quantities in the expression must be compatible (have the exact dimensions): 2.2 m --> 220 cm.

Detailed information about units of measurement in TechEditor is here.

function Convert(Value: string; Units: string): Double;

The Convert method converts the physical quantity Value to the new Units and returns the result in the new units:

var
L: Double;
begin L := MathTranslator.Convert('155 cm', 'm');
ShowMessage('L=' + FloatToStr(L) + ' m'); // 'L=1.55 m' here
end;

function ConvertStr(Value: string; Units: string): string;

The ConvertStr method is similar to the Convert method but returns the result as a text:

var
Pressure: string;
begin Pressure := MathTranslator.ConvertStr('0.25 MPa', 'Pa');
ShowMessage('P=' + Pressure + ' Pa');
end;

 

Forums, Chats, Streams — Join our Discord Community for Help & Support!

Knowledge Base - Content

Users Online

    No members to show currently
View All

TechEditor 2.0 Overview

Dystlab™ — Project for Engineers

Dystlab™. All rights reserved.

Ukraine, 76006, Ivano-Frankivsk.

E-mail:
technot needed texteditoranother not needed text@dystlabdummy text.store

Telegram:
https://t.me/techeditor

Dystlab™ — торговельна марка, зареєстрована в Державному реєстрі свідоцтв України на знаки для товарів і послуг 26.02.2018, свідоцтво № 238304. Власник: фізична особа-підприємець Артьомов В. Є., ЄДРПОУ/ІНН: 3003314690.