Classes

xDev lets you write a class in two ways: in .prg code with CREATE CLASS, or in C with the runtime API of classes.h. The program uses both the same way. The class function, such as Point(), returns a new object, Point():New( 1, 2 ) sets its variables, and oPoint:Move( 1, 1 ) sends it a message.

A class in .prg is the usual choice. It has typed variables (DATA x AS FLOAT), class variables, methods, properties with ACCESS and ASSIGN, inheritance with FROM and Super, scopes (EXPORTED, PROTECTED, HIDDEN, READONLY), operators, DELEGATE, ON ERROR and destructors. xdev compiles it to machine code like any other .prg code.

A class in C fits where the work is done in C anyway: a wrapper of a C library, a data structure that must be fast, or code that talks to the operating system. Its methods are C functions; the class is made once at run time and then behaves like a .prg class, with typed variables and checked arguments. The C file is compiled with exception support and linked with the program, either as an object file or in a static library.

Classes in PRG shows a complete class with inheritance. Classes in C shows the Point class in C, ready to compile, and the program that uses it.

C

Classes in C

Write a class in C and use it from .prg code

Classes in PRG

Write a class in .prg code with CREATE CLASS