C++ Builder

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 Useful Hints For Working With Styles To Build Visually Stunning Windows Applications

Want to style your Delphi/C++Builder applications with few steps? Want to view and choose your style before applying to your application? Don’t know how to do? This post will guide you. A style is a set of graphical details that define the look and feel of a VCL/FMX application. Similar to a theme in Windows. A style permits you to change the appearance of every part and state of a control.   Where are the styles on your computer? C:UsersPublicDocumentsEmbarcaderoStudio21.0Styles. Plenty of styles available under this folder, you can choose from here. Where can you get other styles from? Use Tools -> Get it Manager -> Styles -> Select one among them and install. After installing these styles can be found under this folder C:UsersPublicDocumentsEmbarcaderoStudio21.0Styles With folder names per platform like -> Android, iOS, macOS, Linux, and Win. Other these styles, we can get some third party Styles from DelphiStyles How to view your styles? Navigate to his folder, C:Program Files (x86)EmbarcaderoStudio21.0binVCLStyleViewer.exe and pass the parameter with the Style name with path. Similarly for FMX Styles use FMXStyleViewer.exe. Alternatively, you can open the style files, by right click-> open with ->Navigate to VCLStyleViewer.exe or FMXStyeViewer Accordingly. How to convert VCL-Styles to FMX- Styles? Open IDE->Tools->Bitmap Style Designer and open the existing VCL styles and then Save the file as FMX style with Option Save as type value “FireMonkey Style” How do I assign a style to the program? Place a TStyleBook component to the form. Double Click and open the style file from the location mentioned above. Save and close the Style Designer. Assign the Stylebook reference to Form StyleBook Property. Use TStyleBook.UseStyleManager property checked when more than one form created from the main form where StyleBook property is assigned. Note: For Dialogs in FMX the styles are not applied, we need to create custom dialogs. How do I assign a style per platform? On Double-clicking the TStyleBook -> Style designer contains the option Platform where you can choose your platforms. How to set styles for multi-platform in a single application? You can use style manager to set the styles at runtime, but we need to take care of checking the platform, and deployment as well. A Simple solution is to use different data modules for each platform and place TStyleBook in each platform, instantiate according to the platform. Check this full video of useful hints for working with styles. Check out the High DPI Styles and VCL Styling Per Control feature introduced in Latest RAD studio 10.4.1

Read More

Installing Component Packages Manually

Sometimes you need to install components manually. Maybe the installer wasn’t updated for your version of Delphi, or it is an open-source library without an installer. Whatever the reason, here is a short guide in addition to what is found in the DocWiki on the topic. I’m going to write this guide around installing the Radiant Shapes Pack available via GetIt. I’m guessing it wasn’t updated to install in 10.4 yet, and while R&D is working on that this is a great opportunity to learn how to install it manually. After installing from GetIt, you will not find it in the IDE, and it is missing from the packages list, which you access from Component 🡆 Install Packages while no project is open This is where all the BPL Packages are listed. Click the Add button and browse to find the BPL C:Program Files (x86)RaizeRadiantShapes1.4BinRadiantShapesFmx_Design270.bpl (If you don’t have that BPL or path for Radiant Shapes, then make sure you installed from GetIt and you can run the installer manually from C:UsersPublicDocumentsEmbarcaderoStudio21.0CatalogRepositoryRadiantShapes-270-1.2InstallerRadiantShapes.exe ) or whatever design-time package you need. This will install the components into the IDE. Many projects have both design time and runtime packages. A design-time package contains the information necessary to install in the IDE, and any special designers, while RunTime packages only contain the code necessary for use during RunTime. You can optionally even ship these packages with your binary to link them at runtime. Next, you need to tell the IDE where to find the DCUs and optionally source files. What if you only have source files? No problem, open and build all the packages at least in Release Mode on each platform the library suports. Then head to Tools 🡆 Options then Language 🡆 Delphi 🡆 Library. Then complete the details for each platform you built and want to support: Selected Platform – Specifies which platform you are providing details for below: Linux 64-bit, iOS 64-bit, Win 32-bit, Win 64-bit, macOS 64-bit, Android 32-bit, Android 64-bit, and/or iOS Simulator. Library Path – This is the path to the Release DCUs. Some people point to their PAS files here, which works, but then you end up recompiling the library more than necessary. Radiant Shapes includes all the DCUs in subfolders off the path C:Program Files (x86)RaizeRadiantShapes1.4Lib Tip: Paste the new path into the edit box before clicking the browse button if you need to browse to a subfolder. Then be sure to click [Add] when you are done. Library Paths Dialog Location of platform specific DCU folders for Radiant ShapesC:Program Files (x86)RaizeRadiantShapes1.4Lib Browsing Path is where you optionally add a path to the source PAS files. This lets you browse out to those source files from the IDE with the Find Declaration context menu item. For Radiant Shapes, the source is found in C:Program Files (x86)RaizeRadiantShapes1.4Source Debug DCU Path allows you to optionally point to the debug version of the DCUs. This is useful if the debug version has additional information or different behaviors. Radiant Shapes doesn’t have special debug DCUs so we don’t need to add anything here. Once you’ve completed these settings for each platform you are good to go! Happy installing!

