Noutați

Learn C++ Event Handling In 5 Minutes

In this short tutorial, C++ Product Manager, David Millington, explains what event handlers are and how to use them in your C++ application development.  Overview The event is that something happens.  Event handler – a method that’s called when something happens or is attached to an event. Technical details: an object-method pointer, referring to both the method and object instance on which to call the method. And it can have any signature. Defining Event Handlers In an event receiver class, you define event handlers, which are methods with signatures for instance: return types, calling conventions, and arguments that match the event that they will handle. Firing Events To fire an event, simply call the method declared as an event in the event source class. If handlers have been hooked to the event, the handlers will be called. Be sure to check out other tutorials on C++ Builder here:

Read More

Powerful Native Windows Open Source And Free Python IDE Built In Delphi

Embarcadero’s users understand the scalability and stability of C++ and Delphi, and depend on the decades of innovation those languages bring to development. Ninety of the Fortune 100 and an active community of more than three million users worldwide have relied on Embarcadero’s award-winning products over the past 30 years. Icons by Icons8.com. © 2020 EMBARCADERO INC. ALL RIGHTS RESERVED Legal

Read More

RAD Studio Roadmap November 2020

Embarcadero’s users understand the scalability and stability of C++ and Delphi, and depend on the decades of innovation those languages bring to development. Ninety of the Fortune 100 and an active community of more than three million users worldwide have relied on Embarcadero’s award-winning products over the past 30 years. Icons by Icons8.com. © 2020 EMBARCADERO INC. ALL RIGHTS RESERVED Legal

Read More

Learn To Build A Python GUI For Working with 2D Graphics And The Matplotlib Library In A Delphi Windows App

Drawing graphics programmatically is a very popular task these days. You can easily solve it using Matplotlib library with Python4Delphi (P4D). P4D is a free set of instruments that allows you to work with Python scripts, modules and types in Delphi. In this post, we will look at how to run Matplotlib library using Python for Delphi. With Delphi and C++Builder and Python4Delphi, you can build Python GUI apps for Windows using various Python libraries. Open project Demo1 to run the Python script in Python for Delphi. Use Memo1 for Python script and Memo2 for results. Click Execute button for running the script. Download Demo1 source from GitHub. If you run into a floating point division error when executing the code run MaskFPUExceptions(True); before you call ExecStrings. procedure TForm1.Button1Click(Sender: TObject); begin PythonEngine1.ExecStrings( Memo1.Lines ); end; procedure TForm1.Button1Click(Sender: TObject); begin PythonEngine1.ExecStrings( Memo1.Lines ); end; Python Matplotlib library provides various tools for working with 2D graphics. With this library, you can create graphics, customize legends, style sheets, color schemes, and manipulate images. There are examples of code from the Matplotlib below. Draw a plot You can draw very simple plots with Mathplotlib. Or, if you want, you can change the shape and color of the points in the graphic in different ways. In the following example, we will draw the green triangular points using the argument ‘g^’  in function plot(). import matplotlib.pyplot as plt import numpy as np t = np.arange(0., 5., 0.2) plt.plot(t, ‘g^’) plt.show() import matplotlib.pyplot as plt import numpy as np t = np.arange(0., 5., 0.2) plt.plot(t, ‘g^’) plt.show() Stacked bar chart In this example, we show how to draw a stacked bar plot. We will use the function bar() twice. We need to pass to this function such parameters as labels, values of various categories that need to be displayed, names of labels. Finally, we will set such graphic parameters as title, y-label. import matplotlib.pyplot as plt labels = [1, 2, 3, 4, 5] cat1_means = [14, 39, 30, 19, 54] cat2_means = [43, 62, 52, 51, 29] width = 0.35 fig, ax = plt.subplots() ax.bar(labels, cat1_means, width, label=’Cat1′) ax.bar(labels, cat2_means, width, bottom=cat1_means, label=’Cat2′) ax.set_ylabel(‘Scores’) ax.set_title(‘Scores by product cutegories’) ax.legend() plt.show() import matplotlib.pyplot as plt labels = [1, 2, 3, 4, 5] cat1_means = [14, 39, 30, 19, 54] cat2_means = [43, 62, 52, 51, 29] width = 0.35 fig, ax = plt.subplots() ax.bar(labels, cat1_means, width, label=‘Cat1’) ax.bar(labels, cat2_means, width, bottom=cat1_means, label=‘Cat2’) ax.set_ylabel(‘Scores’) ax.set_title(‘Scores by product cutegories’) ax.legend() plt.show() Draw curves and fill the area In this example, we use the function plot() again to build a graphic of cos(x). Then we fill the area in green color between two curves using function fill_between(). Pass parameters x, y1 and y2 to determine the curve and exclude some horizontal regions from being filled using parameter where. import matplotlib.pyplot as plt import numpy as np fig, ax = plt.subplots() x = np.arange(0, 7 * np.pi, 0.1) y = np.cos(x) ax.plot(x, y, color=’black’) ax.fill_between(x, 0, 1, where=y > 0.75, color=’green’, alpha=0.5, transform=ax.get_xaxis_transform()) plt.show() import matplotlib.pyplot as plt import numpy as np fig, ax = plt.subplots() x = np.arange(0, 7 * np.pi, 0.1) y = np.cos(x) ax.plot(x, y, color=‘black’)   ax.fill_between(x, 0, 1, where=y > 0.75,                 color=‘green’, alpha=0.5, transform=ax.get_xaxis_transform()) plt.show() We got acquainted with some of the Matplotlib library’s features. Go here, […]

