jhildy
07-14-2007, 03:16 AM
Ok first things first. i know everyone has seen the forms with unlimited players and i am going to demonstrate how to do this. This technique was created by RSN and all of the procedures were probably made by him. I will just teach you to adapt them to your script.
1.First off go into Srl/SRL/misc/UsersManager.scar
2.Copy all of those procedures in there except "LoadForm" "TheForm" "ShowFormModal" and "TehForm" you don't have to copy the vars, only the procedure that i did not mention.
3.Setting up your form. First off you have to have created your form with every necissary object. For example
ignore everything that has an x over it they are all just to make it more user friendly. but everything else is necissary for the user manager to work for what i am doing.
http://img526.imageshack.us/img526/7097/tutorialpic1yz2.th.png (http://img526.imageshack.us/my.php?image=tutorialpic1yz2.png)
In this script i had
Players[0].Name
Players[0].Pass
Players[0].Nick
Players[0].Integer[0]
Players[0].Active
I believe you can tell which of these represents each object in my form if not i will go into greater detail.
So i made my form for those specific Player variables.
Next you need to add those four buttons that are not Xed out.
Make one a left arrow(<-,<=,ect.) one say Add Player one say Delete Player and one with a right arrow(=>,->). The last thing you can do is add a groupbox to make it look neater (it is the Box that says Player Control around my buttons. Although this is not necissary to make this function, it looks neater. Another thing you should do is name your Edit1,Edit2 objects something easy like Eduser,Edpass,Ednick,Edloads,ect. Naming Eduser,Edpass,and Ednick makes your life easier since in RSN's procedures thats what the variables are already set as. Also add a label in the corner and name it lblUser.
4. Adapting the procedures. Ok this part takes the longest. Paste RSN's procedures into your script. As you look at his procedures, you probably can guess what you have to do. I will go through step by step anyway.
Look at this Procedure.
procedure AddUser;
begin
SetArrayLength(Players, GetArrayLength(Players) + 1);
Players[GetArrayLength(Players) - 1].Name := 'New Name';
Players[GetArrayLength(Players) - 1].Pass := 'New Pass';
Players[GetArrayLength(Players) - 1].Nick := 'New Nick';
Players[GetArrayLength(Players) - 1].Active := True;
Players[GetArrayLength(Players) - 1].Loc := 'New Location';
end;
Here you should set all of your Players Vars to something similar to this. For example if you have Players[0].Integer[0] and it is loads, i would reset that to 0 so you can just add in
procedure AddUser;
begin
SetArrayLength(Players, GetArrayLength(Players) + 1);
Players[GetArrayLength(Players) - 1].Name := 'New Name';
Players[GetArrayLength(Players) - 1].Pass := 'New Pass';
Players[GetArrayLength(Players) - 1].Nick := 'New Nick';
Players[GetArrayLength(Players) - 1].Active := True;
Players[GetArrayLength(Players) - 1].Loc := 'New Location';
Players[GetArrayLength(Players) - 1].Integer[0] := 0;
end;
And just do that for all the Players variables you have in your script.
The next Procedure is
procedure Inititate(Sender: TObject);
begin
lblUser.Caption := IntToStr(cUser);
Players[cUser].Nick := edNick.Text;
Players[cUser].Name := edUser.Text;
Players[cUser].Pass := edPass.Text;
Players[cUser].Loc := edLocation.Text;
Players[cUser].Integer[0] := (strtoint(edloads.Text));
if (cbActive.Text = 'True') then
Players[cUser].Active := True
else
Players[cUser].Active := False;
cUser := GetArrayLength(Players) - 1;
end;
This is where you would have saved time by naming your edit boxes accordingly. If not then you have to find out which of your editboxes are named what and input them in the place of edNick.Text or edUser.Text
if you have more such as an integer you would just add that as a variable like thisprocedure Inititate(Sender: TObject);
begin
lblUser.Caption := IntToStr(cUser);
Players[cUser].Nick := edNick.Text;
Players[cUser].Name := edUser.Text;
Players[cUser].Pass := edPass.Text;
Players[cUser].Loc := edLocation.Text;
Players[cUser].Integer[0] := Strtoint(edLoads.Text);
if (cbActive.Text = 'True') then
Players[cUser].Active := True
else
Players[cUser].Active := False;
cUser := GetArrayLength(Players) - 1;
end;
I will be using Integer1 throughout this Tutorial and the edit box will be named edLoads. So if you have a string or a boolean then you can add it like that. The cbActive is a combobox. If you go back to the picture of my form you will see a combobox there. I find this the easiest way to use booleans but any other way would work.
Again all you have to do in this picture is put your players variables in and change the names of your form objects to what they are.
procedure CreateUser(Sender: TObject);
begin
Players[cUser].Nick := edNick.Text;
Players[cUser].Name := edUser.Text;
Players[cUser].Pass := edPass.Text;
Players[cUser].Loc := edLocation.Text;
Players[cUser].Integer[0] := Strtoint(edLoads.Text);
if (cbActive.Text = 'True') then
Players[cUser].Active := True
else
Players[cUser].Active := False;
AddUser;
cUser := GetArrayLength(Players) - 1;
lblUser.Caption := IntToStr(cUser);
edLocation.Text := Players[cUser].Loc;
edNick.Text := Players[cUser].Nick;
edUser.Text := Players[cUser].Name;
edPass.Text := Players[cUser].Pass;
Strtoint(edLoads.text) := Players[cUser].Integer[0];
if (Players[cUser].Active) then
cbActive.Text := 'True'
else
cbActive.Text := 'False';
end;
Same thing as you have been doing.
procedure ForwardUser(Sender: TObject);
begin
Players[cUser].Nick := edNick.Text;
Players[cUser].Name := edUser.Text;
Players[cUser].Pass := edPass.Text;
Players[cUser].Loc := edLocation.Text;
Players[cUser].Integer[0] := Strtoint(edLoads.Text);
if (cbActive.Text = 'True') then
Players[cUser].Active := True
else
Players[cUser].Active := False;
if (cUser + 1 > GetArrayLength(Players) - 1) then
cUser := 0
else
cUser := cUser + 1;
lblUser.Caption := IntToStr(cUser);
edLocation.Text := Players[cUser].Loc;
edNick.Text := Players[cUser].Nick;
edUser.Text := Players[cUser].Name;
edPass.Text := Players[cUser].Pass;
Strtoint(edLoads.text) := Players[cUser].Integer[0];
if (Players[cUser].Active) then
cbActive.Text := 'True'
else
cbActive.Text := 'False';
end;
Same thing once again.
procedure BackUser(Sender: TObject);
begin
Players[cUser].Nick := edNick.Text;
Players[cUser].Name := edUser.Text;
Players[cUser].Pass := edPass.Text;
Players[cUser].Loc := edLocation.Text;
Players[cUser].Integer[0] := Strtoint(edLoads.Text);
if (cbActive.Text = 'True') then
Players[cUser].Active := True
else
Players[cUser].Active := False;
if (cUser - 1 < 0) then
cUser := GetArrayLength(Players) - 1
else
cUser := cUser - 1;
lblUser.Caption := IntToStr(cUser);
edLocation.Text := Players[cUser].Loc;
edNick.Text := Players[cUser].Nick;
edUser.Text := Players[cUser].Name;
edPass.Text := Players[cUser].Pass;
Strtoint(edLoads.text) := Players[cUser].Integer[0];
if (Players[cUser].Active) then
cbActive.Text := 'True'
else
cbActive.Text := 'False';
end;
Almost there!
procedure DeleteUser(Sender: TObject);
var
lo, na, ni: string;
ac: Boolean;
in: integer;
begin
lo := Players[GetArrayLength(Players) - 1].Loc;
na := Players[GetArrayLength(Players) - 1].Name;
ni := Players[GetArrayLength(Players) - 1].Nick;
ac := Players[GetArrayLength(Players) - 1].Active;
in :=Players[GetArrayLength(Players) - 1].Integer[0];
Players[cUser].Loc := lo;
Players[cUser].Name := na;
Players[cUser].Nick := ni;
Players[cUser].Active := ac;
Players[cUser].Integer[0] := in;
SetArrayLength(Players, GetArrayLength(Players) - 1);
if (cUser + 1 > GetArrayLength(Players) - 1) then
cUser := 0
else
cUser := cUser + 1;
lblUser.Caption := IntToStr(cUser);
edLocation.Text := Players[cUser].Loc;
edNick.Text := Players[cUser].Nick;
edUser.Text := Players[cUser].Name;
edPass.Text := Players[cUser].Pass;
strtoint(edloads.text) := Players[cUser].Integer[0];
if (Players[cUser].Active) then
cbActive.Text := 'True'
else
cbActive.Text := 'False';
end;
Last one!!!
procedure Start(Sender: TObject);
begin
lblUser.Caption := IntToStr(cUser);
edLocation.Text := Players[cUser].Loc;
edNick.Text := Players[cUser].Nick;
edUser.Text := Players[cUser].Name;
edPass.Text := Players[cUser].Pass;
strtoint(edLoads.text) := Players[cUser].integer[0];
if (Players[cUser].Active) then
cbActive.Text := 'True'
else
cbActive.Text := 'False';
end;
Ok when you are finally done adapting all of those procedures to fit your script you can move on.
5. Your buttons. Remember the buttons (<=,Add User,Delete User,=>) well now is when you have to use these. Scroll down to your initform procedure and find your left arrow button (<-,<=).
When you get to it everything should be there except for btnBack := TButton.Create(gbControl);
btnBack.Parent := gbControl;
btnBack.Left := 12;
btnBack.Top := 22;
btnBack.Width := 45;
btnBack.Height := 25;
btnBack.Caption := '<-';
btnBack.TabOrder := 0;
btnBack.OnClick := @BackUser;//this
add that with the name of your button insted of btnback.
then with your (->) arrow
btnNext := TButton.Create(gbControl);
btnNext.Parent := gbControl;
btnNext.Left := 216;
btnNext.Top := 23;
btnNext.Width := 45;
btnNext.Height := 25;
btnNext.Caption := '->';
btnNext.TabOrder := 1;
btnNext.OnClick := @ForwardUser;// add this
again change the btnNext to whatever you named your button.
Now with Create User
btnCreate := TButton.Create(gbControl);
btnCreate.Parent := gbControl;
btnCreate.Left := 138;
btnCreate.Top := 22;
btnCreate.Width := 75;
btnCreate.Height := 25;
btnCreate.Caption := 'Create';
btnCreate.TabOrder := 2;
btnCreate.OnClick := @CreateUser;//add
and again with delete user
btnDelete := TButton.Create(gbControl);
btnDelete.Parent := gbControl;
btnDelete.Left := 59;
btnDelete.Top := 22;
btnDelete.Width := 75;
btnDelete.Height := 25;
btnDelete.Caption := 'Delete';
btnDelete.OnClick := @DeleteUser;//add
btnDelete.TabOrder := 3;
Now one last thing go to your frmdesign vars at the beginning of your initform procedure and add this.
frmDesign := CreateForm;
frmDesign.Left := 254;
frmDesign.Top := 107;
frmDesign.Width := 308;
frmDesign.Height := 316;
frmDesign.Caption := 'User Manager';
frmDesign.Color := clBtnFace;
frmDesign.Font.Color := clWindowText;
frmDesign.Font.Height := -11;
frmDesign.Font.Name := 'MS Sans Serif';
frmDesign.Font.Style := [];
frmDesign.Visible := False;
frmDesign.PixelsPerInch := 96;
frmDesign.OnShow := @Start;//add this
Now you are done with the button assignments.
6.Almost the last thing to do is add cUser as a Integer at the beginning and add this to your main loopLoadUs;
cUser := 0;
if (GetArrayLength(Players) = 0) then
AddUser;
Safeinitform;
SafeShowFormModal;
Saveus;
Now you should be done.
1.First off go into Srl/SRL/misc/UsersManager.scar
2.Copy all of those procedures in there except "LoadForm" "TheForm" "ShowFormModal" and "TehForm" you don't have to copy the vars, only the procedure that i did not mention.
3.Setting up your form. First off you have to have created your form with every necissary object. For example
ignore everything that has an x over it they are all just to make it more user friendly. but everything else is necissary for the user manager to work for what i am doing.
http://img526.imageshack.us/img526/7097/tutorialpic1yz2.th.png (http://img526.imageshack.us/my.php?image=tutorialpic1yz2.png)
In this script i had
Players[0].Name
Players[0].Pass
Players[0].Nick
Players[0].Integer[0]
Players[0].Active
I believe you can tell which of these represents each object in my form if not i will go into greater detail.
So i made my form for those specific Player variables.
Next you need to add those four buttons that are not Xed out.
Make one a left arrow(<-,<=,ect.) one say Add Player one say Delete Player and one with a right arrow(=>,->). The last thing you can do is add a groupbox to make it look neater (it is the Box that says Player Control around my buttons. Although this is not necissary to make this function, it looks neater. Another thing you should do is name your Edit1,Edit2 objects something easy like Eduser,Edpass,Ednick,Edloads,ect. Naming Eduser,Edpass,and Ednick makes your life easier since in RSN's procedures thats what the variables are already set as. Also add a label in the corner and name it lblUser.
4. Adapting the procedures. Ok this part takes the longest. Paste RSN's procedures into your script. As you look at his procedures, you probably can guess what you have to do. I will go through step by step anyway.
Look at this Procedure.
procedure AddUser;
begin
SetArrayLength(Players, GetArrayLength(Players) + 1);
Players[GetArrayLength(Players) - 1].Name := 'New Name';
Players[GetArrayLength(Players) - 1].Pass := 'New Pass';
Players[GetArrayLength(Players) - 1].Nick := 'New Nick';
Players[GetArrayLength(Players) - 1].Active := True;
Players[GetArrayLength(Players) - 1].Loc := 'New Location';
end;
Here you should set all of your Players Vars to something similar to this. For example if you have Players[0].Integer[0] and it is loads, i would reset that to 0 so you can just add in
procedure AddUser;
begin
SetArrayLength(Players, GetArrayLength(Players) + 1);
Players[GetArrayLength(Players) - 1].Name := 'New Name';
Players[GetArrayLength(Players) - 1].Pass := 'New Pass';
Players[GetArrayLength(Players) - 1].Nick := 'New Nick';
Players[GetArrayLength(Players) - 1].Active := True;
Players[GetArrayLength(Players) - 1].Loc := 'New Location';
Players[GetArrayLength(Players) - 1].Integer[0] := 0;
end;
And just do that for all the Players variables you have in your script.
The next Procedure is
procedure Inititate(Sender: TObject);
begin
lblUser.Caption := IntToStr(cUser);
Players[cUser].Nick := edNick.Text;
Players[cUser].Name := edUser.Text;
Players[cUser].Pass := edPass.Text;
Players[cUser].Loc := edLocation.Text;
Players[cUser].Integer[0] := (strtoint(edloads.Text));
if (cbActive.Text = 'True') then
Players[cUser].Active := True
else
Players[cUser].Active := False;
cUser := GetArrayLength(Players) - 1;
end;
This is where you would have saved time by naming your edit boxes accordingly. If not then you have to find out which of your editboxes are named what and input them in the place of edNick.Text or edUser.Text
if you have more such as an integer you would just add that as a variable like thisprocedure Inititate(Sender: TObject);
begin
lblUser.Caption := IntToStr(cUser);
Players[cUser].Nick := edNick.Text;
Players[cUser].Name := edUser.Text;
Players[cUser].Pass := edPass.Text;
Players[cUser].Loc := edLocation.Text;
Players[cUser].Integer[0] := Strtoint(edLoads.Text);
if (cbActive.Text = 'True') then
Players[cUser].Active := True
else
Players[cUser].Active := False;
cUser := GetArrayLength(Players) - 1;
end;
I will be using Integer1 throughout this Tutorial and the edit box will be named edLoads. So if you have a string or a boolean then you can add it like that. The cbActive is a combobox. If you go back to the picture of my form you will see a combobox there. I find this the easiest way to use booleans but any other way would work.
Again all you have to do in this picture is put your players variables in and change the names of your form objects to what they are.
procedure CreateUser(Sender: TObject);
begin
Players[cUser].Nick := edNick.Text;
Players[cUser].Name := edUser.Text;
Players[cUser].Pass := edPass.Text;
Players[cUser].Loc := edLocation.Text;
Players[cUser].Integer[0] := Strtoint(edLoads.Text);
if (cbActive.Text = 'True') then
Players[cUser].Active := True
else
Players[cUser].Active := False;
AddUser;
cUser := GetArrayLength(Players) - 1;
lblUser.Caption := IntToStr(cUser);
edLocation.Text := Players[cUser].Loc;
edNick.Text := Players[cUser].Nick;
edUser.Text := Players[cUser].Name;
edPass.Text := Players[cUser].Pass;
Strtoint(edLoads.text) := Players[cUser].Integer[0];
if (Players[cUser].Active) then
cbActive.Text := 'True'
else
cbActive.Text := 'False';
end;
Same thing as you have been doing.
procedure ForwardUser(Sender: TObject);
begin
Players[cUser].Nick := edNick.Text;
Players[cUser].Name := edUser.Text;
Players[cUser].Pass := edPass.Text;
Players[cUser].Loc := edLocation.Text;
Players[cUser].Integer[0] := Strtoint(edLoads.Text);
if (cbActive.Text = 'True') then
Players[cUser].Active := True
else
Players[cUser].Active := False;
if (cUser + 1 > GetArrayLength(Players) - 1) then
cUser := 0
else
cUser := cUser + 1;
lblUser.Caption := IntToStr(cUser);
edLocation.Text := Players[cUser].Loc;
edNick.Text := Players[cUser].Nick;
edUser.Text := Players[cUser].Name;
edPass.Text := Players[cUser].Pass;
Strtoint(edLoads.text) := Players[cUser].Integer[0];
if (Players[cUser].Active) then
cbActive.Text := 'True'
else
cbActive.Text := 'False';
end;
Same thing once again.
procedure BackUser(Sender: TObject);
begin
Players[cUser].Nick := edNick.Text;
Players[cUser].Name := edUser.Text;
Players[cUser].Pass := edPass.Text;
Players[cUser].Loc := edLocation.Text;
Players[cUser].Integer[0] := Strtoint(edLoads.Text);
if (cbActive.Text = 'True') then
Players[cUser].Active := True
else
Players[cUser].Active := False;
if (cUser - 1 < 0) then
cUser := GetArrayLength(Players) - 1
else
cUser := cUser - 1;
lblUser.Caption := IntToStr(cUser);
edLocation.Text := Players[cUser].Loc;
edNick.Text := Players[cUser].Nick;
edUser.Text := Players[cUser].Name;
edPass.Text := Players[cUser].Pass;
Strtoint(edLoads.text) := Players[cUser].Integer[0];
if (Players[cUser].Active) then
cbActive.Text := 'True'
else
cbActive.Text := 'False';
end;
Almost there!
procedure DeleteUser(Sender: TObject);
var
lo, na, ni: string;
ac: Boolean;
in: integer;
begin
lo := Players[GetArrayLength(Players) - 1].Loc;
na := Players[GetArrayLength(Players) - 1].Name;
ni := Players[GetArrayLength(Players) - 1].Nick;
ac := Players[GetArrayLength(Players) - 1].Active;
in :=Players[GetArrayLength(Players) - 1].Integer[0];
Players[cUser].Loc := lo;
Players[cUser].Name := na;
Players[cUser].Nick := ni;
Players[cUser].Active := ac;
Players[cUser].Integer[0] := in;
SetArrayLength(Players, GetArrayLength(Players) - 1);
if (cUser + 1 > GetArrayLength(Players) - 1) then
cUser := 0
else
cUser := cUser + 1;
lblUser.Caption := IntToStr(cUser);
edLocation.Text := Players[cUser].Loc;
edNick.Text := Players[cUser].Nick;
edUser.Text := Players[cUser].Name;
edPass.Text := Players[cUser].Pass;
strtoint(edloads.text) := Players[cUser].Integer[0];
if (Players[cUser].Active) then
cbActive.Text := 'True'
else
cbActive.Text := 'False';
end;
Last one!!!
procedure Start(Sender: TObject);
begin
lblUser.Caption := IntToStr(cUser);
edLocation.Text := Players[cUser].Loc;
edNick.Text := Players[cUser].Nick;
edUser.Text := Players[cUser].Name;
edPass.Text := Players[cUser].Pass;
strtoint(edLoads.text) := Players[cUser].integer[0];
if (Players[cUser].Active) then
cbActive.Text := 'True'
else
cbActive.Text := 'False';
end;
Ok when you are finally done adapting all of those procedures to fit your script you can move on.
5. Your buttons. Remember the buttons (<=,Add User,Delete User,=>) well now is when you have to use these. Scroll down to your initform procedure and find your left arrow button (<-,<=).
When you get to it everything should be there except for btnBack := TButton.Create(gbControl);
btnBack.Parent := gbControl;
btnBack.Left := 12;
btnBack.Top := 22;
btnBack.Width := 45;
btnBack.Height := 25;
btnBack.Caption := '<-';
btnBack.TabOrder := 0;
btnBack.OnClick := @BackUser;//this
add that with the name of your button insted of btnback.
then with your (->) arrow
btnNext := TButton.Create(gbControl);
btnNext.Parent := gbControl;
btnNext.Left := 216;
btnNext.Top := 23;
btnNext.Width := 45;
btnNext.Height := 25;
btnNext.Caption := '->';
btnNext.TabOrder := 1;
btnNext.OnClick := @ForwardUser;// add this
again change the btnNext to whatever you named your button.
Now with Create User
btnCreate := TButton.Create(gbControl);
btnCreate.Parent := gbControl;
btnCreate.Left := 138;
btnCreate.Top := 22;
btnCreate.Width := 75;
btnCreate.Height := 25;
btnCreate.Caption := 'Create';
btnCreate.TabOrder := 2;
btnCreate.OnClick := @CreateUser;//add
and again with delete user
btnDelete := TButton.Create(gbControl);
btnDelete.Parent := gbControl;
btnDelete.Left := 59;
btnDelete.Top := 22;
btnDelete.Width := 75;
btnDelete.Height := 25;
btnDelete.Caption := 'Delete';
btnDelete.OnClick := @DeleteUser;//add
btnDelete.TabOrder := 3;
Now one last thing go to your frmdesign vars at the beginning of your initform procedure and add this.
frmDesign := CreateForm;
frmDesign.Left := 254;
frmDesign.Top := 107;
frmDesign.Width := 308;
frmDesign.Height := 316;
frmDesign.Caption := 'User Manager';
frmDesign.Color := clBtnFace;
frmDesign.Font.Color := clWindowText;
frmDesign.Font.Height := -11;
frmDesign.Font.Name := 'MS Sans Serif';
frmDesign.Font.Style := [];
frmDesign.Visible := False;
frmDesign.PixelsPerInch := 96;
frmDesign.OnShow := @Start;//add this
Now you are done with the button assignments.
6.Almost the last thing to do is add cUser as a Integer at the beginning and add this to your main loopLoadUs;
cUser := 0;
if (GetArrayLength(Players) = 0) then
AddUser;
Safeinitform;
SafeShowFormModal;
Saveus;
Now you should be done.