SRL Archive - Lape

Form troubles..


Fitta

2014-10-25 08:11:37

I have a weird bug that is out of my knowledge..
When I run it and click start it crashes Simba!

Ideas?


program NMZ;
{$i AeroLib/AeroLib.Simba}

{
FORM VARIABLES
}
var
FittForm:TForm;
ButtonArr: array [0..1] of TButton;
ComboBox: TComboBox;
CheckBoxArr: array [0..3] of TCheckBox;
LabelArr: array [0..6] of TLabel;
EditArr: array [0..4] of TEdit;
SaveForm: Boolean;

{
SCRIPT VARIABLES
}
T: Array [0..2] of Timer;



const
default = 'Arial Black';

Button_OK = 0;
Button_Save = 1;

CheckBox_Prayer = 0;
CheckBox_Abs = 1;
CheckBox_Track = 2;
CheckBox_Logout = 3;

Label_FProg = 0;

Edit_FKEY = 0;
Edit_PrioStart = 1;
Edit_PrioEnd = 2;
Edit_BoostStart = 3;
Edit_BoostEnd = 4;

Timer_Boost = 0;
Timer_WaitPot = 1;
Timer_Flick_Prayer = 2;

Bool_Prio_Pot = 0;
Bool_Prio_Out = 1;
Bool_Boost_Out = 2;
Bool_Player_Prayer = 5;
Bool_Player_Abs = 7;
Bool_Player_Logout = 6;

Int_Boost_NextPot = 0;
Int_DrinkDoses = 1;
Int_Flick_Next = 2;
Int_Prio_NextPot = 3;
Int_Player_PrioStart = 4;
Int_Player_PrioEnd = 5;
Int_Player_BoostStart = 6;
Int_Player_BoostEnd = 7;

Str_Player_Skill = 0;

OUTLINE_VIAL = 75;



function getChecked(comp: TCheckBoxState): boolean;
begin
if comp = cbChecked then
Result := True;
end;

procedure SaveInfo;
begin
If Not SaveForm then
Exit;

WriteINI('nmz', 'skill', Me.Strings[Str_Player_Skill], ScriptPath + 'nmzsetup.ini');
WriteINI('nmz', 'prayer', BoolToStr(Me.Booleans[Bool_Player_Prayer]), ScriptPath + 'nmzsetup.ini');
WriteINI('nmz', 'abs', BoolToStr(Me.Booleans[Bool_Player_Abs]), ScriptPath + 'nmzsetup.ini');
WriteINI('nmz', 'logout', BoolToStr(Me.Booleans[Bool_Player_Logout]), ScriptPath + 'nmzsetup.ini');
WriteINI('nmz', 'priostart', IntToStr(Me.Integers[Int_Player_PrioStart]), ScriptPath + 'nmzsetup.ini');
WriteINI('nmz', 'prioend', IntToStr(Me.Integers[Int_Player_PrioEnd]), ScriptPath + 'nmzsetup.ini');
WriteINI('nmz', 'booststart', IntToStr(Me.Integers[Int_Player_BoostStart]), ScriptPath + 'nmzsetup.ini');
WriteINI('nmz', 'boostend', IntToStr(Me.Integers[Int_Player_BoostEnd]), ScriptPath + 'nmzsetup.ini');
end;

procedure loadInfo;
var
t_bool: Boolean;
begin
If FileExists(ScriptPath + 'nmzsetup.ini')then
begin

ComboBox.setCaption(ReadINI('nmz', 'skill', ScriptPath + 'nmzsetup.ini'));

t_bool := StrToBoolDef(ReadINI('nmz', 'prayer', ScriptPath + 'nmzsetup.ini'), False);
If t_bool then
begin
CheckBoxArr[CheckBox_Abs].setVisible(False);
FittForm.SetBounds(400, 320, 190, 400);
CheckBoxArr[CheckBox_Prayer].SetBounds(15, 15, 150, 150);
LabelArr[1].setCaption('Prayer');
end;

t_bool := StrToBoolDef(ReadINI('nmz', 'abs', ScriptPath + 'nmzsetup.ini'), False);
If t_bool then
begin
CheckBoxArr[CheckBox_Prayer].setVisible(False);
FittForm.SetBounds(400, 320, 190, 400);
CheckBoxArr[CheckBox_ABS].SetBounds(15, 15, 150, 150);
LabelArr[1].setCaption('Absorption');
end;

If StrToBoolDef(ReadINI('nmz', 'logout', ScriptPath + 'nmzsetup.ini'), False) then
CheckBoxArr[CheckBox_Logout].setState(cbChecked);

