C++ Builder

Learn How To Use constexpr In Modern C++ With C++Builder For Windows Development

In this tutorial, you will learn how to utilize constexpr variables and constexpr functions. The principal idea is the performance enhancement of applications by doing calculations at compile time rather than run time. The purpose is to allocate time in the compilation and save time and run time. The constexpr keyword was introduced in C++11 and improved in C++14 and C++17. constexpr specifies that the value of an object or a function can be evaluated at compile-time and the expression can be used in other constant expressions. A compiler error is raised when any code tries to alter the value. Unlike const, constexpr can also be applied to functions and class constructors. constexpr symbolizes that the value or return value is constant and where possible is calculated at compile time. The primary difference between const and constexpr variables is that the initialization of a const variable can be deferred until run time. A constexpr variable must be initialized at compile time. Moreover, all declarations of a constexpr variable or function must have the constexpr specifier. constexpr float x = 42.0; constexpr float y{108}; constexpr float z = exp(5, 3); constexpr int i; // Error! Not initialized int j = 0; constexpr int k = j + 1; //Error! j not a constant expression constexpr float x = 42.0; constexpr float y{108}; constexpr float z = exp(5, 3); constexpr int i; // Error! Not initialized int j = 0; constexpr int k = j + 1; //Error! j not a constant expression With C++17, we can estimate conditional expressions at compile time. The compiler is then able to eliminate the false branch. template auto get_value(T t) { if constexpr (std::is_pointer_v) { return *t; } else { return t; } } templatetypename T> auto get_value(T t) {     if constexpr (std::is_pointer_vT>) {         return *t;     } else {         return t; } } You can do more amazing things with if constexpr. Be sure to check out these workshops: constexpr Functions A constexpr function is one whose return value is computable at compile time when consuming code requires it. A constexpr function or constructor is implicitly inline. constexpr int method_call(int a, int b) { return a * b; } constexpr int method_call(int a, int b) {     return a * b; } Example The following sample shows constexpr variables, functions and several use cases #ifdef _WIN32 #include #else typedef char _TCHAR; #define _tmain main #endif #include #include #include constexpr int method_call(int a, int b) { return a * b; } constexpr auto degrees_to_radians(const double degrees) { return degrees * (M_PI / 180.0); } constexpr int sum(int n) { if (n > 0) { return n + sum(n – 1); } return n; } template auto get_value(T t) { if constexpr (std::is_pointer_v) { return *t; } else { return t; } } int _tmain(int argc, _TCHAR* argv[]) { constexpr int i = 1 + 2; constexpr int j = method_call(5, 10); constexpr auto radians = degrees_to_radians(90); constexpr auto sum_one_to_ten = sum(10); int a = 5; int* pa = &a; int at = 5; int* pt = &at; auto value_a = get_value(a); auto value_pa = get_value(pa); std::cout 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 […]

Read More

Leveraging High DPI with Ray Konopka – DelphiCon 2020

Have you ever accessed a website on your mobile device and found that it was formatted for desktop and nearly unreadable on a 5″ screen?  Similar problems occur for users running high-DPI screens. As 4K screens proliferate and the consumer pressure for 8K grows, it’s important to adjust user interfaces to prevent forms and controls from becoming unreadably small on high-resolution monitors.  RAD Studio 10.3 Rio and Rio Update 2 introduced enhanced controls for high-DPI applications to remedy this problem and Ray Konopka of Raize Software, Inc. is here to teach us how to maximize their advantages. Just seven days away, Leveraging High DPI in VCL Applications is a must-see talk for all developers, hobbyists, and RAD Studio enthusiasts looking to gain new techniques to stay relevant in our changing software landscape. 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 High-DPI knowledge and leave with a greater understanding of Delphi web applications. 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 How To Use C++ Lambda Expressions In C++17 With C++Builder