Read More

Structured Programming in Delphi – DelphiCon 2020

Have you heard of functional programming but are vague on the details?  Are you ready to expand beyond the object-oriented mindset?  Tomorrow, Nick Hodges, author of Coding in Delphi, will teach us how to harness functional programming techniques to craft beautiful programs in Delphi.  Just one day away, Functional Programming with Delphi is a knowledge-broadening talk you don’t want to miss! DelphiCon 2020 offers ten talks and four expert panels by Embarcadero tech partners and Most Valuable Professionals spanning the range of software from education to industrial database access. Come for the functional programming and leave with a greater understanding of how to maximize performance with Delphi. The conference is free and open to the public. Sign up now by clicking the “Save my seat” button at delphicon.embarcadero.com!

Read More

Learn To Build A Python GUI For Processing Images With Pillow Library In A Delphi Windows App

Are you looking for a simple way to process images programmatically? You can do it with Python for Delphi using Pillow library. Python for Delphi (P4D) is a free tool that allows you to execute Python scripts, create new Python modules and types in Delphi. This post will guide you on how to run Pillow library code using Python for Delphi. You can easily build Python GUI apps using your favorite Python libraries for Windows using Delphi and C++Builder and Python4Delphi. In order to run the Python script in Python for Delphi, open and run project Demo1. Then insert the script into lower Memo, click Execute button, and get the result in upper Memo. You can find the Demo1 source on GitHub. procedure TForm1.Button1Click(Sender: TObject); begin PythonEngine1.ExecStrings( Memo1.Lines ); end; procedure TForm1.Button1Click(Sender: TObject); begin   PythonEngine1.ExecStrings( Memo1.Lines ); end; With Pillow library, you can perform geometric and color transformations. It also allows to cut, copy part of the image and merge several images into one. Let’s take a look at some examples. Open, show, and get image properties First, open the image using function open(). You can get image properties such as format, size, type. from __future__ import print_function from PIL import Image im = Image.open(“test.jpg”) print(im.format, im.size, im.mode) im.show() from __future__ import print_function from PIL import Image im = Image.open(“test.jpg”) print(im.format, im.size, im.mode) im.show() Create thumbnails thumbnail() function allows you to create an image thumbnail. The input parameters of this function are the size of the image that you want to get in pixels. Use save() function to save the image in a specified directory. from __future__ import print_function from PIL import Image import os path = “test.JPG” im = Image.open(path) size = (250, 250) outfile = os.path.splitext(path)[0] + “.thumbnail” im.thumbnail(size) im.save(outfile, “JPG”) from __future__ import print_function from PIL import Image import os   path = “test.JPG” im = Image.open(path) size = (250, 250) outfile = os.path.splitext(path)[0] + “.thumbnail”   im.thumbnail(size) im.save(outfile, “JPG”) Geometrical transformations Function transpose() allows you to perform different geometrical transformations with the image. For example, you can rotate the image by a given angle or flip it horizontally and vertically. from __future__ import print_function from PIL import Image im = Image.open(“test.jpg”) box = (0, 0, 320, 426) region = im.crop(box) region = region.transpose(Image.ROTATE_180) region = region.transpose(Image.FLIP_LEFT_RIGHT) im.paste(region, box) im = im.rotate(45) im.save(“test2.jpg”) from __future__ import print_function from PIL import Image im = Image.open(“test.jpg”) box = (0, 0, 320, 426) region = im.crop(box) region = region.transpose(Image.ROTATE_180) region = region.transpose(Image.FLIP_LEFT_RIGHT) im.paste(region, box) im = im.rotate(45) im.save(“test2.jpg”) Change images colors Now let’s look at how to change image color. Function split() allows you to decompose the image into separate colors and work with each color separately. In the following example first, we split the image into separate parts by color. Then select the area where the green value is less than 150. At the next step, we increase the blue value by 0.5. In the end, we merge everything into a new image. source = im.split() R, G, B = 0, 1, 2 mask = source[G].point(lambda i: i source = im.split() R, G, B = 0, 1, 2 mask = source[G].point(lambda i: i 150 and 255) out = source[B].point(lambda i: i * 0.5) source[R].paste(out, None, mask) source[B].paste(out, None, mask) im = Image.merge(im.mode, source) Now you can make various modifications […]

Read More

Quickly Migrate and Modernize Your Delphi/C++ Apps Using FastReport With Windows High DPI Setup

Display panel manufacturers have packed an increasing number of pixels into each unit of physical space on their panels resulted in the dots per inch (DPI) of modern display panels. In the past, most displays had 96 pixels per linear inch of physical space (96 DPI); in 2017, displays with nearly 300 DPI or higher are readily available. Variety of monitors like SD, Full HD, 4K Ultra HD, 8K Ultra HD in the market. We have laptops, desktops with small screens, and without display scale factor/DPI changes it’s very hard to use it and this can be even more complicated when talking about Full HD, 4K Ultra HD, 8K Ultra HD. Our application should be able to handle them. You cannot be sure what every user prefers. Some common scenarios where the display scale factor/DPI changes are: Multiple-monitor setups where each display has a different scale factor and the application is moved from one display to another (such as a 4K and a 1080p display) Docking and undocking a high DPI laptop with a low-DPI external display (or vice versa) Connecting via Remote Desktop from a high DPI laptop/tablet to a low-DPI device (or vice versa) Making display-scale-factor settings change while applications are running Desktop applications must tell Windows if they support DPI scaling. By default, the system considers desktop applications DPI unaware and bitmap-stretches their windows. By setting one of the Unaware, System, Per-Monitor, and Per-MonitorV2. available DPI awareness modes, applications can explicitly tell Windows how they wish to handle DPI scaling. When updating a System DPI-aware application to become Per-MonitorV2 aware, the code which handles UI layout needs to be updated such that it is performed not only during application initialization but also whenever a DPI change notification (WM_DPICHANGED in the case of Win32) is received. Things to know on migrating your Delphi Application to High DPI ? Set the DPI awareness Mode in Project->Options->Application->Manifest-DPI Awareness and Select Per-MonitorV2. Use Sceen.PixelsPerInch-primaryDispaly DPI Use TVirtualImageList instead of TImageList. Check all custom draw for absolute positions Use Control.CurrentPPI to get Current PPI of Control Mixed Mode for dialogs(SetThreadDPIAwarenesscontext) Use Form events OnBeforeMonitorDPIChanged/OnAfterMonitorDPIChanged. Note: Ensure backward compatibility for your platform and Delphi version of your application. Some of the Delphi And FastReport High DPI Controls: TControl: procedure such as ScaleforPPI, ChangScale, ScaleControlsForPPI helps for High DPI change. TFrxBAseForm: procedure such as UpdateResources, UpdateFormPPI, ProcessPreferences, and Message WM_DPICHANGED helps for FastReport form DPI change. TFrxDPIAwareCustomControl: procedure such as DoPPIChanged, GetScale, and Message WM_DPICHANGED_AFTERPARENT helps for FastReport custom control DPI change. Check out the Video Fast Migration to Windows 10 High DPI, below for Demonstration. Check the latest RAD Studio 10.4.1 Features which includes VCL Style Changes for High DPI.

Read More

Learn How To Use Auto-Typed Variables In C++ For Windows Development

auto-typed variables is a C++11 feature that allows the programmer to declare a variable of type auto, the type itself being deduced from the variable’s initializer expression. The auto keyword is treated as a simple type specifier (that can be used with * and &), and its semantics are deduced from the initializer expression. auto-typed Variables Examples int IntFnc() {} bool BoolFunc() {} char* CharSFunc() {} int _tmain(int argc, _TCHAR* argv[]) { // x is int auto x = IntFunc(); // y is const bool const auto y = BoolFunc(); // w is char* auto w = CharSFunc(); return 0; } int IntFnc() {} bool BoolFunc() {} char* CharSFunc() {}      int _tmain(int argc, _TCHAR* argv[]) {     // x is int     auto x = IntFunc();     // y is const bool     const auto y = BoolFunc();     // w is char*     auto w = CharSFunc();       return 0; } Multi-declarator auto The C++11 standard includes the multi-variable form of auto declarations, such as: int* func(){} int _tmain(int argc, _TCHAR* argv[]) { auto x = 3, * y = func(), z = 4; return 0; } int* func(){}   int _tmain(int argc, _TCHAR* argv[]) {         auto x = 3, * y = func(), z = 4;         return 0; } The restriction with multi-declarator auto expressions is that the variables must have the same base type. For example, the following line of code is well-formed: auto x = 3, y = *(new int); auto x = 3, y = *(new int); because x and y have the same base type : int, while the following code: will generate the error: [bcc64 Error] File1.cpp(11): ‘auto’ deduced as ‘int’ in declaration of ‘x’ and deduced as ‘double’ in declaration of ‘y’. This feature is supported by the Clang-enhanced C++ compilers. Check out all of the modern C++ language features supported in the latest C++Builder for Windows development.

Read More

Learn To Build Modern Enterprise-Grade Native Applications For Windows With RAD Studio

In this webinar, one of the Embarcadero MVP Serge Pilko shows off the RAD Studio against Electron and other JavaScript frameworks for desktop application development. Overview Native desktop development for Windows JavaScript framework-based solutions vs. RAD Studio for Windows Development Electron & Node.js .NET WinForms & WPS vs. Delphi & C++ Builder VCL or FMX JavaScript for Desktop Many JavaScript libraries let you create desktop GUI applications with web technologies like JavaScript, HTML, and CSS. And it is connected to the web easily. With JavaScript desktop development libraries you can’t get the native performance, no native user interface.  Consumes more memory because your JavaScript application needs an engine Source code protection issue Not all enterprise developers are ready to rely on open-source solutions  Delphi & C++ Builder for Desktop A proven tool for Windows desktop development Small executable file size and low memory usage Native application The best performance you can get Thousands of use cases are ready to explore Native look and feel Easy to design and bring the best user experience Be sure to check out the whole session to learn about the benchmarks in action and more about modernizing your applications! Learn more about enhancing your productivity with RAD Studio.

Read More

More TMS WEB Core Tips & tricks

Today we want to bring to your attention two totally different TMS WEB Core features. These little tidbits that can bring your TMS WEB Core web client application from good to great. The first is about handling application termination and the second is about getting something more out of TWebStretchPanel. Application termination For long, handling web application termination was simple: it was not really handled. When there was a reason to handle it server side, software developers came up with the concept of sessions. In a nutshell, when a user first requests a HTML page from the server, a session is started and typically a session timer runs. If the users requests a page update or performs another request from the user, the session timer is reset. If the user does nothing or worse, closes the browser, the server timer runs and when it reaches a predefined time, for example 20 minutes, the session is considered closed and thus stopped. We have all experienced the consequences. You decide to go and grab a cup of coffee, meet a colleague in the coffee room, have an interesting talk that of course takes longer than expected and you return to your desk, want to continue using your web application and you are greeted with a session timeout and need to login again. In the world of modern single-page web client applications with stateless REST backend, this is a lot less likely to occur as it is way less likely to have a reason for server side session management. An easy way to look at it, is that the session state is now kept in the client and the web client application will just perform stateless HTTP(s) requests to a backend when data update or retrieval is needed. And still, even in this much more server resource friendly scenario, developers might have a reason to know when the user closes the web application to save something client or server side. To handle this, modern browsers expose the browser window “unload” and “onbeforeunload” JavaScript event. This event is triggered when the browser window is about to be closed or the user leaves the page via navigation. Other than just handling leaving the web client application, it can also be signalled to the user and a confirmation dialog shown to ask if the user really wants to leave. In TMS WEB Core, taking advantage of this is really simple. In your TMS WEB Core web client application, handle the main form’s OnBeforeUnload event. If you wish to show a confirmation dialog, return the confirmation message text via the parameter AMessage. Note that in Google Chrome, a confirmation message will be shown when the message is not empty but it will contain the standard Google text. For the reason, see: https://bugs.chromium.org/p/chromium/issues/detail?id=587940 Here is a code extract that shows the concept. A simple string variable will determine whether some action is needed before closing or not. This string s is empty by default but during application execution can be set (here via a button click). When this string is not empty, it is used to show a prompt when the user wants to close the application via the form.OnBeforeUnload event and in the form.Unload event it can be effectively handled to do a last action before unloading. […]

Read More