How come the lape functions are formatted like this?
Simba Code:procedure TRSInterface.setBounds(newBounds: TBox);
How do you get the dot in there? What record is it pointing to I don't understand
How come the lape functions are formatted like this?
Simba Code:procedure TRSInterface.setBounds(newBounds: TBox);
How do you get the dot in there? What record is it pointing to I don't understand
It's a method specifically for the TRSInterface type. (it's like equivalent to a public static method for static class in java)
So you can do like:
Simba Code:varA: TRSInterface;
//some other code to initialize varA
varA.setBounds();
Within the setBounds body, it could refer to the TRSInterface by calling 'Self'.
Eg.
Simba Code:procedure TBox.printX1;
begin
writeln(Self.X1); //prints x1 of the box
writeln(X1); //does the same thing as ^
end;
begin
IntToBox(1, 2, 3, 4).printX1;
end.
Last edited by riwu; 09-25-2013 at 10:43 PM.
The function you posted (TRSInterface.setBounds(blah)) in the first post is a function that refers to the actual type "TRSInterface" and not a variable.
Lape adds the function to the type record so that when you assign that type record to a variable, say "someVariable : TRSInterface" you can then call "someVariable.setBounds(blah)"
Simba Code:type color = record
test:string;
end;
function color.showColor:string;
begin
result := self.test;
end;
begin
end.
wee ok got it
That method makes things faster right?
Performance wise, there's no significant difference if you access the record field directly instead. Though if you create a getter and setter method for each field you could imitate object-oriented programming, though not quite the case since you can't declare the fields as private.
The main purpose of type methods is just to make methods more readily understood and the code more readable.
For instance, you will need to remember to use GetTPABounds() to get the bound of a TPA, and GetATPABounds() to get the bound of ATPA.
If the developer create type methods for both of them to return the bounds, you can simply do
So in essence, you just need to remember to call .getBounds to get the bound of whichever typeSimba Code:TPA.getBounds(); //gets the bound of TPA
ATPA.getBounds(); //gets the bound of ATPA
As all non-primitives are stored as references (pointers to the memory addresses) in lape, this feature is extremely useful as we can just make .equals methods for all the types (rather than a standard-alone function for every type, which is much harder to use and uglier as well)
Last edited by riwu; 09-26-2013 at 11:24 AM.
An example of how this can be used is this:
Simba Code:type
TSomeType = record
weHaveSomeVariables : array [0..3] of Integer;
end;
function TSomeType.toBox(): TBox;
begin
result := intToBox(self.weHaveSomeVariables[0], self.weHaveSomeVariables[1],
self.weHaveSomeVariables[2], self.weHaveSomeVariables[3]);
end;
function TBox.searchForColor(whatColor : Integer): Boolean;
begin
// if (CODE GOES HERE) then
result := True;
end;
var
Weehaw : TSomeType;
begin
Weehaw.weHaveSomeVariables := [2, 3, 4, 5];
if Weehaw.toBox().searchForColor(0) then
writeLn('Found the color 0 in the box created from Weehaw');
end.
Which means you can create incredibly long lines that do the same job as 20 lines of code do without taking away readability.
There are currently 1 users browsing this thread. (0 members and 1 guests)