akarigar
2014-11-10 16:36:50
Hey guys, I was wondering if someone could point me in the right direction here. I want to achieve something like the following.
...
function exec(f: function(x: integer): boolean; x: integer);
begin
result := f(x);
end;
begin
...
writeLn(exec(@bankScreen.open, x));
end.
Of course, the above won't work. So I looked around and found this, which says to use of object. This kind of works, but doesn't. Let's take a look at the following example.
program Example;
{$DEFINE SMART}
{$i srl-6/srl.simba}
type TSimpleFunction = function(x: integer): boolean of object;
function runSimpleFunction(f: TSimpleFunction; x: integer): boolean;
begin
result := f(x);
end;
begin
clearDebug();
setupSRL();
writeLn('bankScreen.open:');
writeLn(runSimpleFunction(@bankScreen.open, BANK_CHEST_LUMBRIDGE));
writeLn('bankScreen.clickButton:');
writeLn(runSimpleFunction(@bankScreen.clickButton, BANK_BUTTON_PRESET_1));
end.
The result of running the above is:
bankScreen.open:
-- TRSBankscreen.__openChest()
---- isMouseOverText()
------ Current mouse-over text: "Use Bank chest"
------ Found "Use Bank" in mouse-over string: "Use Bank chest"
---- isMouseOverText(): True
---- Succesfully opened the bank
-- TRSBankscreen.__openChest() result = true
True
bankScreen.clickButton:
Error: Access violation at line 1173
Execution failed.
Line 1173 of bankscreen.simba is:
result := (not self.isOpen());
I would have been okay with the results if both functions failed, you know, since TRSBankScreen is a record with no apparent relation to TObject. But it doesn't do that. I'm not sure what's causing this access violation, anyone know? I have checked, self is set to bankScreen, and it exists. So my question is why is this happening? How do I get around it? Is it possible to do what I'm trying to do in Lape? Bonus question: are classes for Lape under development? Thanks in advance!