Search This Blog

Friday, May 17, 2024

Why should a Delphi developer avoid using the variant type?

Delphi's variant type provides advantages for developers, but it's important not to use variants blindly.

Advantages include:

  1. Flexibility: Variants can hold various data types like integers, strings, floating-point numbers, and even objects. This eliminates the need for multiple variable declarations for different data types, making code more concise.
  2. Loose Typing: Delphi uses runtime type checking for variants. This allows for dynamic data assignment at runtime, useful for situations where the data type might be unknown beforehand.
  3. Generic Functions and Procedures: Variants can be used as parameters in functions and procedures, enabling them to work with different data types without needing specific versions for each type. This promotes code reusability.
  4. Component Communication: COM (Component Object Model) heavily utilizes variants for data exchange between components. Delphi's variant support simplifies communication with COM components.
  5. Data Persistence: Variants can store various data types in a single variable, making them useful for saving and loading mixed-type data from files or databases.


Disadvantages include

  1. Performance Overhead
    • The Variant type introduces significant performance overhead compared to strongly typed variables
  2. Lack of Compile-Time type-checking
    • One of the main advantages of a strongly typed language like Delphi is compile-time type checking, which catches errors early in the development process. Using Variant bypasses this safety net, as type checking happens at runtime instead.
  3. Increased Complexity and Potential for Bugs
  4. Limited IDE Support: Watchlist, etc
  5. Memory Management and Resource Usage
    • Occupies more memory (it consumes 16 bytes of memory in 32-bit outputs, while the memory used by an integer is equal to 4 bytes and string is equal to 4 bytes - in 64-bit outputs, it consumes 24 bytes of memory)
  6. If a variable of variant type has a string value, the index of this string cannot be accessed. (runtime error: EVariantInvalidArgError or Invalid Argument)
  7. As soon as the variant variable is created, this variable is initialized with the Unassigned value.
  8. Variant type includes a type code and a value (or a pointer to a value).
  9. By default, a variant type holds all types except records, sets, files, classes, and pointers!
  10. The varArrayRedim function should be used to change the size of variant arrays.

Conclusion(Best Practices):

  • Use strongly typed variables whenever possible.
  • Utilize Generics for type-safe collections and methods.
  • Employ overloaded methods to handle different types if flexibility is required.
  • Make use of type-specific functions and procedures to ensure type safety and maintain performance.

Monday, May 6, 2024

Don't let Delphi die!

The Delphi community is currently facing a critical time 😔. 

I'm writing this because I care about the future of our beloved programming language, every single word of this article has been experienced during 15 years of work, so I'm not just typing some useless words here, this community and this language are in real danger in the next 5 years.

With the rise of web and scripting languages, the community has dwindled, losing thousands of developers who left the language because of a lack of web development options in Delphi, the first big decline, leaving behind only a few companies where old Delphi developers hold positions of power these days. 

These old-fashioned Delphi developers are often domain experts who are comfortable in their roles and are resistant to change. 

They don't allow the entry of new developers, especially those who are younger and more skilled, fearing that they may be a threat to their position.


This attitude of rejecting anyone better than themselves is not just limited to age but also their mindset.

 Although they know what they don't know, they prefer to stay in their comfort zone of 20-30 years ago.

 This has caused many people, especially those born in the 80s and 90s(who are under 40), to leave the language with regret because they cannot find a job😞.

These selfish old men who held Delphi back and don't allow the younger generation to progress are the real enemies of Delphi 💔. 

They were only interested in making money without contributing to the growth of the community in any aspect over the years.

The language that was once a king is now accelerating toward death, and these guys are playing a big role in it.

In my opinion, Delphi can hardly survive the second big decline, and people must change their mindset before it's too late. 

Delphi cannot wait until these guys retire or pass away. 

If you are one of them, please open your eyes 👀! 

Don't let Delphi die.

Wednesday, December 27, 2023

Is Delphi Still Alive and Kicking? A Look Beyond the Headlines

 

The whispers are getting louder: "Is Delphi dead?" "Time to move on?" For many, the once-dominant language seems shrouded in a cloud of doubt. But before we hastily pronounce its demise, let's take a closer look at the reality beyond the headlines.

