The following code throws an access violation at 106. I have tried doing some debug which can be seen starting at line 97. However I do not understand the error.
Here is the code in question.
Thanks for your time
MM
Code:
program new;
{$DEFINE SMART}
{$i AeroLib/AeroLib.Simba}
{$i Reflection/Reflection.simba}
type
Key = (Cooking, Fletching, Fishing, Firemaking, Woodcutting);
Choosen = set of Key;
Skill = Procedure;
TPair = record
K: Key;
V: Skill;
end;
TMap = array of TPair;
const
FULL_PATH = scriptPath + 'TestConfig.ini';
var
myForm: TForm;
myCheckList: TCheckListBox;
myTabControl: TPageControl;
myTabs: array [0..5] of TTabSheet;
myUserBox, MyPassBox, MyPinBox: TMemo;
myStartButton: TButton;
myTaskLabel, myUserLabel, myPassLabel, myPinLabel : TLabel;
myMainMenu: TMainMenu;
myMenuFile, mySubMenuSave, mySubMenuLoad: TMenuItem;
MyPlayer: TReflectLocalPlayer;
MyLogger: TReflectLogger;
function TMap.Add(K: Key; V: Skill): boolean;
var
I: Integer;
begin
for I := 0 to High(Self) do
if (Self[I].K = K) then
Exit(False);
SetLength(Self, Length(Self) + 1);
Self[High(Self)].K := K;
Self[High(Self)].V := @V;
exit(True);
end;
function TMap.Remove(K: Key): boolean;
var
I: Integer;
begin
if (Self.get(K) = nil) then
Exit(False);
for I := 0 to High(Self) - 1 do
if (Self[I].K = K) then
Swap(Self[I], Self[I + 1]);
SetLength(Self, Length(Self) - 1);
Exit(True);
end;
function TMap.Get(K: Key): Skill;
var
I: Integer;
begin
for I := 0 to High(Self) do
if (Self[I].K = K) then
Exit(@Self[I].V);
Exit(nil);
end;
procedure OnClickCheckList(sender: TObject; index: Integer);
{$IFNDEF CODEINSIGHT} native; {$ENDIF}
begin
if myCheckList.getChecked(index) then
begin
myTabs[index] := myTabControl.addTabSheet();
myTabs[index].setCaption(myCheckList.getItems().getStrings(index));
end
else
begin
myTabs[index].Free;
end;
end;
procedure onClick(sender: TObject);
{$IFNDEF CODEINSIGHT} native; {$ENDIF}
var
I : Integer;
begin
case sender of
myStartButton:
begin
myForm.Free;
end;
mySubMenuSave:
begin
//Client.Writeln(myCheckList.getItems().getStrings(1));
//Client.Writeln( BoolToStr(myCheckList.getChecked(1)) );
//Client.WriteLn(FULL_PATH);
for I:= 0 to myCheckList.getItems.getCount - 1 do
begin
Client.Writeln('In iteration ' + IntToStr(I));
Client.Writeln(' ' + myCheckList.getItems().getStrings(I));
Client.Writeln(' ' + BoolToStr(myCheckList.getChecked(I)));
Client.Writeln('Does ' + FULL_PATH + ' exist? ' + BoolToStr(FileExists(FULL_PATH)));
WriteINI('Tasks', myCheckList.getItems().getStrings(I), BoolToStr(myCheckList.getChecked(I)), FULL_PATH);
end;
end;
mySubMenuLoad:
begin
end;
end;
end;
procedure InitGUI;
{$IFNDEF CODEINSIGHT} native; {$ENDIF}
var
I : Integer;
K : Key;
begin
with myForm do
begin
Init(nil);
SetCaption('Edgeville Extravaganza');
setBounds(0, 0, 400, 170);
setPosition(poScreenCenter);
end;
myMainMenu.Init(myForm);
myMenuFile := myMainMenu.AddMenu('File');
mySubMenuSave := myMenuFile.addMenu('Save');
mySubMenuLoad := myMenuFile.addMenu('Load');
mySubMenuSave.setOnClick(onClick);
mySubMenuLoad.setOnClick(onClick);
with myTabControl do
begin
Init(myForm);
setParent(myForm);
setBoundsRect(myForm.getBaseBounds);
myTabs[0] := addTabSheet();
myTabs[0].setCaption('Main');
end;
with myTaskLabel do
begin
Init(myForm);
setParent(myTabs[0]);
setCaption('Select Tasks:');
setLeft(5);
setTop(5);
end;
with myCheckList do
begin
Init(myForm);
setParent(myTabs[0]);
setLeft(myTaskLabel.getLeft);
setTop(myTaskLabel.getTop + myTaskLabel.getHeight + 5);
setHeight(95);
for K := Low(Key) to High(Key) do
getItems().add(ToStr(k));
setOnItemClick(OnClickCheckList);
end;
with myUserLabel do
begin
Init(myForm);
setParent(myTabs[0]);
setCaption('Enter User Info:');
setLeft(myCheckList.getLeft + myCheckList.getWidth + 10);
setTop(myTaskLabel.getTop);
end;
with myUserBox do
begin
Init(myForm);
setParent(myTabs[0]);
setText('Username or EMail');
setLeft(myUserLabel.getLeft);
setTop(myUserLabel.getTop + myUserLabel.getHeight + 5);
setWidth(270);
setHeight(25);
end;
with myPassLabel do
begin
Init(myForm);
setParent(myTabs[0]);
setCaption('Password:');
setLeft(myUserBox.getLeft);
setTop(myUserBox.getTop + myUserBox.getHeight);
end;
with MyPassBox do
begin
Init(myForm);
setParent(myTabs[0]);
setText('Password');
setLeft(myPassLabel.getLeft);
setTop(myPassLabel.getTop + myPassLabel.getHeight);
setWidth(150);
setHeight(25);
setPasswordChar('*');
setMaxLength(20);
end;
with myPinLabel do
begin
Init(myForm);
setParent(myTabs[0]);
setCaption('Pin:');
setLeft(myUserBox.getLeft + myUserBox.getWidth - getWidth - 15);
setTop(myUserBox.getTop + myUserBox.getHeight);
end;
with MyPinBox do
begin
Init(myForm);
setParent(myTabs[0]);
setWidth(80);
setHeight(25);
setLeft(myPinLabel.getLeft);
setTop(MyPassBox.getTop);
setMaxLength(4);
setPasswordChar('*');
end;
with MyStartButton do
begin
Init(myForm);
setParent(myTabs[0]);
setCaption('Start');
setLeft(MyPinBox.getLeft);
setTop(MyPinBox.getTop + MyPinBox.getHeight + 5);
end;
myForm.ShowModal;
end;
procedure FreeGUI;
{$IFNDEF CODEINSIGHT} native; {$ENDIF}
begin
if (myForm = nil) then
exit;
MyLogger.Status('Freeing GUI...');
myForm.free;
end;
procedure StartGUI;
begin
try
sync(InitGUI);
except
MyLogger.Error('Failed to initialize GUI!');
finally
sync(FreeGUI);
end;
end;
procedure Cook;
begin
Writeln('Cook!');
end;
procedure Fletch;
begin
Writeln('Fletch!');
end;
procedure Fish;
begin
Writeln('Fish!');
end;
procedure Burn;
begin
Writeln('Burn!');
end;
procedure Chop;
begin
Writeln('Chop!');
end;
function GearInInv() : Boolean;
begin
Result:= true;
end;
function GearInEquip() : Boolean;
begin
Result:= true;
end;
function HasGear() : Boolean;
begin
Result:= GearInEquip OR GearInInv;
end;
var
Perform: TMap;
begin
StartGUI();
{Perform.add(Cooking, @cook);
if (Perform.get(Cooking) <> nil) then //check if it exists..
Perform.get(Cooking)(); //call the function.
Perform.get(Firemaking)();
//writeln();
Perform.remove(Cooking);
writeln(Perform.get(Cooking)); }
end.