EditArr[Edit_PrioStart].setCaption(ReadINI('nmz', 'priostart', ScriptPath + 'nmzsetup.ini'));
EditArr[Edit_PrioEnd].setCaption(ReadINI('nmz', 'prioend', ScriptPath + 'nmzsetup.ini'));
EditArr[Edit_BoostStart].setCaption(ReadINI('nmz', 'booststart', ScriptPath + 'nmzsetup.ini'));
EditArr[Edit_BoostEnd].setCaption(ReadINI('nmz', 'boostend', ScriptPath + 'nmzsetup.ini'));

end;
end;

procedure procedure_OnClick(sender: TObject);
{$IFNDEF CODEINSIGHT}
native;
{$ENDIF}
begin
case Sender of
CheckBoxArr[CheckBox_Prayer]:
begin
Case CheckBoxArr[CheckBox_Prayer].getState of
cbChecked:
begin
CheckBoxArr[CheckBox_Abs].setVisible(False);
FittForm.SetBounds(400, 320, 190, 400);
CheckBoxArr[CheckBox_Prayer].SetBounds(15, 15, 150, 150);
LabelArr[1].setCaption('Prayer');
end;

cbUnchecked:
begin
CheckBoxArr[CheckBox_Abs].setVisible(True);
FittForm.SetBounds(400, 320, 320, 50);
CheckBoxArr[CheckBox_Prayer].SetBounds(15, 15, 150, 150);
end;

end;
end;

CheckBoxArr[CheckBox_Abs]:
begin
Case CheckBoxArr[CheckBox_Abs].getState of
cbChecked:
begin
CheckBoxArr[CheckBox_Prayer].setVisible(False);
FittForm.SetBounds(400, 320, 190, 400);
CheckBoxArr[CheckBox_ABS].SetBounds(15, 15, 150, 150);
LabelArr[1].setCaption('Absorption');
end;

cbUnchecked:
begin
CheckBoxArr[CheckBox_Prayer].setVisible(True);
FittForm.SetBounds(400, 320, 320, 50);
CheckBoxArr[CheckBox_ABS].SetBounds(15+145, 15, 150, 150);
end;

end;
end;

ButtonArr[Button_Save]:
begin
SaveForm := True;
end;

ButtonArr[Button_OK]:
begin
Me.Booleans[Bool_Player_Prayer] := (CheckBoxArr[CheckBox_Prayer].getState = cbChecked);
Me.Booleans[Bool_Player_Abs] := (CheckBoxArr[CheckBox_Abs].getState = cbChecked);
Me.Booleans[Bool_Player_Logout] := (CheckBoxArr[CheckBox_Prayer].getState = cbChecked);

Me.Integers[Int_Player_PrioStart] := StrToIntDef(EditArr[Edit_PrioStart].getCaption, -1);
Me.Integers[Int_Player_PrioEnd] := StrToIntDef(EditArr[Edit_PrioEnd].getCaption, -1);
Me.Integers[Int_Player_BoostStart] := StrToIntDef(EditArr[Edit_BoostStart].getCaption, -1);
Me.Integers[Int_Player_BoostEnd] := StrToIntDef(EditArr[Edit_BoostEnd].getCaption, -1);

FittForm.Close;
end;

end;
end;


procedure InitForm;
{$IFNDEF CODEINSIGHT}
native;
{$ENDIF}
var
I: Integer;
begin
FittForm.Init(nil);

with FittForm do
begin
SetCaption('FittForm');
SetBounds(408,321,320,50);
SetPosition(poScreenCenter);
SetBorderStyle(bsToolWindow);
SetColor(16777215);
GetFont().SetName(default);
GetFont().SetColor(536870912);
GetFont().SetSize(11);
end;


For I:=0 to High(ButtonArr)do
begin
ButtonArr[I].Init(FittForm);
with ButtonArr[I] do
begin
SetParent(FittForm);
SetBounds(20+(I*75), 360, 60, 25);
SetOnClick(procedure_OnClick);
GetFont().SetName(default);
GetFont().SetColor(536870912);
GetFont().SetSize(9);
end;
end;
ButtonArr[Button_OK].SetCaption('Start');
ButtonArr[Button_Save].SetCaption('Save');

ComboBox.Init(FittForm);
With ComboBox do
begin
SetParent(FittForm);
SetBounds(15, 100, 140, 28);
SetEnabled(True);
setCaption('Style of combat?');
GetItems().Add('Attack');
GetItems().Add('Strength');
GetItems().Add('Defence');
GetItems().Add('Range');
GetItems().Add('Mage');
SetOnClick(procedure_OnClick);
GetFont().SetName(default);
GetFont().SetColor(536870912);
GetFont().SetSize(7);
end;

