Special

Clearance Sale!

We've been publishing for over five years now and it's time to clear out our inventory of back issues, so we're slashing prices!

RBD Magazines

Check out this amazing clearance sale of all our past issues. Missing some issues? This is a great time to complete your RBD collection. Save up to 40% off the regular price of our printed back issue packages. These prices are only good until the end of the year May 2008 and supplies are limited, so place your order today.

Article Preview


Buy Now

Print:
PDF:

Feature

The Extends and Assigns Keywords

Issue: 2.1 (August/September 2003)
Author: Charles Yeomans
Author Bio: Charles Yeomans pontificates about most things REALbasic from his computer in Lexington, Kentucky.
Article Description: No description available.
Article Length (in bytes): 15,701
Starting Page Number: 21
RBD Number: 2111
Resource File(s):

Download Icon 2111.sit Updated: Friday, October 17, 2003 at 12:21 PM

Related Link(s): None
Known Limitations: None

Excerpt of article text...

REALbasic 5.1 introduced two new keywords, "Extends" and "Assigns," that allow developers to do wonderful things. In this article, we'll explore their use by way of examples, and also take a look at the benefits of their introduction for application design in REALbasic.

The Extends Keyword

The "Extends" keyword allows you to add new subroutines and functions to an existing class. It does this by telling the compiler to treat global methods as methods of the declared type of the first parameter. Some examples will make this clear.

Examples

As our first example, let's add a HexDump function to the MemoryBlock class.

Function HexDump(Extends m as MemoryBlock) as String

dim i, N as Integer

dim output as String

N = m.Size - 1

For i = 0 to N

If m.byte(i) < -at-h0A then

output = output + "0" + Hex(m.byte(i))

Else

output = output + Hex(m.byte(i))

End if

Next

Return output

End Function

In the declaration of HexDump, the presence of the keyword "Extends" in front of the MemoryBlock parameter tells RB that HexDump should not be treated as a global function anymore. Instead, it can and must be called as a function of the MemoryBlock class.

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

Article copyrighted by REALbasic Developer magazine. All rights reserved.


 


|

 


Weblog Commenting and Trackback by HaloScan.com