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


(send private message)

Posts: 933
Topics: 55

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

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

//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

//call class procedure change, which will change var2 to 5000

//again write the contents to console

//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

//exit our application

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:


Currently Active Users:
There are currently 3 user(s) online. 0 member(s) and 3 guest(s)
Most users ever online was 1046, January 28, 2022, 2:08 pm.

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