Console safety

| | Comments (5)

Here's a new, little-known feature of RB2006r1 -- you can now set the console safety on classes, methods, etc within the IDE.

Let's say you're creating a set of 3rd party classes that you want to give away to users. It used to be that you had no control over whether that class would work in a console application, not work, should *only* work in a console app, etc.

Now, you can explicitly tell the IDE "hey, this can be used under these circumstances."

In the project item editor, right click on a class. You'll see a group of three options:

Desktop Applications Only
Desktop and Console Applications
Console Applications Only

With a checkmark next to one of them.

If your class cannot be used in a console app (for instance, maybe its super is Canvas), then you should select Desktop Application Only. If your class should only be used in a console application (maybe it relies on StdIn or StdOut), then you should select Console Applications Only. Finally, if your app really doesn't care (maybe it's a MemoryBlock subclass), then you can just leave it as Desktop and Console.

This concept extends to the individual parts of the class or module as well. You can flag methods, properties, etc as appropriate.

5 Comments

I met your ex Rachel last night. She's so LITTLE and CUTE! :)

And if you're really adventurous, you can export your project to XML (or to rbvx if you prefer) and add that same kind of tag to other parts of your project as well. And use any kind of constant as a decision maker. For example, you can have two methods of same name and parameter, and make one be used with "TargetWindows" and the other one with "TargetMacOS". Or something more useful.
And the info does get preserved if you work in the IDE and save & reopen your project.
Pretty neat!

@Jessica -- and crazy to boot. :-P I much prefer my Lissy!

So, when will RB auto-detect that your class derives from Canvas and automatically set the "no console" flag? You could simply inherit that attribute, after all...

When someone feature requests that very sensible idea. ;-) But there are still cases where you will run into problems. Take FolderItem for example. It has console safe items and not console safe items on it. So it's tough to set the defaults for the methods and properties to anything sensible, even though the class itself could inherit the flags.

Leave a comment

Disclaimer

I'm currently an employee of REAL Software. My blog is mine. The opinions represented in this blog are mine as well and may not represent my employer's opinions. All original material is copyrighted and property of the author.

REALbasic® is a registered trademark of REAL Software, Inc. REAL SQL Server™ and Lingua™ are pending trademarks of REAL Software, Inc. All rights reserved.