Introducing the “Welcome to Xojo” Bundle!

New to Xojo and looking for guidance? We've put together a terrific bundle to welcome you! Xojo Bundle

This bundle includes six back issues of the magazine -- all of year 21 in printed book and digital formats -- plus a one-year subscription (beginning with 22.1) so you'll be learning all about Xojo for the next year. It's the perfect way to get started programming with Xojo. And you save as much as $35 over the non-bundle price!

This offer is only available for a limited time as supplies are limited, so hurry today and order this special bundle before the offer goes away!

Article Preview

Buy Now

Issue 17.4 ('100th Issue')
Instant purchase and download via GumRoad!


TextField Warning

Indicating invalid entries with a warning sign

Issue: 17.4 (July/August 2019)
Author: Markus Winter
Author Bio: Markus is a Molecular Biologist who taught himself REALbasic programming in 2003 to let the computer deal with some exceedingly tedious lab tasks. Some call it lazy, he thinks it smart. He still thinks of himself as an advanced beginner at best.
Article Description: No description available.
Article Length (in bytes): 6,881
Starting Page Number: 24
Article Number: 17403
Resource File(s):

Download Icon project174003.zip Updated: 2019-06-30 18:21:42

Related Link(s): None

Excerpt of article text...

For my NumbersOnlyField articles I find myself in need of a TextField that flags when an entry is invalid. While it is easy enough to directly draw a warning sign on the window beside the TextField, that approach would lead to problems if the window has custom backgrounds, or the TextField is locked to the window and the window gets resized. Following that path quickly gets more complex and messy than it is worth. But Xojo provides a much easier and simpler way for us as we can use a TextField in a ContainerControl instead!

So what do we want to achieve? We want a TextField that draws a warning triangle when an entry is invalid (e.g. not a number), and a checkmark or something else when it is valid.

So first we make a custom class TextFieldWithDrawing with super TextField, and give it a property IsValidEntry as Boolean with the default value set to false (always choose the safe default option, because an empty field is not a numeric value anyway).

Note that it is better to use positive Booleans like IsValidEntry rather than negated Booleans like IsInvalidEntry. Why? Because it is more difficult to follow double negations like if IsInvalidEntry = False or if Not IsInvalidEntry... which is the same as if IsValidEntry = True or if IsValidEntry.

As the TextField needs to react to input, we add an event handler for TextChanged, and also create an identical event definition TextChanged in order to be able to propagate the event.

...End of Excerpt. Please purchase the magazine to read the full article.