For I:=0 to High(CheckBoxArr)do
begin
CheckBoxArr[I].Init(FittForm);

With CheckBoxArr[I] do
begin
SetParent(FittForm);
getFont().SetSize(7);
SetOnClick(procedure_OnClick);
SetBounds(15+(I*145), 15, 150, 150);
end;
end;
CheckBoxArr[CheckBox_Prayer].SetCaption('Using Prayer?');
CheckBoxArr[CheckBox_Abs].SetCaption('Using Absorption?');
CheckBoxArr[CheckBox_Logout].SetCaption('Logout when done?');
CheckBoxArr[CheckBox_Logout].setVisible(True);
CheckBoxArr[CheckBox_Logout].SetBounds(15, 50, 150, 150);
CheckBoxArr[CheckBox_Track].SetCaption('Track experience?');
CheckBoxArr[CheckBox_Track].setVisible(True);
CheckBoxArr[CheckBox_Track].SetBounds(15, 70, 150, 150);

For I:=0 to High(LabelArr)do
begin
LabelArr[I].Init(FittForm);

With LabelArr[I] do
begin
SetParent(FittForm);
getFont().SetSize(7);
SetBounds(15, 130+(I*40), 50, 50);
SetVisible(False);
end;
end;
LabelArr[Label_FProg].setCaption('F for progress');
LabelArr[Label_FProg].setVisible(True);
LabelArr[Label_FProg].SetBounds(35, 130, 50, 50);
LabelArr[Label_FProg].setEnabled(False);

LabelArr[1].setCaption('Absorption');
LabelArr[1].getFont().SetSize(9);
LabelArr[1].setVisible(True);
LabelArr[1].SetBounds(50, 180, 50, 50);

LabelArr[2].setCaption('Start');
LabelArr[2].getFont().SetSize(6);
LabelArr[2].setVisible(True);
LabelArr[2].SetBounds(35, 205, 50, 50);

LabelArr[3].setCaption('End');
LabelArr[3].getFont().SetSize(6);
LabelArr[3].setVisible(True);
LabelArr[3].SetBounds(100, 205, 50, 50);

LabelArr[4].setCaption('Overloads');
LabelArr[4].getFont().SetSize(9);
LabelArr[4].setVisible(True);
LabelArr[4].SetBounds(50, 240, 50, 50);

LabelArr[5].setCaption('Start');
LabelArr[5].getFont().SetSize(6);
LabelArr[5].setVisible(True);
LabelArr[5].SetBounds(35, 265, 50, 50);

LabelArr[6].setCaption('End');
LabelArr[6].getFont().SetSize(6);
LabelArr[6].setVisible(True);
LabelArr[6].SetBounds(100, 265, 50, 50);

For I:=0 to High(EditArr)do
begin
EditArr[I].Init(FittForm);

With EditArr[I] do
begin
SetParent(FittForm);
SetBounds(50, 100+(I*40), 50, 50);
SetVisible(False);
getFont().SetSize(7);
end;
end;
EditArr[EDIT_FKEY].SetBounds(44, 127, 15, 12);
EditArr[EDIT_FKEY].SetVisible(True);
EditArr[EDIT_FKEY].setEnabled(False);

EditArr[EDIT_PrioStart].SetBounds(65, 200, 15, 12);
EditArr[EDIT_PrioStart].SetVisible(True);

EditArr[Edit_PrioEnd].SetBounds(130, 200, 25, 12);
EditArr[Edit_PrioEnd].SetVisible(True);

EditArr[Edit_BoostStart].SetBounds(65, 260, 15, 12);
EditArr[Edit_BoostStart].SetVisible(True);

EditArr[Edit_BoostEnd].SetBounds(130, 260, 25, 12);
EditArr[Edit_BoostEnd].SetVisible(True);

loadInfo;
FittForm.ShowModal;
end;


procedure Free;
{$IFNDEF CODEINSIGHT}
native;
{$ENDIF}
begin
if (FittForm = nil) then
exit();
client.writeln('Freeing form...');
FittForm.free;
end;


procedure ShowForm();
begin
try
sync(InitForm);
except
writeln('ERROR: Failed to initialize form');
finally
sync(Free);
end;
end;



begin
initAL;
ClearDebug();
ShowForm();
SaveInfo;
end.

Olly

2014-10-25 10:37:12

You can't use readini, just call it before showing the form and save info in a global var