Register | Login
Forum Index > Samples > Sample class usage
Author Message
Pages: 1
Admin
Site Admin

avatar

(send private message)

Posts: 923
Topics: 54

Location:
OverHertz Studio
[32] Sample class usage - posted: 2011-05-12 16:41:56
A small sample showing how to create and use a class in Ziron

compiled with Ziron 1.1.12.2

Code:
program WIN32CUI 'Sample';

//include simple memory manager - required for new, delete
#include 'smm32.zir';

//include console helpers
#include 'console.zir';

//declare our class named ZClass, which will use register edi
class ZClass uses edi {
  //declare some class variables
  DWord var1;
  DWord var2;
  
  //declare a class procedure named "change"
  procedure change() {
    //assign 5000 to this instance var2
    this.var2 = 5000;  
    //return to where we were called
    ret
  }
}

//declare our class pointer; note no * - classes are always pointers.
ZClass c;

//create a new instance
c = new ZClass;

//lets first store edi
push edi;

//we will use edi also to access the class object
edi = c as ZClass;

//set var2 to 100
edi.var2 = 100;

//write the 100 to the console; note we set our class to use edi, but not to worry
//edi is protected by the class so it will be restored on return
WriteNumber(edi.var2);

//call class procedure change, which will change var2 to 5000
edi.change();

//again write the contents to console
WriteNumber(edi.var2);

//no longer use edi
edi as nothing;

//restore edi's contents
pop edi;

//delete the class instance
delete c;

//sleep for 1 second to see output
Sleep(1000);

//exit our application
ExitProcess(0);


if you have any questions, do not hesitate to ask.

Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Pages: 1
create new reply


Quick reply:

Message:



Currently Active Users:
There are currently 1 user(s) online. 0 member(s) and 1 guest(s)
Most users ever online was 533, May 5, 2016, 7:19 am.


Statistics:
Threads: 223 | Posts: 1835 | Members: 49 | Active Members: 49
Welcome to our newest member, pierrotstudio
const Copyright = '2011-2017 © OverHertz Ltd. All rights reserved.';
Web development by OverHertz Ltd