PDA

View Full Version : Function Pointer Access Violation



gmkizzle
08-27-2016, 10:47 PM
Trying to write a function that waits for the result of a function().

function ConditionWait(condition: function: Boolean; ms: Integer): Boolean;
var
timeout: TCountDown;
begin
timeout.SetTime(ms);;
repeat
if (timeout.IsFinished()) then
Exit(False);
until(condition()); // Access Violation Here
Exit(True);
end;

This is how I am calling it. I am getting an access violation.
if (ConditionWait(@TDialogue.HasDialogue(), 5000)) then
begin
// ...
end

Laquisha
08-28-2016, 12:52 AM
Trying to write a function that waits for the result of a function().

function ConditionWait(condition: function: Boolean; ms: Integer): Boolean;
var
timeout: TCountDown;
begin
timeout.SetTime(ms);;
repeat
if (timeout.IsFinished()) then
Exit(False);
until(condition()); // Access Violation Here
Exit(True);
end;

This is how I am calling it. I am getting an access violation.
if (ConditionWait(@TDialogue.HasDialogue(), 5000)) then
begin
// ...
end

Good luck figuring out any ogLib code - the most un-user-friendly thing ever to be written on these forums.

Anyway, just use waitTypeFunc() from SRL-6. Should be what you need.

https://github.com/SRL/SRL-6/blob/master/lib/utilities/time.simba#L331

Kasi
08-28-2016, 02:44 AM
Remove parenthesis.

AFools
08-28-2016, 03:11 AM
Good luck figuring out any ogLib code - the most un-user-friendly thing ever to be written on these forums.

Anyway, just use waitTypeFunc() from SRL-6. Should be what you need.

https://github.com/SRL/SRL-6/blob/master/lib/utilities/time.simba#L331

LOLed!

tomhank1511
11-23-2016, 08:45 AM
Good luck figuring out any ogLib code

tls
11-23-2016, 05:46 PM
First off, you are trying to call a type function without using a reference to an actual instance of that type.
Second, you are trying to pass in a different type than is expected. When using a type function you have to append "of object" to the return type of the parameter:


program new;

type foo = record
bar: integer;
end;

function foo.baz(): boolean;
begin
exit(true);
end;

// what you have
function waitforcondition(callback: function: boolean; timeout: integer): boolean;
var
start: longword;
begin
start := getsystemtime;
while (start + timeout) >= getsystemtime do
begin
if callback then exit(true);
wait(5);
end;
end;

// what you need
function waitforcondition(callback: function: boolean of object; timeout: integer): boolean; overload;
var
start: longword;
begin
start := getsystemtime;
while (start + timeout) >= getsystemtime do
begin
if callback then exit(true);
wait(5);
end;
end;

var
f: foo;
begin
// create an instance of foo
f := [1];
// use that instance's function reference, not the type reference
writeln(waitforcondition(@f.baz, 3000));
end.

Joopi
11-23-2016, 09:40 PM
This thread was dead since a long time but the spambot grave dug it...

Harrier
11-24-2016, 12:14 AM
This thread was dead since a long time but the spambot grave dug it...

So? tls gave a decent answer which explained stuff which wasn't in earlier posts and it wasn't grave dug according to the current rules.

acow
11-24-2016, 01:25 AM
So? tls gave a decent answer which explained stuff which wasn't in earlier posts and it wasn't grave dug according to the current rules.

Joopi; was just practicing not quoting/@mentioning anybody in a post. Exceptional work this time around fam, keep it up.

rj
11-24-2016, 02:52 AM
Joopi; was just practicing not quoting/@mentioning anybody in a post. Exceptional work this time around fam, keep it up.

yeah exceptional backseat modding by Joopi as always LOL


why did the derep button have to go

Joopi
11-24-2016, 02:42 PM
My point being that whoever asked this question has long since stopped caring and hasnt even been logged in for several weeks. Harrier;

But sure someone, at some point, might need it in 10 years or so. But not worth the effort.

Harrier
11-24-2016, 05:34 PM
My point being that whoever asked this question has long since stopped caring and hasnt even been logged in for several weeks. Harrier;

But sure someone, at some point, might need it in 10 years or so. But not worth the effort.

Just because someone hasn't logged in for two weeks means you shouldn't answer it and explain it? My God and tls put the effort in so who cares? It's there is someone needs it in the future.