C++ got lots of additions throughout C++11, C++14 and C++17. Currently, C++ is a completely different language than it use to be. This Modern C++ post explains how to use the Standard Template Library and the most important features of the C++17 that will greatly help you write readable, maintainable, and expressive code! One of the new features of C++11 was lambda expressions. Throughout C++11, C++14, and C++17, the lambda expressions got some new additions that made lambda expression even more powerful.  If you do not know what lambda expression is, here is the answer: Lambda expressions or lambda functions construct closures. A closure is a very generic term for unnamed (temporary) objects that can be called like functions and can capture variables in scope. Lambda expressions are a great way to help to make code generic and tidy. Lambda expressions can be used as parameters for real generic algorithms to specialize in what those achieve when processing specific user-defined types.  With lambda expressions, we can encapsulate code to call it later, and that also might be somewhere else because we can copy them around.  Or we can also encapsulate code to call it multiple times with different parameters. Let’s have a real example: #ifdef _WIN32 #include #else typedef char _TCHAR; #define _tmain main #endif #include #include using namespace std; int _tmain(int argc, _TCHAR* argv[]) { string hello = “C++”; string world = “17”; auto add_things = [](auto a, auto b) { return a + b; }; auto i = add_things(1, 2); auto s = add_things(hello, world); cout 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 #ifdef _WIN32 #include #else typedef char _TCHAR; #define _tmain main #endif   #include #include   using namespace std;   int _tmain(int argc, _TCHAR* argv[]) {     string hello = “C++”;     string world = “17”;       auto add_things = [](auto a, auto b) { return a + b; };       auto i = add_things(1, 2);     auto s = add_things(hello, world);   cout i endl; cout s endl;   cout [](auto a, auto b){ return a + b; }(2, 2) ‘n’;       system(“pause”);       return 0; } Pay attention to this line: auto add_things = [](auto a, auto b) { return a + b; }; auto add_things = [](auto a, auto b) { return a + b; }; This is easy to use, just like any other binary function. As we defined its parameters to be of the auto type, it will work with anything that defines the plus operator (+), just as strings do. And here we are using the lambda expression and printing the output to the console: auto i = add_things(1, 2); auto s = add_things(hello, world); cout auto i = add_things(1, 2); auto s = add_things(hello, world);   cout i endl; cout s endl; We do not need to store a lambda expression in a variable to utilize it. We can also define it in place and then write the parameters in parentheses just behind it (2, 2): cout cout [](auto a, auto b){ return a + b; }(2, 2) ‘n’; As you can see this is the syntax for lambda expressions. The shortest lambda expression possible is []{}, it just accepts no […]

Read More

[InfoGraphic] DevOps, Development and RAD Studio

DevOps is a term I’m hearing more and more during customer conversation, and I am often sharing the different ways that Delphi, C++Builder and RAD Studio programming supports DevOps. (Keep reading – free infographic below) The term DevOps originates back to around 2008/9 when the two worlds of Development and Operations were traditionally stereotypes as Dev V Ops, with typical exchanges like “It’s not my machines, it’s your code!” – “No, it’s not my code it’s your machines!”. These stereotypes were built from friction found in the key business requirement for almost any system – making changes! The ability to rapidly make changes is important if you want to stay ahead of the competition. RAD developers are used to Agile development and being able to create changes quickly, however, getting them deployed needs Operations. To the Operations team, making changes brings a high-risk of an outage, but this prevents innovations from being pushed in a timely manner. This conflict is something that DevOps acknowledges and tries to breakdown through new ways of working that bring both sides closer together. Over the years, the two worlds of Dev and Ops have had to start thinking more like each other, including, how to get feedback from live environments to find issues that appear in the code. Agile, and DevOps like to re-use and expand, so rather than giving a full-blown commentary on how RAD Studio supports Delphi and C++ Builder developers today, let me keep it simple and say that the libraries, components, toolchains (and more) found in RAD Studio, and our wider partner ecosystem, provide broad support to both Developers and Operations teams who need to communicate and share what is happening in the field. The component-based architecture and cross-platform libraries that work across multiple systems are the perfect foundation stone for rapid agile development, that can be supported simply. But finally, a picture paints a thousand words. This is just a snapshot of the RAD eco-system, there is too much to put everything on here, but I hope this gives a flavor of just the tip of the iceberg, and how the RAD Studio IDE, and the Delphi and C++Builder languages and libraries are enabling development teams the world over to support DevOps today. RAD Studio DevOps InfoGraphic Download Infographic PDF

Read More

Learn How To Quickly Animate, Apply Image Effects, Transition Effect To Your Delphi And C++ FireMonkey Apps

