Creating a Class in REALbasic line

Class is a great way to make some things faster by saving the time of producing the code. Wrote it once, use it always. Learn how to create and how to use own Class in REALbasic. Watch it, learn it, enjoy it!

Definition of Class by Wikipedia

In object-oriented programming, a class is a programming language construct that is used as a blueprint to create objects of that class. This blueprint describes the state and behavior that the objects of the class all share. An object of a given class is called an instance of the class. The class that contains that instance can be considered as the type of that object, e.g. a type of an object of the “Fruit” class would be “Fruit”.

Creating a Class in REALbasic

Run REALbasic IDE and go to Project TAB. Click there on Add Class button and select created Class1.

realbasic add class

Now go to Property and Value and change the Name from Class1 to cHTTP and add to Super value HTTPSocket. Double click on cHTML Class in Project TAB.

realbasic class property and value

Add Method and Add Property

In code editor for this class we will create a new Property, so click Add Property and in Declaration type Data in As type String.

realbasic class code editor

Our next step will be creating a new Method. Click on Add Method button next to Add Property and enter for Method Name downloadHTML. Now insert this code below.

1
2
3
Data = Me.Get ("http://tutspolis.com", 3 )
 
Me.Close

The HTTPSocket has got a option called Get with will simply in this case get the html code of indicated URL. Our class will download for us the HTML from tutspolis.com.

Using a Class in REALbasic project

Now in GUI builder we will have a new control called cHTML. We can simply drag and drop it to our Window. To try out our new class add to the Window controls TextArea and PushButton. Double click on PushButton and enter the code:

1
2
3
4
Dim tuts As new cHTML
 
tuts.downloadHTML // get the html code
TextArea1.Text =  tuts.Data // display it in TextArea control

The effect

When we will press PushButton, TextArea will fill up with HTML code of tutspolis.com home page. You can now for example render the code, modify it or get only some important for you information. It can be also done in class cHTML on other Method.

Author: Jakub Pawlak

I'm interested in all. Currently working on the development of TUTSPOLIS and I hope that in near feature the project will be successful.

Leave a Reply

Copyrights (c) TUTSPOLIS | Powered by Wordpress MU | Inspired at Elegant Themes designed by qbap (HTML5 & CSS3)