SRL Archive - OSR Help

Out of Range in form


bbri06

2010-06-07 23:28:24

Can't figure this one out :mad:


program new;
{.include SRl/SRL.scar}

Type
TFormPlayers = Record
Name, Pass, Nick, Pin : String;
Active : boolean;
End;

var
frmDesign : TForm;
Buttons : Array [0..2] of TButton;
Labels: Array [0..6] of TLabel;
LabelNames: Array of String;
LabelPosX, EditPosX, EditPosY, LabelPosY: TIntegerArray;
EditBoxes: Array [0..5] of TEdit;
List1: TListBox;
ComboBox1: TComboBox;
FormPlayers : Array of TFormPlayers;
i: integer;

Function PlayersInINI(var NPlayers: integer): boolean;
begin
NPlayers := StrToInt(ReadINI('NumCharacters', 'Num', 'scripts/BbriConfigFile.ini'));
Result := (NPlayers > 0);
end;

Function LoadCharsINIList: TStringArray;
var
i, NPlayers: integer;
s: string;
begin
Writeln('Loading players');
PlayersInINI(NPlayers);
SetLength(Result, NPlayers);
for i := 0 to NPlayers - 1 do
begin
Result[i] := ReadINI('Character' + IntToStr(i), 'Name', 'scripts/BbriConfigFile.ini');
end;
end;

Procedure SaveItem;
var
OldNum, i: integer;
NewNum: string;
begin
OldNum := StrToInt(ReadINI('NumCharacters', 'Num', 'Scripts/BbriConfigFile.ini'));
NewNum := IntToStr((OldNum + 1));
WriteINI('NumCharacters', 'Num', NewNum, 'Scripts/BbriConfigFile.ini')
NewNum := IntToStr(OldNum);;
WriteINI('Character' + (NewNum), 'Name', EditBoxes[3].Text, 'Scripts/BbriConfigFile.ini');
WriteINI('Character' + (NewNum), 'Pass', EditBoxes[4].Text, 'Scripts/BbriConfigFile.ini');
WriteINI('Character' + (NewNum), 'Nick', EditBoxes[5].Text, 'Scripts/BbriConfigFile.ini');
WriteINI('Character' + (NewNum), 'Pin', EditBoxes[6].Text, 'Scripts/BbriConfigFile.ini');
for i := 3 to 6 do
EditBoxes[i].Clear;
end;

Procedure DeleteItem;
begin
end;

Procedure FormEnd;
var
i: integer;
begin
if(Length(FormPlayers) = 0)then
begin
Writeln('No players selected to use');
Writeln('Script is terminating');
frmDesign.ModalResult := mrOk;
TerminateScript;
end;
Writeln('Starting script using the following players');
for i := 0 to High(FormPlayers) do
Writeln(FormPlayers[i].Name);
frmDesign.ModalResult := mrOk;
end;

Procedure ButtonClick(Sender:TObject);
begin
Case Sender of
Buttons[0] : begin
if(Length(EditBoxes[2].Text) > 0)
and (Length(EditBoxes[3].Text) > 0)
and (length(EditBoxes[4].Text) > 0)
and (Length(EditBoxes[5].Text) > 0)then
begin
List1.Items.Add(EditBoxes[2].Text)
SaveItem;
end else
Writeln('Please fill out the character info boxes.');
end;
Buttons[1] : FormEnd;
Buttons[2] : ;
end;
end;

Procedure ListClick(Sender: TObject);
begin
comboBox1.CLEAR;
ComboBox1.Items.Add('Active');
end;

Procedure SetupPlayer(PlayerIndex: integer);
begin
SetLength(FormPlayers, (High(FormPlayers) + 2));
FormPlayers[High(FormPlayers)].Name := ReadINI('Character' + IntToStr(PlayerIndex), 'Name', 'Scripts/BbriConfigFile.ini');
FormPlayers[High(FormPlayers)].Pass := ReadINI('Character' + IntToStr(PlayerIndex), 'Pass', 'Scripts/BbriConfigFile.ini');
FormPlayers[High(FormPlayers)].Nick := ReadINI('Character' + IntToStr(PlayerIndex), 'Nick', 'Scripts/BbriConfigFile.ini');
FormPlayers[High(FormPlayers)].Pin := ReadINI('Character' + IntToStr(PlayerIndex), 'Pin', 'Scripts/BbriConfigFile.ini');
FormPlayers[High(FormPlayers)].Active := True;
end;

Procedure ActiveSet(Sender: TObject);
begin
if(ComboBox1.ItemIndex = 0)then
SetupPlayer(List1.ItemIndex);
end;

procedure InitForm;
var
i, BoxWidth, NPlayers: integer;
PlayersINI: TStringArray;
begin
frmDesign := CreateForm;
frmDesign.Left := 100;
frmDesign.Top := 100;
frmDesign.Width := 600;
frmDesign.Height := 400;
frmDesign.Caption := 'Bbri06s Edgeville Fly Fisher';
frmDesign.Color := 13755364;
frmDesign.Font.Name := 'Calibri';
frmDesign.Font.Color := CLBlack;

for i := 0 to 2 do
begin
Buttons[i] := Tbutton.Create(frmDesign);
Buttons[i].Parent := frmDesign;
Buttons[i].left := 140 + (i * 110);
Buttons[i].Top := 340;
Buttons[i].Width := 100;
Buttons[i].Height := 30;
Buttons[i].OnClick := @ButtonClick;
end;
Buttons[0].Caption := 'Add Player';
Buttons[1].Caption := 'Start Script';
Buttons[2].Caption := 'Del Player';

