Google
www ResExcellence

Application Makeovers
Desktop Snapshots
iTunes Skins
Mighty Mouse Cursors
Uploads
Boot Images
Dock Poofs
Links List
Photoshop Goodies
Users Forum
Boot Panels
Download Stats
Log-In Panels
REALbasic
Clocks
GUI Software
Mac OS X Mods
Safari Stuff
Desktop Pictures
Icons
Mac OS X Themes
Splash Screens
Homepage
Download a free demo of REALbasic!
Download a free demo of REALbasic!
Recent Articles...
3D
3D Photo Gallery (Part 2)
3D Photo Gallery (Part 1)

Audio
iPod Tricks (Part 3)
iPod Tricks (Part 2)
iPod Tricks (Part 1)
Laugh Track Machine
Audio Player with Reverb
Shepard Melody
RB Phone Home
Build a Drum Machine

Custom Controls
Custom Buttons
Custom Buttons Part II
iTunes-style Listboxes
Custom Controls

General RB
Wiggle Window
JPEG in PDF
Hey! You got your Checkbox in my Listbox!
Background Applications
Listbox Auto-Find
Virtual Volumes
Time Tracker
Software Distribution (Part 4)
Software Distribution (Part 3)
Software Distribution (Part 2)
Software Distribution (Part 1)
Exceptions
Living on the Edge
Tips and Tricks
Review of REALbasic 3.0
Text Clippings Made Easy

Graphics
Image Spinner
Cropping Graphics (Part 4)
Cropping Graphics (Part 3)
Cropping Graphics (Part 2)
Cropping Graphics (Part 1)
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

Internet
Display Web Image In Canvas
HTML IMG Tags
Version Tracking
Even Smarter Instant Messaging
Web Tiler
JavaScript and REALbasic
Stock Ticker (Part 2)
Stock Ticker (Part I)
AIM Mate

Mac OS X
Using Sheets in REALbasic
Build a Bundle (Part 2)
Build a Bundle (Part 1)
Dock Your Passwords
Mac OS X Debugging
REALbasic Mac OS X Icon Tutorial
Animate Your Dock
RB and the Command Line

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

Printing
Print to PDF

Registration
Registration Code Validation

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

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

Speech
Speech Recognition

Video
Big Brother Video Capture

resexc2.gif (20k)

Newest Dev Tools!

Book Alert !
REALbasic for Dummies
by Erick Tejkowski
$19.99 @ Amazon

Made with REALbasic!

Problems?
Downloads are in StuffIt 5 format (free download).
Tell me about a bad link (Thanks!).
Submission Policy

Web Canvas Images  |  REALbasic News (09/13)  |  Custom Buttons Part II

09-17-03

Web Canvas Images by Seth Willits

For some reason, I have a nasty habit of referring to each tutorial as "this week's," so if I do say "week," just smile and nod and know that I mean "this tutorial." With that in mind...

In this tutorial we're going to learn how to use the HTTPSocket class, a new feature in REALbasic 5.0, to show an image that we're going to download from the web in a canvas. As you might think, this is actually quite simple, but by no means is the HTTPSocket class "simple." Simple to use maybe, but what you can do with it is for the most part limitless. (We'll explore the HTTPSocket class in future tutorials.)

The first step is to create a new project and drag a canvas to the window. Next, Control-Click or Right-Click on the main window. (Didn't know that contextual menu was there, did you?) Select "HTTPSocket" from "Add Control->Any->Socket Core...->TCPSocket...". After that, add two properties "Image as picture" .

The HTTPSocket class allows your REALbasic application to connect to a web site, or more accurately, an HTTP server and send requests such as downloading a file or submitting a form. The HTTPSocket class has two settable properties, Address and Port, but since we're going to be using the Get method of the HTTPSocket class which requires an absolute URL anyway, we only need to be concerned about the port which is nearly always 80. So go ahead and put in 80 as the Port value for HTTPSocket1.

For our project we're going to download an image from the ResExcellence website, located at "http://www.resexcellence.com/realbasic/images_02/rbnewslogo.jpg". We're going to request the image from within the Open event of the canvas and then upon receiving it, we'll refresh the canvas so that it draws.

The HTTPSocket.Get method requires only one parameter, an absolute URL to a file on the web site (and in our case this will be the URL in the previous paragraph), but it also has an optional parameter of type FolderItem which specifies a file to download the requested file to. If we don't supply a folderItem to the Get method, then REALbasic puts the data returned by the HTTP server into a string and calls the PageReceived event. On the contrary, if we do specify a file, the DownloadComplete event is fired which has - among others - a "file" parameter which is the file we specified in the Get call.

Here's the one line of code for the Open event of the canvas. This line requests the image and downloads it to the "rbnewslogo.jpg" file in the "Temporary Items" folder.


It's important that you specify an absolute URL whenever you use the Get method because if you don't you'll get an error code "103", but note that the file we download and the file we download it to do not have to have the same name.

The DownloadComplete event will only be called if there was a successful connection to the web site, but it doesn't guarantee that the request was fulfilled. For example, if you typed "/rb_knews.jpg" as the file name in the URL parameter of the Get method, the DownloadComplete event would be called, but the httpStatus parameter would be 404 signaling that the file could not be found. With that in mind, in our DownloadComplete event, we're going to test whether the file exists (because if it does then the request was fulfilled), open the file as a picture, put it into our "Image" property, and then call the Refresh method of the canvas so the image will be drawn.


The last bit is to actually draw the image into the canvas via the Paint event:


(We test for nil because the canvas may try to draw itself before we've downloaded the image, and drawing nil images is bad.)

Now in a real application, we'd want to handle errors because the real world is never perfect. We can test for a connection error using the Error event:


And we can test for HTTP errors in the DownloadComplete event.


That's all for this week...err... tutorial.... You know what I mean. :-)

09-13-03

REALbasic News by Seth Willits

TCplus 1.1 - TCplus for OS X
Virtual Volume Browser b1 - Browse Virtual Volumes with Finder-like ease.
FontCatalog 1.0 - Find Typefaces Faster.
ZeboPhoto v1.3.4 - Popular image viewer/editor program for Macintosh Classic and OS X
MacIcon - RB class to draw system and file icons.
IntelliSwipe USB Credit Card Reader - Driverless credit card reader for your Mac.
Informator 1.0 - Multifunctional Finder Get Info replacement
FMOD Wrappers v0.1b - Access to the cross platform audio library.


resexc1.gif (8k)

Application Makeovers
Desktop Snapshots
iTunes Skins
Mighty Mouse Cursors
Uploads
Boot Images
Dock Poofs
Links List
Photoshop Goodies
Users Forum
Boot Panels
Download Stats
Log-In Panels
REALbasic
Clocks
GUI Software
Mac OS X Mods
Safari Stuff
Desktop Pictures
Icons
Mac OS X Themes
Splash Screens
Homepage

Maintained by the Staff of ResExcellence. This entire site ©1997-2003 ResExcellence
Privacy Statement? Sure we gotta Privacy Statement.

[an error occurred while processing this directive]on the ResEx LinuxPPC Server