4D Blog

Home Tips Formula – Think outside the box

Formula – Think outside the box

January 9, 2020

Tips

According to the top 10 blog posts of 2019, the Formula: More power behind simplicity post ranked quite high … in the top five. It seems that Formula really grabbed your attention, so here’s another tip that Vincent de Lachaux (developer and 4D expert) has shown me and I’m sharing with you!

Use formula in a generic dialog

The FORM command lets you easily create a generic alert dialog. Simply direct the dialog to different texts to be displayed in an object:

$object:=New Object(\
   "mainText";"Are you sure you want to empty the trash?";\
   "additionalText";"You can't undo this action.";\
   "okText";"Empty Trash";\
   "cancelText";"Cancel"\
)

You can further enrich this object with a formula for the actions behind the OK and Cancel buttons. Your formula can call a 4D command or project method, with or without parameters.

$object.okAction:=Formula(myMethod("Trash";"ok"))
$object.cancelAction:=Formula(myMethod("Trash";"cancel"))

Then, use generic code in the buttons:

Form.cancelAction.call()
// Or
Form.okAction.call()

That’s it! You now have a completely generic alert dialog.

Add formulas in the Storage object

If you have verification or calculation functions anywhere in your code, you can add formulas to the Storage object.

Here’s an example:

// Define common functions
If (Storage.ƒ=Null)
   Use (Storage)
      Storage.ƒ:=New shared object
      Use (Storage.ƒ)
         // Register the function in Storage
         Storage.ƒ.isValid:=Formula(....)
         Storage.ƒ.computeX:=Formula(....)
      End use
   End use
End if

Using this function, you don’t change the content of the storage, so you don’t need Use/End Use.

Create formulas when loading a component

To use the methods of a component in the host database, you must first share the method. However, when you’re adding methods, it can be easy to forget. Here’s an idea for sharing component formulas!

In your component, create a method that returns an object to the host database. This object contains formulas that call the methods of your component. Result? Only one method to share. Cool isn’t it!?

That’s all for this blog post. Now it’s your turn to share this tip with someone else! 

Discuss

Tags Formula, v17 R3, v18

Latest related posts

  • April 28, 2025

    Tips & Tricks for your 4D Apps – April 2025 Edition

  • April 9, 2025

    Restrict data according to privileges or information saved in session storage

  • April 7, 2025

    Designing an Interactive and Dynamic Menu Bar in Qodly application

Vanessa Talbot
Vanessa Talbot
• Product Owner •Vanessa Talbot joined 4D Program team in June, 2014. As a Product Owner, she is in charge of writing the user stories then translating it to functional specifications. Her role is also to make sure that the feature implementation delivered is meeting the customer need.Since her arrival, she has worked to define key features in 4D. She has worked on most of preemptive multi-threading new features and also on a very complex subject: the new architecture for engined application. Vanessa has a degree from Telecom Saint-Etienne. She began her career at the Criminal Research Institute as a developer for the audiovisual department. She has also worked in media and medical fields as expert in technical support, production as well as documenting 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