LabelPosX := [60, 220, 220, 332, 332, 332, 332];
LabelPosY := [80, 82, 127, 100, 140, 180, 220];
LabelNames := ['Players list', 'Break after', 'Break for', 'Username', 'Password', 'Nickname', 'Pin'];
for i := 0 to 6 do
begin
Labels[i] := TLabel.Create(frmDesign);
Labels[i].Parent := frmDesign;
Labels[i].Left := LabelPosX[i];
Labels[i].Top := LabelPosY[i];
Labels[i].Caption := LabelNames[i];
end;

EditPosX := [210, 210, 415, 415, 415, 415];
EditPosY := [100, 145, 100, 140, 180, 220];
for i := 0 to 5 do
begin
if(i > 1)then
BoxWidth := 175
else
BoxWidth := 100;
EditBoxes[i] := TEdit.Create(frmDesign);
EditBoxes[i].Parent := frmDesign;
EditBoxes[i].Top := EditPosY[i];
EditBoxes[i].Left := EditPosX[i];
EditBoxes[i].Width := BoxWidth;
EditBoxes[i].Height := 20;
end;
EditBoxes[5].Text := 'Set to "0000" for no pin';
EditBoxes[3].PasswordChar := '*';

List1 := TListBox.Create(frmDesign);
List1.Parent := frmDesign;
List1.Top := 100;
List1.Left := 10;
List1.Width := 175;
List1.Height := 175;
List1.OnClick := @ListClick;
if(PlayersInINI(NPlayers))then
begin
PlayersINI := LoadCharsINIList;
for i := 0 to High(PlayersINI) do
begin
Writeln('Loaded Player ' + PlayersINI[i]);
List1.Items.Add(PlayersINI[i]);
end;
end;

ComboBox1 := TComboBox.Create(frmDesign);
ComboBox1.Parent := FrmDesign;
ComboBox1.Top := 280;
ComboBox1.Left := 40;
ComboBox1.Width := 80;
ComboBox1.Height := 20;
ComboBox1.OnChange := @ActiveSet;
end;

procedure SafeInitForm;
var
v: TVariantArray;
begin
setarraylength(V, 0);
ThreadSafeCall('InitForm', v);
end;

procedure ShowFormModal;
begin
frmDesign.ShowModal;
end;

procedure SafeShowFormModal;
var
v: TVariantArray;
begin
setarraylength(V, 0);
ThreadSafeCall('ShowFormModal', v);
end;

Procedure SetupFormConfig;
var
FileNum: integer;
begin
writeln('Setting up player info file');
CreateFile('Scripts/BbriConfigFile.ini');
Writeln('Waiting for file creation');
Wait(2000);
Writeln('File should be made; script must be restarted now');
TerminateScript;
end;

begin
if(not(FileExists('Scripts/BbriConfigFile.ini')))then
SetupFormConfig;
if(ReadINI('NumCharacters', 'Num', 'scripts/BbriConfigFile.ini') = '')then
WriteINI('NumCharacters', 'Num', '0', 'scripts/BbriConfigFile.ini');
SetLength(FormPlayers, 0);
SafeInitForm;
SafeShowFormModal;
end.

Out of Range error at this line


procedure ShowFormModal;
begin
frmDesign.ShowModal;
end; //this line

Only gets the out of range error in Simba after I have closed the form, but when I click the AddPlayer button, I get a Simba popup that tells me to press ok to risk data corruption or cancel to kill the program. Help please

FrostFyr

2010-06-08 15:10:58

I do belive that you trying to use boxes 0..6 and have only declared 0..5
also filenames should have \'s not /'s

Hopefully that clears your problems :)

bbri06

2010-06-08 16:30:09

Filenames work either way and 0..5 is correct, I believe. I'm using 6 edit boxes.

Cazax

2010-06-09 09:27:53

Line 51-56:
WriteINI('Character' + (NewNum), 'Name', EditBoxes[3].Text, 'BbriConfigFile.ini');
WriteINI('Character' + (NewNum), 'Pass', EditBoxes[4].Text, 'BbriConfigFile.ini');
WriteINI('Character' + (NewNum), 'Nick', EditBoxes[5].Text, 'BbriConfigFile.ini');
WriteINI('Character' + (NewNum), 'Pin', EditBoxes[6].Text, 'BbriConfigFile.ini');
for i := 3 to 6 do
EditBoxes[i].Clear;
If you have 6 boxes from 0 to 5 so you should have:
  WriteINI('Character' + (NewNum), 'Name', EditBoxes[2].Text, 'BbriConfigFile.ini');
WriteINI('Character' + (NewNum), 'Pass', EditBoxes[3].Text, 'BbriConfigFile.ini');
WriteINI('Character' + (NewNum), 'Nick', EditBoxes[4].Text, 'BbriConfigFile.ini');
WriteINI('Character' + (NewNum), 'Pin', EditBoxes[5].Text, 'BbriConfigFile.ini');
for i := 2 to 5 do
EditBoxes[i].Clear;
and I recommend you to use a constant for the ini location, so you don't have to type it every time you use it:

Const
INI_LOC = 'Scripts/BbriConfigFile.ini';

...

WriteINI('Character' + (NewNum), 'Name', EditBoxes[2].Text, INI_LOC);
WriteINI('Character' + (NewNum), 'Pass', EditBoxes[3].Text, INI_LOC);
WriteINI('Character' + (NewNum), 'Nick', EditBoxes[4].Text, INI_LOC);
WriteINI('Character' + (NewNum), 'Pin', EditBoxes[5].Text, INI_LOC);
It also makes it easier to edit if you want a different location.

bbri06

2010-06-09 16:04:22

:) Thanks for the fix and the advice on the const. + rep