Animation, Effects and Transition are the words applied mostly to the Film Industry and those days were gone. But these become the basic expectation from the customer for any Mobile, Desktop, Web Applications. A simple meme requires animations to convey a message more creatively. Will you miss to provide such a feature in your Delphi/C++ Application to wow your customers? This post will provide a quick overview of animation, Image Effects, Transition, and Direct how to do the same in FireMonkey Applications. Animation: Animations modify property values over time. They can be started automatically or manually, both with an optional delay. After the animation has run its course over the defined time period, it can stop, start over, or do the same but in reverse. Kinds of Animation : The provided subclasses of TAnimation fall into three categories: Interpolations from a start value to an end value: TIntAnimation changes any property that is an integer. TFloatAnimation changes any property that is a real number, like position (X, Y, and Z axes must be done separately), rotation, and opacity. TRectAnimation changes the location of the four edges of a TBounds property. TColorAnimation changes any string or integer property that contains a color, including those of type TAlphaColor (which is actually a Cardinal number), by modifying the red, green, blue, and alpha values of the color. TGradientAnimation changes a gradient (type TGradient) by modifying the colors of each point that defines the gradient. TBitmapAnimation transitions from a starting bitmap image to another by drawing the final image (type TBitmap) with increasing opacity, causing it to fade into view. Interpolating through a series of values, not just two: from the first to the second, from the second to the third, and so on: Stepping through a list without interpolation: TBitmapListAnimation works like a timed slideshow, with all images combined horizontally into a single bitmap. With a fast frame rate (short duration and/or many images), it looks like a movie. Animation Type Controls how Interpolations is applied(Start and End). Image Effects: The FireMonkey built-in ImageFX engine provides over 50 GPU-powered effects. These effects are nonvisual components that can be found in the Effects category on the Tool Palette. All the provided effects can be simply enabled or disabled by setting the Enabled flag from the Form Designer, or programmatically. To know More about the Kinds of effects Check here Transition Effects: FireMonkey includes over twenty image transition effects, in which source pixels are progressively transformed into a target bitmap image, from simple fades to fancy banded swirls. The progress of the transformation is deterministic and can be set to an arbitrary percentage. This percentage can be animated to transition over time. To animate the progress of the transformation, see Apply an Animation Effect to a Property of an Image Effect. I guess, You might got rough idea on Animation, Effects, Transition Effects. Watch this Video, Delphi Skill Sprint – Using Effects, Animations and Transitions on FireMonkey shown below for Demonstration. Check this video for more demonstration on the same topic which covers FMX TTabControl Transitions as well.

Read More

Why C++Builder? Check Out The Advantages Of A C++ Developer On Windows

C++ has consistently dominated “Top Programming Languages” lists worldwide this year. With such a strong demand, C++ developers are well-positioned to experience a good problem: too much work. You can join the presenter and C++Builder Product Manager, David Millington, to explore the features and functionality that set C++Builder apart by helping C++ developers worldwide build stunning apps faster. Additionally, get an exclusive sneak peek into the powerful updates coming soon to C++Builder. David Millington is a long-time C++ and Delphi developer. Originally from Australia, he now lives in far north Europe, a decision he loves every summer when he has 22 hours of daylight, before deciding he’s crazy every winter with 22 hours of night. Since joining Embarcadero in 2016, he has worked as the senior product manager for C++, the RAD Studio IDE and debugger. Embarcadero tools are built for elite developers who build and maintain the world’s most critical applications. Our customers choose Embarcadero because we are the champion of developers, and we help them build more secure and scalable enterprise applications faster than any other tools on the market. In fact, ninety of the Fortune 100 and an active community of more than three million users worldwide have relied on Embarcadero’s award-winning products for over 30 years. In the tutorial below you see in more details about the advantages of the C++ builder. Not using C++Builder yet? Head over and download the free trial of C++Builder today!

Read More

Quickly Build Powerful Python Modules In Delphi Using Python4Delphi Sample App

