4D Blog

Home Product Enhancing Compilation with Direct Typing in 4D

Enhancing Compilation with Direct Typing in 4D

November 6, 2024

Product

With 4D 20 R7 you can say goodbye to “Compiler_” methods and embrace more freedom in how and where you declare your variables. Save time by staying focus on your development workflow and your coding process thanks to Direct Typing.

In earlier versions of 4D, developers had two options for handling variable typing during compilation. If the “Compilation path” setting was set to anything other than “All variables are typed,” the compiler would attempt to infer the types of untyped variables based on their usage in the code. While this could simplify variable declarations, it came with a trade-off:

  • Slower Compilation: Typing inference requires an additional compilation pass, slowing down the overall build process.
  • Risk of Errors: The compiler might infer incorrect types, potentially introducing difficult debugging bugs.

 

To avoid these issues, developers were advised to enforce strict typing by using the “All variables are typed” option. However, this required declaring all process and inter-process variables within dedicated “Compiler_” methods.

Introducing Direct Typing

To address these challenges, we’ve introduced Direct Typing which simplifies the way variables are declared and typed during compilation.

With Direct Typing, you no longer need to use “Compiler_” methods to declare process or inter-process variables. Instead, you can now define them wherever they logically belong in your code, whether that’s within a method, a class, or any other appropriate context. This gives you greater control over your code’s organization and enhances encapsulation.

This change provides the flexibility to organize your code the way you want, while still ensuring type safety and efficient compilation.

Adopting Direct Typing in Your Projects

Whether you’re working on a new or an existing project, Direct Typing can be easily integrated into your workflow.

  • New projects always use Direct Typing. This means you can start enjoying the benefits of flexible variable declaration and better code organization right away.

  • For existing projects, you’ll find a new setting in the Compilation Path that allows you to toggle Direct Typing on or off. This ensures compatibility with legacy code, giving you the option to migrate at your own pace.

Simply enable this setting, and you’ll be free to declare your process and inter-process variables wherever it makes the most sense in your code.

What’s new with direct Typing?

The #declare syntax is now mandatory for declaring method parameters with direct typing, rendering traditional compiler commands like C_TEXT, C_LONGINT, and others obsolete. One of the key benefits is that, particularly in components, you no longer need to compile the components when compiling a host base. The compiler will automatically fetch the method prototypes directly from the component’s code, simplifying and speeding up the development process.

To assist in converting compiler commands like C_TEXT and C_LONGINT to the var declaration syntax, we’ve made a 4D macro available on GitHub. You can access it here: 4D-Macros on GitHub.

how does it work?

  • When the compiler encounters a variable that hasn’t been explicitly typed, it adds that variable to a list of “to be typed” variables.
  • The compiler then temporarily pauses the compilation of the current method and proceeds to compile other methods.
  • Before pausing, it collects all the variable definitions in the method.
  • After compiling all the methods, the compiler checks if all the variables on the “to be typed” list have been found and assigned a type.
    • If so, it resumes compiling the previously paused methods.
    • If not, errors will be generated to indicate untyped variables.

Conclusion

The introduction of Direct Typing marks a significant improvement in how variable declarations are handled in 4D. By eliminating the need for “Compiler_” methods and allowing variable declarations to be made freely within the code, 4D developers now have greater flexibility and control over how they structure their projects.

To learn more about Direct Typing and how to implement it in your projects, check out our documentation.

Discuss

Tags 20 R7, 21, Compiler, Programming

Latest related posts

  • February 3, 2026

    4D Write Pro – Adding a margin automatically when bullets are set using standard actions

  • January 22, 2026

    Transform Static Documents into Actionable Knowledge with AIKit

  • January 22, 2026

    Deploy Fluent UI effortlessly in your 4D applications

Fabrice Mainguené
Fabrice Mainguené
• Product Owner •Fabrice Mainguené joined 4D Program team in November, 2016. As a Product Owner, he is in charge of writing the user stories then translating it to functional specifications. His role is also to make sure that the feature implementation delivered is meeting the customer need.After obtaining a Bachelor degree in Computer Science at CNAM, Fabrice joined a small software publishing company as a Windev developer. Then he worked for different companies in industry and trade areas as a Windev and web developer as well as technical advisor on new features.
  • Deutsch
  • Français
  • English
  • Português
  • Čeština
  • Español
  • Italiano
  • 日本語

Categories

Browse categories

  • AI
  • Release infos
  • 4D View Pro
  • 4D Write Pro
  • Email, Microsoft 365, Gmail
  • Development Mode
  • 4D Language
  • ORDA
  • User Interface / GUI
  • 4D Qodly Pro
  • Server
  • Maintenance
  • Deployment
  • 4D Tutorials
  • Generic
  • 4D Summit sessions and other online videos

Tags

4D-Analyzer 4D AIKit 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 21 21 R2 Administration AI Artificial Intelligence Build application CI/CD Class Client/Server Code editor Collections Formula Listbox Logs Mail Microsoft 365 Network Objects OpenAI ORDA PDF Pictures Preemptive Programming REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience vscode Web Word processor

Tags

4D-Analyzer 4D AIKit 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 21 21 R2 Administration AI Artificial Intelligence Build application CI/CD Class Client/Server Code editor Collections Formula Listbox Logs Mail Microsoft 365 Network Objects OpenAI ORDA PDF Pictures Preemptive Programming REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience vscode Web Word processor
Subscribe to 4D Newsletter

© 2026 4D SAS - All rights reserved
Terms & Conditions | Legal Notices | Data Policy | Cookie Policy | Contact us | Write for us


Subscribe to 4D Newsletter

* Your privacy is very important to us. Please click here to view our Policy

Contact us

Got a question, suggestion or just want to get in touch with the 4D bloggers? Drop us a line!

* Your privacy is very important to us. Please click here to view our Policy