SRL Archive - Discussions and Debates

Form Helps.


NiCbaZ

2008-09-01 06:35:35

i have hardly ever made a form before so i kinda need some help …

This is what i have done… i have make a calculator skin like with buttons from 1 to 10 and i need to figure out how i get what the user clicks….


if [email]onclick@Button10.Capt[/email]ion then FirstNum:= 1;
if [email]onclick@Button15.Capt[/email]ion then FirstNum:= 2;
if [email]onclick@Button14.Capt[/email]ion then FirstNum:= 3;
if [email]onclick@Button6.Capt[/email]ion then FirstNum:= 4;
if [email]onclick@Button16.Capt[/email]ion then FirstNum:= 5;
if [email]onclick@Button13.Capt[/email]ion then FirstNum:= 6;
if [email]onclick@Button7.Capt[/email]ion then FirstNum:= 7;
if [email]onclick@Button8.Capt[/email]ion then FirstNum:= 8;
if [email]onclick@Button9.Capt[/email]ion then FirstNum:= 9;
if [email]onclick@Button11.Capt[/email]ion then FirstNum:= 0;

its not Onlick like im trying to use but you see what im trying to do?? could some one help me or give the function name?

Daniel.Blaze

2008-09-01 06:42:22

If they are all buttons:

In your procedure InitForm, for all the buttons, implement:


Button[Number].OnClick := @ButtonClicked;

Then above that procedure, create a new one:


procedure ButtonClicked(Sender: TObject);
begin
case Sender of
Button1: Writeln('Button 1 Clicked');
Button2: Writeln('Button 2 Clicked');
end;
end;

Naum

2008-09-01 06:54:07

meh, Just a hunch but this is for scripting comp ;).

Something like this.

Button1.Onlick := @Assign

Then in assign make a variable called value


Var
Value : Integer;
Procedure Assign(sender : tobject);
Begin
Case Sender Of
Button1 : Value := 1;
Button2 : Value := 2;
e.t.c..

Hope I Helped :)

NiCbaZ

2008-09-01 06:58:36

oh cool i get it but could i do this


Button1.Onlick := @FirNum:= 1;



or do i have to create a seperate one like that?

Daniel.Blaze

2008-09-01 07:04:19

The @ symbol is like a pointer to a procedure, so you can't do it like that.

You wouldn't usually do:


procedure test := 1;
begin
...
end;

You could however create a var parameter and return the result in that

Gu3st...

2008-09-01 07:24:01

put this in initform:
Button12.Clicked := @ButtonClicked;

put this BEFORE initform:
procedure ButtonClicked(sender : TObject);
begin
case Sender of
Button12: DoSomething(cool);
end;
end;

Widget

2008-09-02 08:41:09

Something like this?

var
Buttons: array[0..9] of TButton;

..

for i := 0 to 9 do
begin
Buttons[i] := TButton.Create(Form);
Buttons.Parent := Form;
Buttons.SetBounds(50 + 45 mod i, 50 + 45 div i, 40, 40);
Buttons.Caption := IntToStr(i);
Buttons.OnClick := @ButtonClick;
end;

..

procedure ButtonClick(Sender: TObject);
var
i: integer;
begin
for i := 0 to 9 do
if (Sender = Buttons[i]) then
FirstNum := i;
end;

Daniel

2008-09-04 02:27:17

From: Widget
Something like this?

var
Buttons: array[0..9] of TButton;

..

for i := 0 to 9 do
begin
Buttons[i] := TButton.Create(Form);
Buttons.Parent := Form;
Buttons.SetBounds(50 + 45 mod i, 50 + 45 div i, 40, 40);
Buttons.Caption := IntToStr(i);
Buttons.OnClick := @ButtonClick;
end;

..

procedure ButtonClick(Sender: TObject);
var
i: integer;
begin
for i := 0 to 9 do
if (Sender = Buttons[i]) then
FirstNum := i;
end;

Would't work. ButtonClick has to be above the form declarance procedure ;)

Widget

2008-09-04 15:07:27

Yeah yeah, I just always forward everything :p

Example: http://widget.pastebin.com/f3e385cf3

Daniel

2008-09-06 00:24:42

From: Widget
Yeah yeah, I just always forward everything :p

Example: http://widget.pastebin.com/f3e385cf3

My way (most peoples way) = faster?