Read More

Powerful PyDelphiWrapper To Wrap Your Delphi Objects To Python Objects Instantly With FireDAC Sample App

How about wrapping your Delphi Objects to Python Objects with a single line of code? Sounds Interesting? Yes, Python4Delphi has the flexibility to do that using a TPyDelphiWrapper component. This benefits Delphi Developers easily to wrap the existing or new Delphi Objects into Python Objects. This post will guide you on how to wrap a FireDAC TFDTable to a python Object and Manipulates with table data using python scripts. You can also use Python4Delphi with C++Builder. Python4Delphi Demo10_FireDAC Sample App shows how to wrap a Delphi Object(TFDTable, TFDQuery) to Python Object with some Examples as listed. You can find the Demo10_FireDAC 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 Demo10_FireDAC 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. TPyDelphiWrapper: Component that wraps the Delphi Object to Python Object inherited from TEngineClient. It has the capability to store Delphi class registration information, registration for Helper Types(not correspond to Delphi Classes), register python module functions, created event handlers. Wrap, WrapRecord, WrapInterface are the key methods to wrap Delphi Object, Record, and Interface respectively. TSynEdit: Syntax highlighting edit control, not based on the Windows common controls and supported on Windows. For some history check here. How to get and use SynEdit check here. 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. Along with these components TFDConnection,TFDTable,TFDQuery, TDataSource were used. You can find the Python4Delphi Demo10_FireDAC sample project from the extracted GitHub repository ..Python4DelphiDemosDemo10_FireDAC.dproj. Open this project in RAD Studio 10.4.1 and run the application.- Implementation Details: PythonEngine component provides the connection to Python or rather the Python API. This project uses Python3.9 which can be seen in TPythonEngine DllName property. PythonGUIInputOutput component provides a conduit for routing input and output between the Graphical User Interface (GUI) and the currentlyexecuting Python script. PyDelphiWrapper component contains Module and Engine Property which is associated with PythonEngine and modDBFireDAC respectively. In Example 1, SynEditScript1 load the Python script file Example1.py and clicking Execute Button, connected to the database selected in the Combobox, and the script is executed. Example1.py imports the module modDBFireDAC, create an own TFDTable object, and manipulates the table values mentioned in the script. procedure TMain.btnExecuteExample1Click(Sender: TObject); var l_sConnName: String; begin l_sConnName := cobxConnSQLServer.Items[cobxConnSQLServer.ItemIndex]; if self.DBConnectionClosedCheck(l_sConnName) then begin with GetPythonEngine do begin ExecStrings( SynEditScript1.Lines ); end; end; end; procedure TMain.btnExecuteExample1Click(Sender: TObject); var l_sConnName: String; begin l_sConnName := cobxConnSQLServer.Items[cobxConnSQLServer.ItemIndex]; if self.DBConnectionClosedCheck(l_sConnName) then begin    with GetPythonEngine do begin      ExecStrings( SynEditScript1.Lines );    end; end; end; In Example 2, SynEditScript2 loads the Python script file Example2.py and clicking Execute Button, the script is executed. Example2.py imports the module modDBFireDAC shows you how to create a TFDTable object connected to an already created Delphi TFDTable (which may include calculated fields and the like). procedure TMain.btnExecuteExample2Click(Sender: TObject); […]