Yes, Delphi has faced challenges. The transition from Borland to CodeGear, and then to Embarcadero, wasn't always smooth. But to claim it's dead ignores its tenacious spirit and enduring relevance. Just consider these facts:

  • Top 20 Language: Despite the naysayers, Delphi remains firmly entrenched in the top 20 programming languages of 2023, a testament to its continued usefulness and active user base.
  • Thriving Community: Delphi boasts a passionate and dedicated community, constantly pushing the boundaries of the language. Open-source libraries, vibrant forums, and active user groups keep the flame burning bright.
  • Modern Updates: Embarcadero actively invests in Delphi's future. New features, improved IDEs, and cross-platform capabilities ensure it stays relevant in today's tech landscape.

But Delphi's strength lies not just in its statistics. It's about the unique value it brings to the table:

  • Speed and Efficiency: Native compilation and a mature runtime environment make Delphi a champion of performance, ideal for resource-intensive applications.
  • Stability and Reliability: Decades of refinement and a rock-solid foundation make Delphi a trusted choice for mission-critical systems where uptime is paramount.
  • Visual Development Power: The RAD (Rapid Application Development) philosophy at the heart of Delphi empowers developers to build complex applications with incredible speed and ease.

Now, let's address the elephant in the room: "What about Python and Java?" While these languages excel in their respective domains, they're not apples-to-apples comparisons with Delphi. Each language caters to different needs and shines in specific areas.

Instead of pitting them against each other, let's celebrate the diversity and richness of the programming landscape. Delphi offers its own unique strengths, making it the ideal choice for projects where performance, stability, and visual development are key priorities.

So, is Delphi dead? Absolutely not. It's alive, well, and kicking, constantly evolving and adapting to the changing tech landscape. To those considering Delphi, here's the call to action:

  • Dive in and explore its potential: Delphi's vibrant community and wealth of resources are ready to welcome you.
  • Contribute your expertise: Share your knowledge, build libraries, and help shape the future of the language.
  • Spread the word: Challenge the misconceptions and advocate for Delphi's enduring value.

Remember, the future of any language lies not just in its developers, but also in its community. By actively engaging and contributing, we can ensure that Delphi continues to thrive and innovate, silencing the doubters and proving its enduring relevance for years to come.

So, the next time you hear whispers of Delphi's demise, remember this: it's not dead, it's just getting started. Join the movement and help write the next chapter of this remarkable language's story.

Friday, December 22, 2023

It's now possible to apply Vcl-Styles on the IDE itself!

 

Did you notice that it is possible to apply built-in Vcl-Styles on the IDE itself?
Using the "IDE Style Options" menu you can change the default skin of the IDE.





     

    Remarks:

  1. It's possible to apply "Standard Vcl-Styles" or "High-DPI Vcl-Styles"
  2. The Editor theme is separated by Embarcadero, which means you must change it too if needed.
  3. It is available in Delphi 11 Alexandria and 12 Athens.

    
    Here are some screenshots, enjoy!








Monday, December 18, 2023

Harnessing the Power of .RC and .RES Files in Delphi: A Comprehensive Guide

Delphi empowers developers to create robust applications with ease. While building applications, it's crucial to manage resources efficiently, and that's where .rc (resource script) and .res (compiled resource) files come into play. In this blog post, we'll explore their usage in a Delphi project, focusing on creating a simple non-visual component and discussing two common approaches for handling resource files.

Understanding .RC and .RES Files

What are .RC Files?

Resource scripts (.rc files) are text files that contain a set of instructions and definitions describing resources for an application. These resources can include icons, bitmaps, strings, dialogs, and more. In Delphi, .rc files are commonly used to manage resources and provide a centralized way to organize them.

The Role of .RES Files

When you compile an .rc file, it generates a compiled resource file (.res). The .res file contains binary data representing the resources specified in the .rc file. This compiled format is more efficient for runtime loading and improves the overall performance of the application.

Scenario: Creating a Simple Non-Visual Component

Let's dive into a practical example by creating a simple non-visual component in Delphi and managing resources for it.

Step 1: Creating the Delphi Component

unit SimpleComponent;

interface

uses
  System.Classes;

type
  TSimpleComponent = class(TComponent)
  private
    FMessage: string;
  public
    constructor Create(AOwner: TComponent); override;
    procedure ShowMessage;
  published
    property Message: string read FMessage write FMessage;
  end;

implementation

uses
  Vcl.Dialogs;

