PAGE #4 - Introducing Standard Compiler Methods
We now demonstrate the ease of using, what I call, "standard compiler methods".
I suggest that every standard compiler method starts with the numeral sign: "#".
For example, I suggest that every object/class should come endowed with two standard write methods, one for Write(*) and the other for Writeln(*).
When one writes an object/class this standard write method is invoked.
It should be made virtual so that the programmer can override it as he wishes.
Consider the following code as example of the use of a standard write method.
Program Example_Of_Standard_Write_Method;
interface
uses
Classes;
type
some_object_type = object
Procedure #Write; virtual;
Procedure #Writeln; virtual;
end;
implementation
Procedure some_object_type.#Write;
begin
write( 'Now you can write an object!' );
end;
Procedure some_object_type.#Writeln;
begin
#Write;
writeln;
end;
var
some_object : some_object_type;
begin
New( some_object );
some_object.#Writeln; // Outputs: "Now you can write an object!"
writeln( 'My object writes: "', some_object, '" !' ); // Outputs: "My object writes: "Now you can write an object!" !"
Dispose( some_object );
end;
Output for previous code:
Now you can write an object!
My object writes: "Now you can write an object!" !Observe that in the line
writeln( 'My object write: "', some_object, '" !' );
the writeln function accesses some_object.#Write; if this standard compiler method is not implemented within the object/class, then we should always have some default method to be used.
So now we can send any general class/object to the write or writeln functions. Other standard compiler methods should be made as needed (perhaps #read, #readln, ..).