Cast a spell
Since version 2.0 of PPL will be a full blown object-oriented development environment, the PPL language syntax must be as unique and flexible as possible when it comes to object-oriented syntax. We have implemented a new feature that will make object-oriented libraries a pleasure to use. (Note: This might exists in other languages already, I have not encountered this feature so far).
Let’s take the following class:
#class PTest
private(v$);nproc Create
v$ = Args$[0];
end;public proc Show
ShowMessage(v$);
end;
#endclass
Nothing fancy about it, simple stupid. Now if you want to use it you would normally use the following code:
local(t$);
t$ = new PTest(10);
t.Show;
t.Free;
This is a little long if you just want to use the class to access one of its public method. Now take the following code, it is much easier to use, clean and saves you coding time:
PTest(10).Show;
This line of code will do the following internally:
- - Create a new temporary PTest class object.
- - Initialize it with the value 10.
- - Call the Show method.
- - Free the object from memory.
Now I hear you think, ok, nice, but what will be useful for ? In PPL 2.0 we have a PFile class that can do all sort of manipulation on files. Using it normally would result in the following code to delete a file:
f$ = new PFile(“c:\\myfile.txt”);
f.Delete;
f.Free;
With the new method, imagine how cool it would be:
PFile(“c:\\myfile.txt”).Delete;
That’s it, very easy, one line and your done.
What about the PDirectory class?
files$ = PDirectory(“c:\\MyFolder”).Scan;
ForEach(files$)
ShowMessage(files$);
end;
Since we are implementing this new feature, class type casting syntax as to be changed a little:
Before you would do the following:
PCastClass(MyObject$).Method(10, 20, 30);
Now you need to do the following:
Cast(“PCastClass”, MyObject$).Method(10, 20, 30);
It is not really harder but since class type casting will be used less frequently than that one liner object creation disposal syntax, we have a decided to change the cast typing syntax.


