user7247317
user7247317

Reputation:

Pascal - Whats causing this runtime error(216)?

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.

Upvotes: 2

Views: 618

Answers (1)

MK.
MK.

Reputation: 34597

OMG you just made me remember Pascal!

This is how you call the object constructor:

SafetyDepositBox := SDB.Create();

Upvotes: 3

Related Questions