SRL Archive - Help and Support

Form in a form


Infantry001

2006-08-16 19:51:44

How do i make a form load another form when a button is pressed? like starblaster's stressminer

Dankness

2006-08-16 20:42:24

This is how i do it…


{.include SRL\SRL.SCAR}
{.include SRL\SRL\Misc\PlayerForm.Scar}

var
frmMain,frmStats : TForm;
TCW, LLTD, LRLTD, LLO, LLY, LLW : TLabel;
ECW, ELLTD, ELRLTD, ELL0, ELLY, ELLW : TEdit;
TotalOaks,TotalLogs,TotalWillows,TotalYews,TotalRunss,
TotalBankss, TotalAxess : TLabel;
UAB, DI, UG, RP : TCheckBox;
Button1, Button2, Button3 : TButton;
TLogCount, TOakCount, TWillowCount, TYewCount : Integer;
TotalBanks, TotalAxes, TotalRuns : Integer;

//----------------------------------------------------------------------------//
//---> Global Stats Form
//----------------------------------------------------------------------------//

procedure InitStats;
begin
frmStats := CreateForm;
frmStats.Left := 288;
frmStats.Top := 161;
frmStats.Width := 250;
frmStats.Height := 148;
frmStats.Caption := 'Global Stats';
frmStats.Color := clInactiveCaption;
frmStats.Font.Height := -11;
frmStats.Font.Name := 'MS Sans Serif';
frmStats.Font.Style := [];
frmStats.Visible := False;
frmStats.PixelsPerInch := 96;

TotalLogs := TLabel.Create(frmStats);
TotalLogs.Parent := frmStats;
TotalLogs.Left := 20;
TotalLogs.Top := 13;
TotalLogs.Width := 76;
TotalLogs.Height := 15;
TotalLogs.Caption := 'Total Trees Cut : ' + IntToStr ( TLogCount );

TotalOaks := TLabel.Create(frmStats);
TotalOaks.Parent := frmStats;
TotalOaks.Left := 20;
TotalOaks.Top := 26;
TotalOaks.Width := 76;
TotalOaks.Height := 15;
TotalOaks.Caption := 'Total Oaks Cut : ' + IntToStr ( TOakCount );

TotalWillows := TLabel.Create(frmStats);
TotalWillows.Parent := frmStats;
TotalWillows.Left := 20;
TotalWillows.Top := 39;
TotalWillows.Width := 76;
TotalWillows.Height := 15;
TotalWillows.Caption := 'Total Willows Cut : ' + IntToStr ( TWillowCount );

TotalYews := TLabel.Create(frmStats);
TotalYews.Parent := frmStats;
TotalYews.Left := 20;
TotalYews.Top := 52;
TotalYews.Width := 76;
TotalYews.Height := 15;
TotalYews.Caption := 'Total Yews Cut : ' + IntToStr ( TYewCount );

TotalBankss := TLabel.Create(frmStats);
TotalBankss.Parent := frmStats;
TotalBankss.Left := 20;
TotalBankss.Top := 65;
TotalBankss.Width := 76;
TotalBankss.Height := 15;
TotalBankss.Caption := 'Total Banks : ' + IntToStr ( TotalBanks );

TotalRunss := TLabel.Create(frmStats);
TotalRunss.Parent := frmStats;
TotalRunss.Left := 20;
TotalRunss.Top := 78;
TotalRunss.Width := 76;
TotalRunss.Height := 15;
TotalRunss.Caption := 'Total Runs : ' + IntToStr ( TotalRuns );

TotalAxess := TLabel.Create(frmStats);
TotalAxess.Parent := frmStats;
TotalAxess.Left := 20;
TotalAxess.Top := 91;
TotalAxess.Width := 76;
TotalAxess.Height := 15;
TotalAxess.Caption := 'Total Axes : ' + IntToStr ( TotalAxes );

end;

procedure ShowStatsModal;
begin
frmStats.ShowModal;
end;

//----------------------------------------------------------------------------//
//--->
//----------------------------------------------------------------------------//

procedure SafeInitStats;
var
v: TVariantArray;
begin
SetArrayLength ( V, 0);
ThreadSafeCall('InitStats', v);
end;

//----------------------------------------------------------------------------//
//--->
//----------------------------------------------------------------------------//