Read More

Quick Introduction To FireDAC And Its Features For Building Robust Delphi/C++ Builder Database Applications.

FireDAC is a powerful, yet easy-to-use access layer that supports, abstracts, and simplifies data access, providing all the features needed to build real-world high-load applications. FireDAC provides a common API for accessing different database back-ends, without giving up access to unique database-specific features and without compromising on performance. Use FireDAC in Android, iOS, Windows, and Mac OS X applications you are developing for PCs, tablets and smartphones. FireDAC Design Objectives and Architecture : FireDAC enables native high-speed direct access from Delphi and C++Builder.  Provides Universal Data Access i.e) Application built for a single data base can be used for other databases with very minimal changes at configuration. Highly configurable, using this you can fine tune your data access and it is important how your Software access with databases. Simple to deploy as no specific driver required, along with executable it is built. FireDAC local/embedded connectivity to certain local databases, including Microsoft Access database, SQLite database, InterBase ToGo / IBLite, InterBase on localhost, MySQL Embedded, MySQL Server on localhost, Advantage Database local engine, PostgreSQL on localhost, Firebird Embedded, and Firebird on localhost. Full source code provided, Developers can understand the underlying design and source code. Compatibility with the BDE means easy migration of legacy applications with reFind Utility. FireDAC Architecture Supported Database : InterBase, SQLite, MySQL, SQL Server, Oracle, PostgreSQL, IBM DB2, SQL Anywhere, Access, Firebird, Informix and more. Working With Database connections : Option 1: You can connect with any of the above listed Databases either from a Local Machine or Remote DBMS machine using the Data Explorer in the IDE. It is a tabbed pane that is located, along with the Projects Window and the Model View tabs, in the upper-right corner of the IDE window. Can use this, to create new connections, modifies, deletes, or renames your database connections.  The Data Explorer works for databases that use dbExpress or FireDAC connection types. The Data Explorer lets you browse database server-specific schema objects, including tables, fields, stored procedure definitions, stored functions, triggers, and indexes. FireDAC databases also display primary keys, foreign keys and generators. The Data Explorer presents a list of available database types (such as DATASNAP and MYSQL) that you can access and perform various actions on, using the context menus. With Data Explorer, you can easily create and manage database connections. Additionally, you can drag and drop data from a data source to a project to build your database application quickly. The commands available in the Data Explorer depend upon the object selected in the tree view. To display the associated context menu commands, right-click the following node types: You can also use Data Explorer to Obtain connection information, Check here. Option 2 : Create/Modify the connection via TFDconnection component by double clicking which will shows the editor same as Data explorer, where you can provide the DriverId, Username, Database name, Password etc. The connection string is stored in the TFDConnectionDefsparams and it is binded with application as hard-coded values. What if the database path changes after deployment of the application, you need to rebuild to avoid error in connection. To avoid such hard coded connection information, we can select the Connection Definition name in the TFDConnection editor, where Connection definition name need to be predefined and stored in the FDConnectiondefs.Ini file. The connection definitions for different databases are stored in the following fpath. C:UsersPublicDocumentsEmbarcaderoStudioFireDACFDConnectionDefs.ini To create TFDconnection with connection information, a clever way […]

Read More

Robust Way to Find Leaks With Deleaker In Delphi and C++Builder Applications

