itSchRis917
07-19-2007, 03:13 AM
This is my first tut, so sorry if i didnt explain it clearly.
Ok, so I'm going to teach you how to use tags in forms. So, tags are used in forms for mainly one purpose: to save code. When using .tag it allows you to set multiple TObject's to seperate procedures all within the same ClickButton procedure.
So, here would be the simple, sender: TObject procedure using tags.
procedure clickbutton(sender: tobject);
var
v: TVariantArray;
begin
SetArrayLength(V, 0);
if (Sender is TButton) then
case (TButton(Sender).tag) of // used like any other case ____ of statement
-1: begin
PlayerClicked := true;
ThreadSafeCall('SetupForm', v);
end;
-2: frmDesign.ModalResult := mrOk;
-3: begin
frmDesign.ModalResult := mrOk;
Writeln('Script canceled.');
//FreeForm(frmDesign);
TerminateScript;
end;
-4: begin
ColorsClicked := true;
LoadColorsForm;
end;
-5: LoadHelpForm;
-6: LoadStatsForm;
end;
end;
So the majority of that code, is made up of Case(TButton(Sender).tag) of, which is just a basic Case..Of statement, which you should probably know how to use.
BUT...
How do you use the .tag variable?? Simple. You declare it like you would declare any other form variable.
PlayersButton.Tag := -1;
And so on... But I'm not going to go into greater detail than that..
Here's part of my form that i took it from. I'm not going to post the whole form though...
PlayersButton := TButton.Create(frmDesign);
PlayersButton.Parent := frmDesign;
PlayersButton.Left := 190;
PlayersButton.Top := 5;
PlayersButton.Width := 75;
PlayersButton.Height := 25;
PlayersButton.Caption := 'Edit Players';
PlayersButton.OnClick := @clickbutton;
PlayersButton.Tag := -1;
PlayersButton.TabOrder := 8;
StartButton := TButton.Create(frmDesign);
StartButton.Parent := frmDesign;
StartButton.Left := 190;
StartButton.Top := 92;
StartButton.Width := 75;
StartButton.Height := 25;
StartButton.Caption := 'Start Script';
StartButton.OnClick := @clickbutton;
StartButton.Tag := -2;
StartButton.TabOrder := 9;
CancelButton := TButton.Create(frmDesign);
CancelButton.Parent := frmDesign;
CancelButton.Left := 190;
CancelButton.Top := 120;
CancelButton.Width := 75;
CancelButton.Height := 25;
CancelButton.Caption := 'Cancel';
CancelButton.OnClick := @clickbutton;
CancelButton.Tag := -3;
CancelButton.TabOrder := 10;
ColorsButton := TButton.Create(frmDesign);
ColorsButton.Parent := frmDesign;
ColorsButton.Left := 190;
ColorsButton.Top := 33;
ColorsButton.Width := 75;
ColorsButton.Height := 25;
ColorsButton.Caption := 'Edit Colors';
ColorsButton.OnClick := @clickbutton;
ColorsButton.Tag := -4;
ColorsButton.TabOrder := 11;
HelpButton := TButton.Create(frmDesign);
HelpButton.Parent := frmDesign;
HelpButton.Left := 190;
HelpButton.Top := 63;
HelpButton.Width := 75;
HelpButton.Height := 25;
HelpButton.Caption := 'Help';
HelpButton.OnClick := @clickbutton;
HelpButton.Tag := -5;
HelpButton.TabOrder := 13;
StatsButton := TButton.Create(frmDesign);
StatsButton.Parent := frmDesign;
StatsButton.Left := 115;
StatsButton.Top := 120;
StatsButton.Width := 75;
StatsButton.Height := 25;
StatsButton.Caption := 'View Stats';
StatsButton.OnClick := @clickbutton;
StatsButton.Tag := -6;
StatsButton.TabOrder := 16;
So, thats about all there is to it. Hope you enjoyed it!
~ itschris917
Ok, so I'm going to teach you how to use tags in forms. So, tags are used in forms for mainly one purpose: to save code. When using .tag it allows you to set multiple TObject's to seperate procedures all within the same ClickButton procedure.
So, here would be the simple, sender: TObject procedure using tags.
procedure clickbutton(sender: tobject);
var
v: TVariantArray;
begin
SetArrayLength(V, 0);
if (Sender is TButton) then
case (TButton(Sender).tag) of // used like any other case ____ of statement
-1: begin
PlayerClicked := true;
ThreadSafeCall('SetupForm', v);
end;
-2: frmDesign.ModalResult := mrOk;
-3: begin
frmDesign.ModalResult := mrOk;
Writeln('Script canceled.');
//FreeForm(frmDesign);
TerminateScript;
end;
-4: begin
ColorsClicked := true;
LoadColorsForm;
end;
-5: LoadHelpForm;
-6: LoadStatsForm;
end;
end;
So the majority of that code, is made up of Case(TButton(Sender).tag) of, which is just a basic Case..Of statement, which you should probably know how to use.
BUT...
How do you use the .tag variable?? Simple. You declare it like you would declare any other form variable.
PlayersButton.Tag := -1;
And so on... But I'm not going to go into greater detail than that..
Here's part of my form that i took it from. I'm not going to post the whole form though...
PlayersButton := TButton.Create(frmDesign);
PlayersButton.Parent := frmDesign;
PlayersButton.Left := 190;
PlayersButton.Top := 5;
PlayersButton.Width := 75;
PlayersButton.Height := 25;
PlayersButton.Caption := 'Edit Players';
PlayersButton.OnClick := @clickbutton;
PlayersButton.Tag := -1;
PlayersButton.TabOrder := 8;
StartButton := TButton.Create(frmDesign);
StartButton.Parent := frmDesign;
StartButton.Left := 190;
StartButton.Top := 92;
StartButton.Width := 75;
StartButton.Height := 25;
StartButton.Caption := 'Start Script';
StartButton.OnClick := @clickbutton;
StartButton.Tag := -2;
StartButton.TabOrder := 9;
CancelButton := TButton.Create(frmDesign);
CancelButton.Parent := frmDesign;
CancelButton.Left := 190;
CancelButton.Top := 120;
CancelButton.Width := 75;
CancelButton.Height := 25;
CancelButton.Caption := 'Cancel';
CancelButton.OnClick := @clickbutton;
CancelButton.Tag := -3;
CancelButton.TabOrder := 10;
ColorsButton := TButton.Create(frmDesign);
ColorsButton.Parent := frmDesign;
ColorsButton.Left := 190;
ColorsButton.Top := 33;
ColorsButton.Width := 75;
ColorsButton.Height := 25;
ColorsButton.Caption := 'Edit Colors';
ColorsButton.OnClick := @clickbutton;
ColorsButton.Tag := -4;
ColorsButton.TabOrder := 11;
HelpButton := TButton.Create(frmDesign);
HelpButton.Parent := frmDesign;
HelpButton.Left := 190;
HelpButton.Top := 63;
HelpButton.Width := 75;
HelpButton.Height := 25;
HelpButton.Caption := 'Help';
HelpButton.OnClick := @clickbutton;
HelpButton.Tag := -5;
HelpButton.TabOrder := 13;
StatsButton := TButton.Create(frmDesign);
StatsButton.Parent := frmDesign;
StatsButton.Left := 115;
StatsButton.Top := 120;
StatsButton.Width := 75;
StatsButton.Height := 25;
StatsButton.Caption := 'View Stats';
StatsButton.OnClick := @clickbutton;
StatsButton.Tag := -6;
StatsButton.TabOrder := 16;
So, thats about all there is to it. Hope you enjoyed it!
~ itschris917