#!/usr/bin/perl -w # # Copyright 2000 by Michael Coyle # Released under GPL. # # Call it with: # [an error occurred while processing this directive] # # Get the file name from the browser... $file_name = $ENV{'QUERY_STRING'}; # Open the file... open (EP, $file_name); # Print to the browser... print "Content-Type: text/html \n\n"; # Load the file and keep spitting it out to the browser... while () { chomp; print "$_ "; } # Close the file and go home... close EP #!/usr/bin/perl -w # # Copyright 2000 by Michael Coyle # Released under GPL. # # Call it with: # [an error occurred while processing this directive] # # Get the file name from the browser... $file_name = $ENV{'QUERY_STRING'}; # Open the file... open (EP, $file_name); # Print to the browser... print "Content-Type: text/html \n\n"; # Load the file and keep spitting it out to the browser... while () { chomp; print "$_ "; } # Close the file and go home... close EP

3D
3D Photo Gallery (Part 1)
3D Photo Gallery (Part 2)

Audio
Poor Man's MIDI
Make A Metronome
iPod Tricks (Part 1)
iPod Tricks (Part 2)
iPod Tricks (Part 3)
Laugh Track Machine
Audio Player with Reverb
Shepard Melody
RB Phone Home
Build a Drum Machine

Custom Controls and Windows
Double Click Listbox
Draggable Metal Window
Double Click Canvas
Custom Buttons
Custom Buttons Part II
iTunes-style Listboxes
Custom Controls


General RB
Scrolling Windows
Using Mesage Dialogs
Case-Sensitive Word Finder
Introduction to Stacks
Wiggle Window
JPEG in PDF
Listbox Checkboxes
Background Applications
Listbox Auto-Find
Virtual Volumes
Time Tracker
Software Distribution (Part 1)
Software Distribution (Part 2)
Software Distribution (Part 3)
Software Distribution (Part 4)
Exceptions
Tips and Tricks
Text Clippings Made Easy

Graphics
Drawing a Simple Gradient
The SpriteSurface: Space Game
Image Spinner
Cropping Graphics (Part 1)
Cropping Graphics (Part 2)
Cropping Graphics (Part 3)
Cropping Graphics (Part 4)
Shimmer Graphics
Lissajous Figures
Simple Screen Capture
Vector Graphics
Kaleidoscope Images
Stegonography
Spirals!
Image Table
RB Magnifying Lens
Screen Capture
Color Picker Tutorial

Hacks
Ghost Grab
Speedy Mouse Extension
iTunes Plugins
iTunes Skinner

Mac OS X
Global Hot Key Event (Carbon Events)
Login Welcomer (Carbon Events)
Add/Remove Buttons
Resizable Sheets
Mac OS X Preferences Window
Using Sheets in REALbasic
Build a Bundle (Part 1)
Build a Bundle (Part 2)
Dock Your Passwords
Mac OS X Debugging
REALbasic Mac OS X Icon Tutorial
Animate Your Dock
RB and the Command Line

Menus
Window Menu
Templates Menu
Listbox Menu

Novelty
Guessing Game
Calendar Trivia
Tile Mixer
Zip Code Finder
Happy Valentine's Day
Merlin Simulator (Part 1)
Merlin Simulator (Part 2)
Merlin Simulator (Part 3)
Buzzword Machine
AppleSoft BASIC

Printing
Print to PDF

Registration
Registration Code Validation
Network Registration Codes

Resources
Picture Extractor (Part 1)
Picture Extractor (Part 2)

Serial
Caller ID (Part 1)
Caller ID (Part 2)
Caller ID (Part 3)

Speech
Speech Recognition

Socket Communication
Easy Peer-to-Peer File Sharing
MacPAD Version Checking
Display Web Image In Canvas
HTML IMG Tags
Version Tracking
Even Smarter Instant Messaging
Web Tiler
JavaScript and REALbasic
Stock Ticker (Part I)
Stock Ticker (Part 2)
AIM Mate

XML Manipulation
Simple XML Introduction

Video
Big Brother Video Capture

Note: All articles without a byline were written by Erick Tejkowski. When cleaning the site I removed them because the code differed from page to page, and I have yet to put them back in.

resexc2.gif (20k)




REALbasic for Dummies
by Erick Tejkowski

$19.99 @ Amazon





Files are in Stuffit 6.5 or earlier, or ZIP format.
Download Stuffit Expander

Tell us about a bad link.

Using MessageDialogs by Seth Willits
03-10-04




MessageDialogs
I'm willing to bet that the interface feature of REALbasic 5.5 that you'll use the most is the new MessageDialog class. Each operating system has it's own standard dialog API that application developers use to display messages to users and get some kind of simple button-choice feedback. For example, in Mac OS X and Mac OS 9, this is the "StandardAlert" API, and is used for such dialogs as "Do you want to save the document before closing this window?"


(TextEdit in Mac OS X showing a Standard Alert)


In the past, REALbasic developers either had to create their own dialogs from scratch or use a plugin or declare statements to call into the OS's API. However, in REALbasic 5.5, there's no need for this, as a simple MessageDialog class is built-in and fully cross platform! In today's tutorial, we're going to use an instance of the MessageDialog class to confirm that the user wishes to close the window without saving the changes.