It’s quite normal for a developer to forget to destroy or free the objects while developing, these small memory leaks over a period of time lead the application to crash with, out of memory error. Finding that memory leaks in small projects it is easy. How about finding the leaks in large enterprise applications? Tired of finding the leaks? Don’t worry. The Deleaker solves the problem for you in a robust way. Find all the memory leaks, It doesn’t matter what type of leaks are occurring, Deleaker will find them all: memory leaks (produced by the heap, virtual memory, or OLE allocators, etc.), GDI leaks, leaks of Windows USER objects, and handles. Deleaker detects leaks in Delphi and C++ Builder. It can work either as a standalone application or as a RAD Studio extension. Standalone is convenient, for example, if RAD Studio is not installed. If Deleaker works as an extension, a developer can search for leaks without leaving RAD Studio, which lets him move to the source of possible errors quicker. After installation, a new Deleaker item is added to the RAD Studio main menu: How to use the Deleaker : Install the Deleaker setup check here. While installing choose the options as standalone or integration with RAD studio. Create a sample windows VCL application and write a piece of code with some memory leaks in it. Run the application, perform the action to create memory leaks, and close the application. Deleaker will create a snapshot of memory leaks where you can navigate to the line of code from the snapshot window directly to IDE. It’s that simple identify the memory leaks. Check the samples and resources available here. Check this below video demonstration of Deleaker for Delphi and C++ builder.

Read More

The Fastest And Easiest Way To Build Data-Driven Delphi And C++Builder Apps Using Enterprise Connectors

Enterprise connectors – Make Connecting to any application is easy as connecting to a database. Move, integrate, and analyze data with ease utilizing the FireDAC Enterprise Connectors, powered by CData. These unparalleled components allow you to integrate 180+ Enterprise applications, simplifying connectivity into a standard model using SQL. It allows you to integrate application services, like QuickBooks Desktop, MailChimp, Salesforce, YouTube, SugarCRM, Jira, SurveyMonkey, Amazon DynamoDB, Couchbase, PayPal, eBay, Google Sheets, Facebook, Twitter, Slack, and Dropbox. Features : Replication and Caching: Easily copy data to local and cloud data stores such as Oracle, SQL Server, Google Cloud SQL, etc. The replication commands allow for intelligent incremental updates to cached data. Functions Library: A library of over 50 string, date, and numeric SQL functions that can manipulate column values into the desired result. Popular examples include Regex, JSON, and XML processing functions. Client-Side Processing: Enhance the data source’s capabilities with additional client-side query processing to enable analytic summaries of data such as SUM, AVG, MAX, MIN, etc. Customizable: Customize the data model to add or remove tables/columns, change data types, etc. without requiring a new build. These customizations are supported at runtime using editable human-readable schema files. Secure Connectivity: Includes standard Enterprise-class security features such as TLS/ SSL data encryption for all client-server communications. Developer Friendly: Full Design-time support for data operations directly from RAD Studio. How to connect with Google Spread Sheet : Create a new VCL Forms Application. Drop a TFDPhysGoogleSheetsDriverLink and TFDConnection object onto the form. Double-click the TFDConnection object. The FireDAC Connection Editor is displayed. Select “CData.GoogleSheets” in the DriverId menu and configure the connection properties. You can connect to a spreadsheet by providing authentication to Google and then setting the Spreadsheet connection property to the name or feed link of the spreadsheet. If you want to view a list of information about the spreadsheets in your Google Drive, execute a query to the Spreadsheets view after you authenticate. Use the OAuth 2.0 authentication standard. To access Google APIs on behalf on individual users, you can use the embedded credentials or you can register your own OAuth app. OAuth also enables you to use a service account to connect on behalf of users in a Google Apps domain. To authenticate with a service account, you will need to register an application to obtain the OAuth JWT values. See the Getting Started chapter in the help documentation to connect to Google Sheets from different types of accounts: Google accounts, Google Apps accounts, and accounts using two-step verification. Watch this Video, how to connect to Google Spread sheet with powerful FireDAC enterprise connector components. Enterprise Connectors. Check out the full list of Applications supported and components available for Delphi/C++ Builder. Integrate faster with your applications using enterprise connectors.

Read More

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