constructor TSimpleComponent.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FMessage := 'Hello, Delphi!';
end;

procedure TSimpleComponent.ShowMessage;
begin
  ShowMessage(FMessage);
end;

end.


Step 2: Adding Resources from the Project Menu

1. Open your Delphi project.

2. Navigate to Project -> Resources and Images -> Add -> New -> Resource Type: `STRING`, Name: `MY_MESSAGE`.

3. Set the value of `MY_MESSAGE` to your desired message, e.g., "Greetings from Resource".


Step 3: Using the Resource in Delphi Code

unit SimpleComponent;

interface

uses
  System.Classes;

type
  TSimpleComponent = class(TComponent)
  private
    FMessage: string;
  public
    constructor Create(AOwner: TComponent); override;
    procedure ShowMessage;
  published
    property Message: string read FMessage write FMessage;
  end;

implementation

uses
  Vcl.Dialogs, System.SysUtils, System.StrUtils;

{$R *.dfm} // Ensure that this line is present

constructor TSimpleComponent.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);

  // Access the resource string
  FMessage := LoadStr({Resource ID});
end;

procedure TSimpleComponent.ShowMessage;
begin
  ShowMessage(FMessage);
end;

end.


Step 4: Compiling .RC with Command Line

1. Create a new text file named `SimpleComponent.rc`:

MY_MESSAGE STRING "Greetings from Command Line Resource"

2. Open the command prompt and navigate to the folder containing the .rc file.

3. Compile the .rc file using the `BRCC32` compiler:

BRCC32 SimpleComponent.rc

4. Ensure that the generated `SimpleComponent.res` file is present.


Step 5: Using Command Line Resource in Delphi Code

unit SimpleComponent;

interface

uses
  System.Classes;

type
  TSimpleComponent = class(TComponent)
  private
    FMessage: string;
  public
    constructor Create(AOwner: TComponent); override;
    procedure ShowMessage;
  published
    property Message: string read FMessage write FMessage;
  end;

implementation

uses
  Vcl.Dialogs, System.SysUtils, System.StrUtils;

{$R SimpleComponent.res} // Include the compiled resource file

constructor TSimpleComponent.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);

  // Access the resource string
  FMessage := LoadStr({Resource ID});
end;

procedure TSimpleComponent.ShowMessage;
begin
  ShowMessage(FMessage);
end;

end.


Conclusion

In this blog post, we explored the significance of .rc and .res files in Delphi projects. By creating a simple non-visual component, we demonstrated two approaches for managing resources—adding them from the project menu and compiling an .rc file using the command line. Efficient resource management is crucial for building robust Delphi applications, and understanding the use of .rc and .res files is a key step toward achieving that goal.

Tuesday, December 12, 2023

Asked from Google bard!!

 

What is the best option to have ChatGPT's power in RAD Studio?


There is only one option for integrating ChatGPT's capabilities into RAD Studio

ChatGPTWizard:

  • This is a plugin available in the Embarcadero GetIt package manager.
  • It offers access to ChatGPT, WriteSonic, and YouChat, allowing you to compare responses from different AI models.
  • It has an easy-to-use interface that integrates with the RAD Studio IDE.
  • It is free and open-source under the MIT license.


There are several options for integrating ChatGPT's capabilities into your applications

1. RDOpenAI:

  • This is a Delphi component available in the Embarcadero GetIt package manager.
  • It provides event-based access to ChatGPT, making it easy to integrate its functionality into your applications.
  • It offers a more programmatic approach compared to ChatGPTWizard.
  • It is free for non-commercial use.


2. OpenAI for Delphi:

  • This is a library available on GitHub.
  • It provides access to the OpenAI API, which powers ChatGPT and other AI models.
  • It requires more technical knowledge than the other options.
  • It is free and open-source under the MIT license.


Choosing the best option depends on your specific needs and preferences:

  • For IDE the best option is ChatGPTWizard.
  • For beginners, ChatGPTWizard might be the easiest option.
  • If you need to implement AI-based subjects in your application, RDOpenAI or OpenAI for Delphi might be a better choice.
  • Consider factors like cost, ease of use, functionality, and community support when deciding.

Here are some additional resources that you may find helpful:

It's also worth noting that the landscape of AI integrations for RAD Studio is constantly evolving. New options and updates may become available in the future, so it's always a good idea to stay up-to-date on the latest developments.