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

avatar

(send private message)

Posts: 933
Topics: 55

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 4 user(s) online. 0 member(s) and 4 guest(s)
Most users ever online was 1046, January 28, 2022, 2:08 pm.


Statistics:
Threads: 225 | Posts: 1848 | Members: 51 | Active Members: 51
Welcome to our newest member, yecate
const Copyright = '2011-2024 © OverHertz Ltd. All rights reserved.';
Web development by OverHertz Ltd