TMS Software. All-Access

Curve Fitting with FNC Math Components

In this article, we’ll show how to implement curve fitting with FNC math components presented in version 3.2 of TMS Analytics & Physics library, most importantly, with little to no code! Curve fitting (approximation) is a mathematical method of finding a math expression (function) that fits best to some discrete data (series of points). Commonly, we need the following three ingredients to implement the curve fitting: Discrete data (a series of points) to fit. A set of functions (basis functions) to construct the curve. A method of solving the fitting problem (optimization algorithm). Let’s go through the FNC components for these three elements. The first component is TFNCDataSource1D. The component provides data for curve fitting and has the following published properties: Data (TDataCollection1D) – a collection of points. Each collection item has two properties of real type: ‘V’ – the value of the variable; ‘F’ – the value of the function. DataCount (integer) – the number of points in the collection (read-only). With standard Delphi IDE tools for collection editing, we can add and delete points, edit values of the points in design time. There is a binding component to show the data on an FNC chart – TFNCData1DPlotter. It has two primary published properties: Data (TFNCDataSource1D) – a data source to show on the chart. Chart – a chart to show the data. When assigning an FNC chart to the Chart property in design time, the plotter component creates a series for the chart. You can tune the series’ properties to get the appropriate data representation. In the picture below, we showed an example of data, drawn with the data plotter. The second ingredient for curve fitting is the set of basis functions. We’ll use the TFNCLinearConstructedBasis1D component. This component provides the easiest way to get a set of functions for constructing the fitted curve. The main published properties of the component are the following Variable (TVariableProperty) – provides the name of the variable for the basis functions. Coefficient (TVariableProperty) – provides the name of the coefficient for the fitting problem. Kind (TBasisKind) – the type of predefined basis functions. Order (integer) – number of basis functions for approximation. Expression (string) – read-only math expression of the constructed function. Parameter (TParameterCollection) – a set of parameter values for parametric basis functions. With the Kind property, you can select the appropriate basis functions for building the fitted curve: polynomials, Taylor series, exponents, Fourier series, exponential functions. The Order property sets up the number of basis functions to build the curve. Here is an example of the component’s properties, shown in the Object Inspector. The last component we need to complete curve fitting is TFNCApproxFunction1D. This component joins a data source with a basis and implements the least-squares approximation algorithm. It has the following published properties: DataSource (TFNCDataSource1D) – a data source for approximation. Basis (TFNCBasis1D) – a basis for approximation. Formula (TBaseFormulaProperty) – read-only formula of the curve. Expression (string) – read-only math expression of the fitted curve. When you assign the data source and the basis properties, the component runs the approximation algorithm and evaluates the formula and the expression properties, as shown in the picture below. The TFNCApproxFunction1D is a descendant of the TFNCBaseFunction1D component. So, you can draw the curve on an FNC chart as described in […]

Read More

FNC wishes the VCL Delphi community a merry Christmas!

