2
votes

Whenever I run SafteyDepositBox.SetNewCode I get a runtime error 216. Any idea whats causing this? This is the error :

Runtime error 216 at $00401EFC
$00401EFC
$0040153D

$00401596
$00406E31

program Boxy;
{$MODE OBJFPC}
{$M+}
type
 SDB = class
  private
   State : string;
   Code : string;
  public
   Constructor Create();
   procedure SetNewCode(newcode:string);
   function Valid(s:string):boolean;
end;

constructor SDB.Create();
begin
 State := 'Open-NoCode';
 Code := ''; 
end;

procedure SDB.SetNewCode(newcode:string);
begin
 Code := newcode;
 writeln(Code);
end;

function SDB.Valid(s:string):boolean;
var
 IsValid : boolean;
begin 
 If (length(s) = 4) then
  IsValid := true
 else
  IsValid := false;
 Valid := IsValid;
end;

var 
 SafetyDepositBox : SDB;
begin
 SafetyDepositBox.Create();
 SafetyDepositBox.SetNewCode('r2d2');// runtime error 216 here
end.
1
See this question asked yesterday: stackoverflow.com/questions/42064576/… - Marco van de Voort
You could also compile with the -gp -gl FPC options to get a bit more help rather than a raw stack dump. - tonypdmtr

1 Answers

3
votes

OMG you just made me remember Pascal!

This is how you call the object constructor:

SafetyDepositBox := SDB.Create();