4D Blog

Home Product Use class in embedded web area with $4d

Use class in embedded web area with $4d

April 24, 2025

Product

With 4D 20 R9, 4D introduces new commands that allow developers to define an object context for $4d, ensuring only specific functions are exposed. Previously, using $4d meant exposing 4D methods to the web area, but now, you can define and use class functions instead. This improvement allows for better organization, encapsulation, and security when integrating 4D functionalities into web areas.

HDI Context_Web_Area

Limiting Access to Specific Methods with WA SET CONTEXT

With the new WA SET CONTEXT command, developers can set an object containing only the allowed functions for $4d.

For example, if you set the context of a web area with:

var $myWAObject:=cs.WAFunctions.new()
WA SET CONTEXT ( * ; "MyWebArea"; $myWAObject)

with the WAFunctions class:

Function next()
	// Some code here
	
Function previous()
	// Some code here
	
Function current()
	// Some code here

The only $4d javascript functions available in the “MyWebArea” area are:

  • $4d.next()
  • $4d.previous()
  • $4d.current()

 

In the same way, if you want to allow the use of some existing project methods, you can encapsulate them in an object and pass it to the WA SET CONTEXT command:

var $context:={}
$context.myNextMethod:=Formula(myNextMethod)
$context.myPreviousMethod:=Formula(myPreviousMethod)
$context.myCurrentMethod:=Formula(myCurrentMethod)

WA SET CONTEXT(*; "myWebArea"; $context)

and the only $4d javascript functions available in the “MyWebArea” will be:

  • $4d.myNextMethod()
  • $4d.myPreviousMethod()
  • $4d.myCurrentMethod()

Your Web Pages will run as before, but now you are sure that only those 3 methods can be called.

Conclusion

With this new command, 4D gives you better control over how $4d works in your web areas. You can now limit access to only your chosen functions, making your app more secure and organized. Plus, using class methods with $4d helps keep your code cleaner and easier to manage.

Want to learn more? Check out the official documentation here.

Discuss

Tags 20 R9, 21, Web area

Latest related posts

  • May 20, 2025

    Automatic Refresh of OEM Build Licenses

  • May 16, 2025

    New class to handle incoming TCP connections

  • April 29, 2025

    Discover your AI-powered writing assistant in 4D Write Pro

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

  • 4D View Pro
  • 4D Write Pro
  • 4D for Mobile
  • Email
  • Development Mode
  • 4D Language
  • ORDA
  • User Interface / GUI
  • Qodly Studio
  • Server
  • Maintenance
  • Deployment
  • 4D Tutorials
  • Generic
  • 4D Summit sessions and other online videos

Tags

4D-Analyzer 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R8 20 R9 Administration Authentication Build application CI/CD Class Client/Server Code editor Collections Compatibility settings Formula Listbox Logs Mail Microsoft 365 Network Objects ORDA PDF Pictures Preemptive Programming Qodly Studio REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor

Tags

4D-Analyzer 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R8 20 R9 Administration Authentication Build application CI/CD Class Client/Server Code editor Collections Compatibility settings Formula Listbox Logs Mail Microsoft 365 Network Objects ORDA PDF Pictures Preemptive Programming Qodly Studio REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor
Subscribe to 4D Newsletter

© 2025 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