The Interface
Basically, all we're going to do is create a window with an EditField in it and pretend like we're creating a text editor. The interface for the program is below.


(This tutorial's interface)



Keeping Track of The Window's State
One of the key elements in displaying a dialog asking the user if they want to save their changes is knowing whether anything has changed. In Mac OS X the user has immediate feedback if there are unsaved changes in a window through the red close widget. When the window has been modified, this widget has a darkened dot in it.


(Mac OS X's fancy darkened dot)


Now seeing how this is a Mac site, I've used two declares to allow us to get this fancy dot in Mac OS X. Add these two methods to the document window in your REALbasic project:


(Returns true or false based on whether the window has been modified or not)


(Sets whether the window has been modified or not using Window.Modified = Boolean)


As you can see, the function calls to SetWindowModified and IsWindowModified in the Window Manager are very straightforward.


The Carbon Constant
One thing you may have noticed is that I didn't specify "CarbonLib" as the Lib parameter to the declares. Instead what I have done is a define a constant named "Carbon" with different values according to the target platform. I did this because it simplifies the maintenence of code if you want to allow your application to compile for either the Carbon PEF or Carbon MachO executable formats. (MachO compiling is new to REALbasic 5.5.)


(Creates a constant to the Carbon library or framework)


Now if we wanted to support Mac OS 9, we could add another platform constant variation for Mac (Classic) with a value of "InterfaceLib", but since Mac OS 9 is officially dead and Mac OS X offers so many absolutely cool features for developers and users alike, I don't bother even thinking about Mac OS 9 compatability.


Tracking the Modifications
Inside of the EditField's TextChange event, we should set Window.Modified to true since the information in the window has changed. We should also make sure that when the window opens that it is initially unmodified, so let's set it to false.


(Keeing track of the window's changes)


Displaying The MessageDialog
Finaly we get to the meat! Using the MessageDialog class requires that we know about the two principle classes: MessageDialog, and MessageDialogButton. The MessageDialog class represents the window itself. It contains properties for the alert message (Message as String), the explaination of the message (Explaination as String), the icon that will be displayed in the dialog (Icon as Integer), the title of the dialog - which is only displayed in Windows - (Title as String), and finally the three MessageDialogButtons ActionButton, AlternateActionButton, and CancelButton.

The ActionButton property is the button which preforms the default action. It's the default button, and by default it has a Caption value of "OK". The CancelButton is obviously the button which cancels the action and has a default Caption value of "Cancel". The AlternateActionButton is a third button which you can use to offer a third choice. In our case this would be the "Don't Save" button. Note that the CancelButton and AlternateActionButtons by default are not visible while the ActionButton is. Now let's put this to some use:


(Displays a confirmation dialog before closing the window)


As you can see, the code only does something if the window has been modified. If it has, we first create the dialog we're going to display and set the Message and Explaination properties as well as set the button captions and visibility for our three buttons. The reason ActionButton and AlternateActionButton have an ampersand as the first character in their captions, is because it's your way of letting REALbasic know that the keyboard commands Command-S and Command-D should map to those two buttons. On Windows and Linux this would map to Control-S and Control-D. The CancelButton however does not use this feature since by default, Command-. or Control-. on Windows and Linux, is the keyboard command for the cancel button.

After creating the dialog we then display it by calling the ShowModal method of the MessageDialog instance, which then returns a MessageDialogButton pointing to which of the three buttons was clicked. The easiest way to determine which button was clicked is by using a Select Case statement with the button's caption. Make a note that if the caption included an ampersand when you created it, you'll need to include that ampersand in the Select statement.


Final Notes
So there you have it. If you run the application and type in the field, closing the window will bring up the MessageDialog confirming whether you wish to save or not. The MessageDialog class is certainly a welcomed addition to the ever-growing REALbaisc feature set. The only real pitfalls with the implementation is that it currently does not support sheets on Mac OS X and that if your application's only window is a global floating window, the MessageDialog will appear behind it which can either cause a lock up of the application or simply obscure it from ever being seen. While this isn't REAL Software's fault, it can be worked around by implementing your own classes. I actually had to do so for this very reason.

As always, you can download the project for this tutorial.






Please support ResExcellence by Visiting our Sponsors. One click makes a difference.


Download REALbasic and create your own software!

#!/usr/bin/perl -w # # Copyright 2000 by Michael Coyle # Released under GPL. # # Call it with: # [an error occurred while processing this directive] # # Get the file name from the browser... $file_name = $ENV{'QUERY_STRING'}; # Open the file... open (EP, $file_name); # Print to the browser... print "Content-Type: text/html \n\n"; # Load the file and keep spitting it out to the browser... while () { chomp; print "$_ "; } # Close the file and go home... close EP #!/usr/bin/perl -w # # Copyright 2000 by Michael Coyle # Released under GPL. # # Call it with: # [an error occurred while processing this directive] # # Get the file name from the browser... $file_name = $ENV{'QUERY_STRING'}; # Open the file... open (EP, $file_name); # Print to the browser... print "Content-Type: text/html \n\n"; # Load the file and keep spitting it out to the browser... while () { chomp; print "$_ "; } # Close the file and go home... close EP