procedure SafeShowStats( Sender: TObject );
var
v: TVariantArray;
begin
SafeInitStats;
SetArrayLength ( V, 0);
ThreadSafeCall ( 'ShowStatsModal', v);
end;

//----------------------------------------------------------------------------//
//---> BottonClick Actions
//----------------------------------------------------------------------------//

procedure ButtonClick2(sender: TObject);
begin
case Sender of
Button1 : begin
frmMain.ModalResult:= mrOk;
end;
Button2 : begin
SetUpPlayers;
end;
Button3 : begin
SafeShowStats ( Button2 );
end;

end;
end;

//----------------------------------------------------------------------------//
//---> Main Form Procedures
//----------------------------------------------------------------------------//

procedure MainInitForm;
begin

frmMain := CreateForm;
frmMain.Left := 0;
frmMain.Top := 0;
frmMain.Width := 457;
frmMain.Height := 400;
frmMain.Caption := 'Dankness Draynor Chop-All';
frmMain.Color := clInactiveCaption;
frmMain.Font.Height := -11;
frmMain.Font.Name := 'MS Sans Serif';
frmMain.Font.Style := [];
frmMain.ShowHint := True;
frmMain.Visible := False;
frmMain.PixelsPerInch := 96;


TCW := TLabel.Create(frmMain);
TCW.Parent := frmMain;
TCW.Left := 71;
TCW.Top := 26;
TCW.Width := 76;
TCW.Height := 13;
TCW.Hint := 'Set Higher for Lower LVL and Lower for Higher LVL';
TCW.Caption := 'Time Chop Wait';
TCW.Font.Height := -11;
TCW.Font.Name := 'MS Sans Serif';
TCW.Font.Style := [];
TCW.ParentFont := False;

ECW := TEdit.Create(frmMain);
ECW.Parent := frmMain;
ECW.Left := 161;
ECW.Top := 21;
ECW.Width := 121;
ECW.Height := 21;
ECW.AutoSelect := False;
ECW.ParentShowHint := False;
ECW.ShowHint := True;
ECW.TabOrder := 2;
ECW.Text := '90000';

LLTD := TLabel.Create(frmMain);
LLTD.Parent := frmMain;
LLTD.Left := 67;
LLTD.Top := 65;
LLTD.Width := 80;
LLTD.Height := 13;
LLTD.Caption := 'Loads Per Player';
ELLTD := TEdit.Create(frmMain);
ELLTD.Parent := frmMain;
ELLTD.Left := 159;
ELLTD.Top := 61;
ELLTD.Width := 121;
ELLTD.Height := 21;
ELLTD.TabOrder := 9;
ELLTD.Text := '3';

LRLTD := TLabel.Create(frmMain);
LRLTD.Parent := frmMain;
LRLTD.Left := 24;
LRLTD.Top := 104;
LRLTD.Width := 123;
LRLTD.Height := 13;
LRLTD.Caption := 'Random Loads Per Player';
ELRLTD := TEdit.Create(frmMain);
ELRLTD.Parent := frmMain;
ELRLTD.Left := 158;
ELRLTD.Top := 101;
ELRLTD.Width := 121;
ELRLTD.Height := 21;
ELRLTD.TabOrder := 10;
ELRLTD.Text := '2';

LLO := TLabel.Create(frmMain);
LLO.Parent := frmMain;
LLO.Left := 105;
LLO.Top := 143;
LLO.Width := 42;
LLO.Height := 13;
LLO.Caption := 'Oak LVL';
ELL0 := TEdit.Create(frmMain);
ELL0.Parent := frmMain;
ELL0.Left := 156;
ELL0.Top := 141;
ELL0.Width := 121;
ELL0.Height := 21;
ELL0.TabOrder := 11;
ELL0.Text := '20'

LLW := TLabel.Create(frmMain);
LLW.Parent := frmMain;
LLW.Left := 94;
LLW.Top := 182;
LLW.Width := 53;
LLW.Height := 13;
LLW.Caption := 'Willow LVL';
ELLW := TEdit.Create(frmMain);
ELLW.Parent := frmMain;
ELLW.Left := 157;
ELLW.Top := 181;
ELLW.Width := 121;
ELLW.Height := 21;
ELLW.TabOrder := 13;
ELLW.Text := '30';


