Extensions for TMS WEB Core for Delphi
1. Introduction TMS WEB Core is a framework that allows the user to write JavaScript web client applications with the Object Pascal language. Therefore the Object Pascal code is transpiled to JavaScript with the pas2js compiler . TMS WEB Core supports the three IDEs Embarcadero RAD Studio with Delphi, Microsoft Visual Studio Code and Lazarus. This article is primarily concerned with Delphi and shows four options to extend the TMS WEB Core product: Creating design-time packages Writing custom WEB Core components Using & registering base web form classes Registering custom Frames 2. Demo The above mentioned options are practically shown in the demo DemoPackage (download here) which contains a run-time package, a design-time package, a TMS WEB Core application and a VCL application. 3. Packages Delphi projects can contain packages, either for regular programs and for the IDE. A package is a Delphi specific library, similar to a DLL (Dynamic Link Library) on Windows. Packages end with the extension .BPL (Borland Package Library) and are created by the compiler after compilation. When starting an application, the packages are loaded statically. We have to differentiate between two sorts of packages. These are run-time packages and design-time packages. 3.1. Run-time Packages A run-time package is a library that includes parts of the source code and provides parts of the functionality of the application. Instead of having one single executable, it is split into a small executable and multiple packages. 3.2. Design-time Packages Design-time packages are used by the Delphi IDE to make components load dynamically. Therefore components must be registered. Doing this, the IDE tool palette will list the components and this allows the designer to display the components. It is good practice to split the code into run-time code for the run-time package and register code (and any other code that might be only needed and used at design-time) for the design-time package. This design-time package for this demo is DemoPackageIDE.dproj. 3.3. How to set design-time and run-time packages The options of a project can be set in the so called “Project Options”. There is a radio button in the section “Description”, in which the options “Run-time only” and “Design-time only” can be selected. The option “Design-time and Runtime” can be selected, but is as mentioned above not recommended. 3.4. Build control It is also recommended to select “Explicit rebuild” since the option “Rebuild as needed” often leads to problems with packages that are distributed over several project groups. 4. Writing custom TMS WEB Core components The demo contains the unit MyFloatEdit with the component TMyFloatEdit which is a small improvement of a TWebEdit. 4.1. Registering a Component The Delphi IDE calls all public procedures named “Register” from design-time packages. These procedures are called when the design-time package is loaded. Inside a Register procedure components can be registered. The Demo shows how this looks like: interface procedure Register; implementation procedure Register;begin RegisterComponents(‘My TMS WEB components!!’, [TMyFloatEdit]);end; 4.2. DesignIDE package In order to call RegisterComponents it is necessary to require the DesignIDE package in a Designtime package. The Demo shows this: requires… DesignIDE,… 4.3. Platforms In order to register a component the Delphi designer needs to be informed which platforms the component shall be used for (e.g. Win32, Win64 and WEB). In the Delphi IDE all TMS WEB Core projects are treated […]