Intro FNC was born in 2016 and with it, a lot of great opportunities and ideas. We started with TMS FNC Chart, followed by TMS FNC UI Pack only 4 months later! The typical components such as a grid, treeview, planner and many more are included as you would expect in a UI component set. In April 2020, with TMS FNC Maps, we introduced a brand new way to add and work with mapping/routing services in your application. Today we have a wide variety of visual and non-visual components and libraries to enhance your application. The latest addition to the FNC family, named TMS FNC WX Pack, provides access to a whole new world of JavaScript/HTML based libraries and components to Delphi. All of this would not be possible without a solid foundation, a component structure that is reliable as well as extensible. Solid Structure The architecture needed to be solid, robust as well as extensible. Our initial idea was to create a base component for each product separately, but not long after, we abandoned the idea and immediately thought out of the box and created TMS FNC Core. TMS FNC Core was the foundation we created starting with a custom control class and some utility functions. Over the years TMS FNC Core grew into a versatile base foundation for creating cross-platform and cross-framework custom controls. This includes VCL, FMX, LCL and WEB frameworks. Today we focus on a showcasing TMS FNC Core for VCL.  Working on FNC components and the TMS FNC Core foundation on a daily basis and looking back at beginning made us realize that TMS FNC Core is much more than just a foundation. It’s actually capable of doing powerful things with little to no code. The following example demonstrates what TMS FNC Core alone is capable of. No need to install additional components, just download, install TMS FNC Core, plugin the code and experience the true power of FNC. Merry Christmas Out of all the features TMS FNC Core has to offer, we picked a couple of important ones: PDF export, SVG and asynchronous file download support. The code snippet below shows how to download an SVG, export it to PDF. Not more than 25 lines of code went into this sample, with a very nice and warm result, especially during this time of the year! uses VCL.TMSFNCCloudBase, VCL.TMSFNCTypes, VCL.TMSFNCPDFLib, VCL.TMSFNCGraphicsTypes; procedure TChristmasForm.GenerateChristmasWishes; begin TTMSFNCCloudBase.DownloadFileFromURL(‘https://tmssoftware.com/site/img/merry%20christmas.svg’, procedure(const ARequestResult: TTMSFNCCloudBaseRequestResult) var b: TTMSFNCBitmap; p: TTMSFNCPDFLib; begin p := TTMSFNCPDFLib.Create; b := TTMSFNCBitmap.CreateFromStream(ARequestResult.ResultStream); try p.HeaderSize := 100; p.HeaderFont.Size := 24; p.HeaderFont.Style := [TFontStyle.fsBold]; p.HeaderFont.Name := ‘Lucida Handwriting’; p.HeaderFont.Color := MakeGraphicsColor(156, 41, 41); p.Header := ‘tmssoftware.com wishes you a’; p.Footer := ”; p.BeginDocument(‘Christmas.pdf’); p.NewPage; p.Graphics.DrawImage(b, p.MediaBox); p.EndDocument(True); finally b.Free; p.Free; end; end); end; Download TMS FNC Core today, explore the capabilities!. Found something yourself that’s worth sharing? Please let us know, we are excited to find out what you have created, in which way you are using FNC. TMS and FNC wishes you all the best and a merry Christmas!

Read More

Advanced FNC Math Components

In version 3.2 of the TMS Analytics & Physics library, we’ve introduced new FNC Math components. The components allow easy development of math applications with all the advantages of the Delphi IDE. The base concepts of the math components have been described in the previous article. In this article, we’ll introduce several advanced components for designing more complicated math applications. With the base components TFNCFunction1D, TFNCDerivative1D, and TFNCIntegral1D we can evaluate functions, derivatives, and integrals of math expressions. Let’s consider the following component: TFNCFunctionDerivative1D – introduces a symbolic derivative of an FNC function; allows evaluating the derivative for the specified variable value. The component provides the following published properties: Variable (TVariableProperty) – a variable specifying the argument of the function. D (TVariableProperty) – a variable specifying the differential. Functional (TFNCBaseFunction1D) – a differentiable FNC function. Formula (TFormulaProperty) – read-only formula denoting the resulting math expression of the derivative. As one can see, this component is like the TFNCDerivative1D, but the Functional property now is of TFNCBaseFunction1D type. This means that we can assign any appropriate function to the property. The component will trace the functional’s change and re-evaluate the derivative automatically. Let’s start developing an advanced FNC math application. Put a TFNCProvider on the form and create three parameters ‘A’, ‘B’, and ‘L’. Add new TFNCFunction1D and TFNCFunctionDerivative1D components. Assign required properties to the function as described in this article. Add an FNC Chart and two plotters for both components (the function and the derivative). Then connect the derivative component with the function, assigning its Functional property. Finally, input a simple math expression, say ‘5*sin(x)’, into the Formula property of the function. Our math application at the design time is shown in the picture below: Then we can add a text box, allowing the user to input a math expression, and a button with the following simple event handler: procedure TForm1.Button1Click(Sender: TObject);var  f: string;begin  f:= Edit1.Text;   FNCFunction1D1.Formula.Formula:= f;end;   The developed application provides functionality for drawing a user-defined function and its derivative on one chart. An example of the running application is shown in the following picture:   Note that we created only one button with the event handler which assigns the formula to the function. When the formula is changed, the derivative is re-evaluated and the chart is updated automatically. Let’s move on and modify the application to evaluate also the second derivative of the function. It is possible due to the special structure of the FNC math components. As the TFNCFunctionDerivative1D class is a descendent of the TFNCBaseFunction1D, the derivative is considered to be an FNC function. Thus, we can just evaluate a derivative of any other derivative and get the second-order derivative of a function. Putting a new TFNCFunctionDerivative1D component (together with a plotter for the FNC chart) and assigning the functional property to the first derivative component, we get the fully functional application: Finally, let’s consider the TFNCFunctionIntegral1D component. It has the same properties as the TFNCFunctionDerivative1D class, but it evaluates the indefinite integral of a function. Now we can create a single application that provides the evaluation of a user-defined function, its derivatives of the first and the second order, and its integral.  The source code of the demo project for the article can be downloaded from here. To develop your own FNC math application […]

Read More

A Raspmerry Christmas with Miletus

Time flies and we are yet again at the end of the year. With the holidays coming up we thought it would be exciting to put our Miletus technology to the test and see what we can achieve in combination with a Raspberry Pi 4. Christmas is just around the corner so why not have a Christmas tree on a screen with some snowflakes and Jingle Bells playing in the background? Preparation With the plan set we need something to show the Christmas tree on. The screen of our choice is an Adafruit PiTFT Plus 320×240 2.8″ TFT. In theory any ILI9431 display should work with this project if it is correctly hooked up to the Raspberry Pi. We also need a Christmas tree. If we carefully examine the available specification, datasheet and a Python library provided by Adafruit, we can learn that the pixel format is set to 16 bit. This means each pixel’s color is stored in an RGB565 format. With our Christmas tree image converted and stored in a binary file we are ready to get started! With respect to software needed to create the project, all we need here is the latest TMS WEB Core v1.9.6.0 release. Let’s get coding First let’s make the SPI connection. Drop the TMiletusRaspberrySPI component onto the form and leave the default settings. In the form’s OnCreate event set the TMiletusRaspberrySPI.Frequency property (= SPI clock frequency) to 16 MHz. This determines how fast the data can be written, which is important if we want to show a 150 kB image at a reasonable speed. Then open the connection: procedure TForm1.MiletusFormCreate(Sender: TObject); begin   MiletusRaspberrySPI1.Frequency := 16000000;   MiletusRaspberrySPI1.Open; end; Next is screen initialization. We can do this as soon as the SPI connection is ready. By using the TMiletusRaspberrySPI.OnOpen event we can initialize the screen, load the image and after that draw the snowflakes. By using async methods and functions we can wait for each of step to finish before moving onto the next one. procedure TForm1.MiletusRaspberrySPI1Open(Sender: TObject); begin   Await(JSValue, InitScreen);   Await(JSValue, LoadChristmasTree);   StartSnowing; end; InitScreen is sending a number of command and data combinations through SPI to the screen so it can be set up with the correct settings. It is based on values from the datasheet and the example library. For further information on these values please study the linked sources. LoadChristmasTree is responsible for loading the Christmas tree onto the screen. While it is possible to embed the binary image as part of the executable, there are a few reasons against it: First of all, it doesn’t make sense to send the whole image to the web application and from there back to the native shell application. Sending 150 Kb of data between these 2 layers on a small device like a Raspberry Pi can be time consuming. Besides, by making it available as a file it gives the flexibility to change it to a different Christmas tree without modifying or recompiling the application! function TForm1.LoadChristmasTree: TJSPromise; begin   Await(Boolean, TMiletusRaspberryMemoryBuffer.LoadFromFile(‘./xmastree.bin’));   Await(JSValue, Block(0, 0, 239, 319, []));   Await(Integer, GPIOWrite(GPIO_DC_PIN, 1));   Await(Boolean, MiletusRaspberrySPI1.WriteMemBuffer);    Result := EmptyPromise; end; We added a new class called TMiletusRaspberryMemoryBuffer in TMS WEB Core v1.9.6.0. This makes it possible to load a file directly from the local file system (or […]

Read More

TMS Analytics joins TMS Academic family

Perhaps this is our product that suits and targets students & teachers best and finally it is available now as a free edition for students & teachers. TMS Analytics helps students by providing a library to easily evaluate mathematical expressions, calculate symbolic derivatives & integration, solving non linear equations, approximation function calculation and more… This library is fully cross-platform, so it can be used in VCL Windows applications as well as FireMonkey applications for Windows, macOS, Linux, Android & iOS. We encourage and hope that students will discover & learn to appreciate Delphi even more when having TMS Analytics in their arsenal of tools.  While you are visiting our academic offerings, check also following products available free for students & teachers: TMS VCL UI Pack: extensive UI controls library for VCL Windows applications TMS WEB Core: Object Pascal RAD component based web client development  TMS FNC UI Pack: extensive UI controls library for both VCL Windows applications & FireMonkey cross-platform applications TMS Aurelius: ORM framework for Delphi with full support for data manipulation, complex and advanced queries, inheritance, polymorphism, and more TMS Flexcel for VCL/FMX: Powerful, extensive & flexible component suite for native Excel report & file generation & manipulation  Also in the coming year 2022, we want to extend our academic offerings! Let us know what products you look forward to the most to join the TMS Academic family. Our team is listening!

Read More

‘How it works’ video series

With this blog we want to announce our new series of ‘How To” videos, presented by our colleague Holger Flick. In these video series you will learn how you can achieve basic interesting functionality with little to no code! Most of the time developers are blocked in a major project, just because of a little piece of information that is missing! This can be a common problem that keeps happening. That is why FlixEngineering and tmssoftware.com will work together to provide you hands-on solutions by explaining this step by step. Unlike other videos these series will not solve complex problems, here we will focus on simple “how to” questions! Subscribe to our YouTube channel and stay tuned for our first “How it works” video:   Happy Holidays!

Read More

High DPI support for all FNC UI Pack Components

High DPI In this update of the TMS FNC UI Pack the main focus was the implementation of high DPI in our controls. Some components already had high DPI support since the previous update. Now all of our components are scaled to the monitor and have clear lines and fonts. This is implemented in design-time for Delphi 11 and in run-time from 10.3 onwards due to the integrated support. Design-Time Editors Introduced in the previous update are the improved editors which have an adjustable theme, high DPI support and available in Delphi and TMS WEB Core for Visual Studio Code. Planner Mode Editor A new addition to the editors is the TMS FNC Planner Mode Editor, which is now registered in design-time. It is possible to configure the mode and the different positions and resources of the planner. The editor is accessible via the mode property or by the configure option in the context menu via the right-click. This update also addresses different fixes and some smaller new features to the product which can be found in the release notes.

Read More

Osaka event about using TMS WEB Core and using REST APIs on Dec 18

On 18 December in Osaka, Japan, there is an event for Japanese Delphi developers interested in using TMS WEB Core and creating REST APIs for use from a TMS WEB Core web client application. The event is offered as a hands-on event, where Delphi developers can bring their laptop and work on projects with TMS WEB Core shown during the event and create REST APIs to be used by the web client app. Some more background information about the organizer of the event and the experience with TMS WEB Core and REST API backends can be found here.  It is of course a great opportunity to meet fellow Delphi & TMS WEB Core developers and exchange tips & tricks among each other. We kindly invite everyone to this upcoming event! Event information and registration is available here: https://ishuprog.connpass.com/event/233617/  TMS customers in Japan will receive an email with information for free entry for this event!

Read More

FNC Math Components in TMS Analytics & Physics 3.2

TMS Analytics & Physics library is a set of classes that provide functionality for building powerful math applications with Delphi. In the new version 3.2 of the library, we introduced special FNC math components. The components bring new possibilities to develop and tune your math application in design-time with standard IDE tools. In this article, we’ll consider the base concepts of the FNC math components and provide information on how to work with functions, derivatives, and integrals. All FNC math components are nonvisual. Each component implements some math concept and provides properties to manipulate and tune it in design- and run-time. Let’s consider the following components: TFNCProvider – creates math environment; allows introducing variables and parameters for function evaluations, symbolic derivatives, and integrals. TFNCFunction1D – introduces a symbolic function of one variable; allows evaluating the function for the specified variable value. TFNCDerivative1D – introduces a symbolic derivative of a math expression; allows evaluating the derivative for the specified variable value. TFNCIntegral1D – introduces a symbolic integral of a math expression; allows evaluating the integral for the specified variable value. To begin any FNC math application we first need to put a TFNCProvider component on the form. The component has two published properties: Variables (TVariableCollection) – a collection of variables that can be used as arguments of functions. Parameters (TParameterCollection) – a collection of parameters that can be used in the math environment to build functions, derivatives, integrals, and other math expressions. When you put a TFNCProvider on the form in design-time, it automatically creates a default variable ‘x’ for your math application. You can change the name of the variable or add/delete variables at design- and run-time. For the simplest math application, the default environment with one variable ‘x’ is enough. So, let’s go forward and consider the next FNC component TFNCFunction1D and its properties: Provider (TFNCProvider) – a math environment for the function. Variable (TVariableProperty) – a variable specifying the argument of the function. Formula (TFormulaProperty) – a formula specifying the math expression of the function. Placing a TFNCFunction1D on the form, it assigns the default value ‘x’ to the Variable property. We need to set up the Provider property and the expression for the Formula property, say ‘5*sin(6*x)’ in the Object Inspector. The resulting properties are shown in the picture below:  The function is ready to use. What can we do with it? The first idea is to draw the function and see what it looks like. We have the TFNCFunction1DPlotter component especially developed for this purpose: TFNCFunction1DPlotter – a binding for an FNC function component and an FNC Chart; allows drawing any FNC function on the chart. The component has several published properties that we can use to tune it and show a function on the FNC Chart: Provider (TFNCProvider) – a math environment for the component. Min (TValueProperty) – the minimal value of the variable range to plot the function. Max (TValueProperty) – the maximal value of the variable range to plot the function. PointCount (Integer) – number of points to plot the function. AFunction (TFNCBaseFunction1D) – a FNC function to plot. AssignLegend (Boolean) – if true, assigns the function’s expression to the serie’s legend. Chart (TTMSFNCChart) – an FNC chart to draw the function. First, we need to assign the appropriate Provider property. The Min […]

Read More

Unit testing comes to TMS WEB Core

Let’s come straight to the point. Writing unit tests is a chore and having unit tests is a blessing. We all want to have the blessing, so with integrated unit testing in TMS WEB Core, we tried to minimize the chore. For unit testing to cover real usage scenarios, it is necessary to run the unit tests on the ‘operating system’ where the web application will run, that is the web browser. After all, all TMS WEB Core apps, and thus your code, will run in the browser, will involve dealing with the browser DOM and browser APIs, it is only logical that a TMS WEB Core unit test runs as a web app in the browser. It also means having the ability to deal with a typical web app world phenomenon and that is asynchronous behavior.  Introducing unit testing now integrated from TMS WEB Core v1.9.5.0. To start a new unit test project, create this from the Delphi IDE wizard and it creates a test project with one unit containing one test class with one test method. It allows you to fully focus on writing the test classes with their test methods. In the project manager, it looks like: and the code generated is: Notice in the code the attribute [TestFixture] on the test classes and the attribute [Test] on the test methods. A class can obviously contain as much test methods as you want and you can register as much test classes as you want with a call to TTMSWEBUnitTestingRunner.RegisterClass(). For the feedback when running the test application, use the Assert class.  When running this application, the test application in the browser behaves in the following way: Asynchronous behavior in the browser Now, how can we deal with typical asynchronous behavior in the browser and still test it properly? Well, for any asynchronous behavior in the browser, decorate the test method using it with the [Async] attribute. Then you can use the await() function to wait for the asynchronous response of the call.  This sample code demonstrates this: TMyTestClassUnit1 = class(TObject) published   //This is an async test method   [Test] [async]   procedure TestAsync; end; procedure TMyTestClassUnit1.TestAsync; var   wr: TWebHttpRequest;   res: TJSXMLHttpRequest;   js: TJSONObject; begin   wr := TWebHttpRequest.Create(nil);   wr.URL := ‘https://download.tmssoftware.com/tmsweb/1.json’;   res := await(TJSXMLHttpRequest, wr.Perform);   js := TJSONObject(TJSONObject.ParseJSONValue(res.responseText));   // response value for userId should be ‘1’   Assert.AreEqual(js.GetJSONValue(‘userId’),’1′); end; Testing JavaScript directly When you use external JavaScript libraries that you also want to involve in a test, there are several ways you can do this. You might have an Object Pascal wrapper class for JavaScript objects that you use in your test method but it could be as simple as calling the JavaScript directly from an ASM code block (a block with embedded JavaScript code within your Object Pascal code).  This is a very simple example of directly calling the JavaScript window prompt function to get a user input: procedure TMyTestClassUnit2.TestIntToStr; var   s: string; begin   asm     s = window.prompt(‘Please give your name’);   end;   Assert.AreEqual(‘Bruno’, s); end; The result in the browser when running this test becomes: A video introduction Follow unit testing step by step as our colleague Holger Flick explains in this YouTube video: Get started Go to the next level of […]

Read More