A Module is a file containing Python definitions and statements similar to the unit file in Delphi. To learn more about Python modules check this tutorial. How to create such Python Modules in Delphi using Python4Delphi components? This post will guide you. You can also use Python4Delphi with C++Builder. Python4Delphi Demo5 Sample App shows how to create a Module, add a routine to that module, Import the module in a python script, and access the added routine. You can find the Demo5 source on GitHub. Prerequisites: Download and install the latest Python for your platform. Follow the Python4Delphi installation instructions mentioned here. Alternatively, you can check out this video Getting started with Python4Delphi. Components used in Python4Delphi Demo5 App: TPythonEngine: A collection of relatively low-level routines for communicating with Python, creating Python types in Delphi, etc. It’s a singleton class. TPythonGUIInputOutput: Inherited from TPythonInputOutput (which works as a console for python outputs) Using this component Output property you can associate the Memo component to show the Output. TPythonModule: It’s inherited from TMethodsContainer class allows creating modules by providing a name. You can use routines AddMethod, AddMethodWithKW to add a method of type PyCFunction. You can create events using the Events property. TMemo: A multiline text editing control, providing text scrolling. The text in the memo control can be edited as a whole or line by line. You can find the Python4Delphi Demo5 sample project from the extracted GitHub repository ..Python4DelphiDemosDemo05.dproj. Open this project in RAD Studio 10.4.1 and run the application. Implementation Details: PythonEngine1 component provides the connection to Python or rather the Python API. This project uses Python3.9 which can be seen in TPythonEngine DllName property. It Is assigned with InitScript which import sys module and prints the Python.Dll version, copyright information to Memo2 using this InitScript. import sys print(“Python Dll: “, sys.version) print(sys.copyright) print() PythonGUIInputOutput1 component provides a conduit for routing input and output between the Graphical User Interface (GUI) and the currentlyexecuting Python script. PythonModule1 with Module name spam is created. During PythonModule1Initialization a method spam_foo is added to the Module. And the definition of the method is included in the same unit file. Logically a python module is created and its methods were created using this PythonModule. Later this can be imported into your python script wherever necessary. function spam_foo( self, args : PPyObject ) : PPyObject; cdecl; begin with GetPythonEngine do begin ShowMessage( ‘args of foo: ‘+PyObjectAsString(args) ); Result := ReturnNone; end; end; procedure TForm1.PythonModule1Initialization(Sender: TObject); begin with Sender as TPythonModule do begin AddMethod( ‘foo’, spam_foo, ‘foo’ ); end; end; function spam_foo( self, args : PPyObject ) : PPyObject; cdecl; begin   with GetPythonEngine do     begin       ShowMessage( ‘args of foo: ‘+PyObjectAsString(args) );       Result := ReturnNone;     end; end; procedure TForm1.PythonModule1Initialization(Sender: TObject); begin   with Sender as TPythonModule do     begin       AddMethod( ‘foo’, spam_foo, ‘foo’ );     end; end; Memo1, used for providing the Python Script which imports spam (PythonModule1), accesses the method spam.foo and the method shows the output. Buttons to perform the execution, load script from, and save the script to file. On Clicking Execute Script Button the script import spam print (spam.foo(‘hello world’, 1)) is executed. Python4Delphi Demo5 Check some of the tutorials available for Python4Delphi here

Read More

Learn How To Create A RAD Server With “David I” Intersimone In Delphi And C++

Embarcadero’s RAD Server provides a turn-key application foundation for rapidly building and deploying services-based applications using Delphi and C++Builder. RAD Server supports the REST (Representational State Transfer) protocol with JSON (or XML) parameter passing and return results. You can publish APIs, manage users and devices that are connected to the RAD Server, capture analytics about the use and users of applications, connect to local and enterprise databases using the FireDAC components and connect with Internet of Things (IoT) devices. RAD Server also supports user authentication, push notifications, geolocation, and data storage. Throughout the RAD Server documentation, source code, and in this technical paper, you’ll see references to EMS (Enterprise Mobility Services). EMS was the original name for the product, technologies, components and wizards that are now included the RAD Server product. With RAD Server’s wizards, components, and tools you can quickly develop new middleware and backend applications or migrate your existing Delphi and C++Builder client/server applications to a RAD Server based application to run on a server or in the cloud. You can publish your endpoints for REST calls from desktop, mobile, console, web and other types of applications. RAD Server comes with a full set of tools, components, database connectivity and interfaces that you will rely upon in building your service applications. RAD Server applications can be deployed on top of Microsoft Windows IIS and Apache web servers, and you can deploy your Delphi-based services to Linux Intel 64-bit servers. Download the full eBook and then check out the video below. Join RAD Studio expert “David I” and learn how to rapidly design, build, debug and deploy services-based solutions using RAD Studio and RAD Server. Want to learn more? Check out more information about RAD Server over on the Embarcadero site.