LLY := TLabel.Create(frmMain);
LLY.Parent := frmMain;
LLY.Left := 104;
LLY.Top := 221;
LLY.Width := 43;
LLY.Height := 13;
LLY.Caption := 'Yew LVL';
ELLY := TEdit.Create(frmMain);
ELLY.Parent := frmMain;
ELLY.Left := 160;
ELLY.Top := 221;
ELLY.Width := 121;
ELLY.Height := 21;
ELLY.TabOrder := 12;
ELLY.Text := '60';


UAB := TCheckBox.Create(frmMain);
UAB.Parent := frmMain;
UAB.Left := 325;
UAB.Top := 25;
UAB.Width := 97;
UAB.Height := 17;
UAB.Hint := 'Use Antiban Features';
UAB.Caption := 'Use AntiBan';
UAB.TabOrder := 14;

DI := TCheckBox.Create(frmMain);
DI.Parent := frmMain;
DI.Left := 327;
DI.Top := 54;
DI.Width := 97;
DI.Height := 17;
DI.Hint := 'Writes Info to Debug Box otherwise States info in the Status Window';
DI.Caption := 'Debug Info';
DI.TabOrder := 15;

UG := TCheckBox.Create(frmMain);
UG.Parent := frmMain;
UG.Left := 326;
UG.Top := 83;
UG.Width := 97;
UG.Height := 17;
UG.Hint := 'Edit Players or Load from File, Please Note only Load from File if All are Active';
UG.Caption := 'Edit Players';
UG.TabOrder := 16;

RP := TCheckBox.Create(frmMain);
RP.Parent := frmMain;
RP.Left := 326;
RP.Top := 112;
RP.Width := 97;
RP.Height := 17;
RP.Hint := 'Choose Players at Random or in Order';
RP.Caption := 'Random Players';
RP.TabOrder := 17;

Button1 := TButton.Create(frmMain);
Button1.Parent := frmMain;
Button1.Left := 16;
Button1.Top := 328;
Button1.Width := 75;
Button1.Height := 25;
Button1.Caption := 'Start Script';
Button1.OnClick:= @buttonclick2;
Button1.TabOrder := 17;

Button2 := TButton.Create(frmMain);
Button2.Parent := frmMain;
Button2.Left := 122;
Button2.Top := 331;
Button2.Width := 75;
Button2.Height := 25;
Button2.Caption := 'Edit Players';
Button2.OnClick:= @buttonclick2;
Button2.TabOrder := 18;

Button3 := TButton.Create(frmMain);
Button3.Parent := frmMain;
Button3.Left := 218;
Button3.Top := 331;
Button3.Width := 75;
Button3.Height := 25;
Button3.Caption := 'Global Stats';
Button3.TabOrder := 19;
Button3.OnClick:= @buttonclick2;
Button3.Tag := -1;
end;


//----------------------------------------------------------------------------//
//--->
//----------------------------------------------------------------------------//

procedure SafeMainInitForm;
var
v: TVariantArray;
begin
SetArrayLength ( V, 0);
ThreadSafeCall ( 'MainInitForm', V);
end;

//----------------------------------------------------------------------------//
//--->
//----------------------------------------------------------------------------//

function ShowMainFormModal: Boolean;
begin
Result:= False;
if(frmMain.ShowModal = mrOk)then
Result:= True;
end;

//----------------------------------------------------------------------------//
//--->
//----------------------------------------------------------------------------//

function SafeShowMainFormModal: Boolean;
var
v: TVariantArray;
begin
SetArrayLength(V, 0);
Result := ThreadSafeCall('ShowMainFormModal', v);
end;

//----------------------------------------------------------------------------//
//--->
//----------------------------------------------------------------------------//
procedure SetUpForms;
begin
SafeMainInitForm;
SafeInitStats;
SafeShowMainFormModal;
FreeForm(frmStats);
FreeForm(frmMain);
end;

begin
SetUpSRL;
SetUpForms;
end.

Keen

2006-08-16 20:51:17

Just made a sender call on the display form procedures.
If you know how to do forms properly then it shouldn't be hard at all.

Infantry001

2006-08-16 22:51:20

well, i dont know how to do forms properly… i know just the basic stuff, like how to make things work, background, stuff like that. im not sure how the sender call stuff works