Read More

Free C++ Bootcamp To Quickstart Your C++ Development

Check out the 5-days C++ boot camp! Within this Bootcamp, you get over 10 hours of free training on C++ Builder. What topics this do Bootcamp cover? Building your first application with C++ Builder Creating fast, responsive user interfaces with animations and effects C++11 chat with C++ Experts C++11 Language Deep Dive C++ Game Development Stepping up to Mobile with Q&A for the Bootcamp In this first session, you learn how to create C++ applications, debugging the project, and exploring the features of C++ Builder. For instance, disabling the classic Borland compiler or changing compilation options. Furthermore, there is a short workshop on C++ language itself which covers C++ 11 features and new functions in C++11. Also multithreaded programming in the C++ workshop. When it comes to C++ Builder, you get amazing libraries for instance Parallel Programming library which helps you to process a big amount of calculations efficiently. Be sure to check out the whole Bootcamp sessions!

Read More

Learn How to Run A Simple Python Script In Delphi Application Using Easy Python4Delphi Sample App

How about combining the strength of Delphi and Python for your applications to provide first-class solutions for your customer needs? Thinking about how to do it? Don’t worry! Python4Delphi does for us. Python for Delphi (P4D) is a set of free components that wrap up the Python DLL into Delphi and C++Builder. They let you easily execute Python scripts, create new Python modules and new Python types. This post will guide you on how to use these components, create a VCL application, run a simple python script in it, and gets the output. Python4Delphi Demo1 Sample App shows how to run a Python Script by typing the python code in a Memo, execute and populate the result in another Memo. You can find the Demo1 source on GitHub. Prerequisites: Download and install the latest Python for your platform. Follow the Python4Delphi installation instructions mentioned here. Alternatively, you can check out this video Getting started with Python4Delphi Components used in Python4Delphi Demo1 App: 1.TPythonEngine: A collection of relatively low-level routines for communicating with Python, creating Python types in Delphi, etc. It’s a singleton class. Some of the key properties for the component listed here. AutoLoad: Enable this property to load the python DLL automatically. It defaults to true. AutoUnload: Enable this property to unload the python DLL automatically. It defaults to true. DllName: By default, it reflects the latest e.g. python39.dll. But you can provide your registered version. DllPath: Physical location of the Python DLL. InitScript: You can provide the python script here to execute implicitly. IO: Associate the TPythonGUIInputOutput component to this property. RegVersion: Registered python version e.g 3.9. UseLastKnownVersion: If you want to use the latest registered Python version installed set this property to True. 2.TPythonGUIInputOutput: Inherited from TPythonInputOutput (which works as a console for python outputs) Using this component Output property you can associate the Memo component to show the output. MaxLineLength: Maximum character length per line. MaxLines: Maximum python script lines can be executed using this component. OutPut: Associate the Memo component to show the output. RawOutput: Produce the result as raw output. UniCodeIO: Set true to provide Input and output as Unicode. 3.TMemo: A multiline text editing control, providing text scrolling. The text in the memo control can be edited as a whole or line by line. You can find the Python4Delphi Demo1 sample project from the extracted GitHub repository ..Python4DelphiDemosDemo01.dproj. Open this project in RAD Studio 10.4.1 and run the application. Implementation Details: PythonEngine1 provides the connection to Python or rather the Python API. This project uses Python3.9 which can be seen in TPythonEngine DllName property. PythonGUIInputOutput1 provides a conduit for routing input and output between the Graphical User Interface (GUI) and the currentlyexecuting Python script. Memo1 used for providing the Python Script and Memo2 for showing the output. Buttons to perform the execution, load script from, and save the script to file. PythonGUIInputOutput1‘s property Output to Memo2. On Clicking Execute Button the script strings are executed using the below code. PythonEngine1.ExecStrings( Memo1.Lines); PythonEngine1.ExecStrings( Memo1.Lines); Load the script to the Memo1 from a file using the code with OpenDialog1 do begin if Execute then Memo1.Lines.LoadFromFile( FileName ); end; with OpenDialog1 do begin   if Execute then     Memo1.Lines.LoadFromFile( FileName ); end; Save the Script to the file using the code, with SaveDialog1 do begin if Execute then Memo1.Lines.SaveToFile( FileName ); end; with SaveDialog1 do […]

Read More