Results 1 to 9 of 9

Thread: How to use tags in forms!

  1. #1
    Join Date
    Jan 2007
    Location
    Illinois.. >.<
    Posts
    1,158
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default How to use tags in forms!

    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.

    Code:
    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.
    Code:
    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...
    Code:
    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

  2. #2
    Join Date
    May 2007
    Location
    baltimore, md
    Posts
    836
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    Whoa thats pretty cool iv never thought of that ill have to try it out thanks.

  3. #3
    Join Date
    Nov 2006
    Location
    NSW, Australia
    Posts
    3,487
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    Interesting. Easier than all those procedures that I make...
    [CENTER][img]http://signatures.mylivesignature.com/54486/113/4539C8FAAF3EAB109A3CC1811EF0941B.png[/img][/CENTER]
    [CENTER][BANANA]TSN ~ Vacation! ~ says :I Love Santy[/BANANA][/CENTER]

    [CENTER][BANANA]Raymond - Oh rilie? says :Your smart[/BANANA][/CENTER]

  4. #4
    Join Date
    Jan 2007
    Location
    Illinois.. >.<
    Posts
    1,158
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    ^^ Yea I did the same thing before.. @buttonclick. @editplayers. @.. @..... And then i always had to remember what was which and blah blah. Not cool.

  5. #5
    Join Date
    Dec 2006
    Location
    Third rock from the sun.
    Posts
    2,510
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    Oooh...

    Thank you for this

  6. #6
    Join Date
    Jan 2007
    Location
    Illinois.. >.<
    Posts
    1,158
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    No problem. Anyone else like it?

  7. #7
    Join Date
    Feb 2006
    Location
    L.A, USA
    Posts
    1,632
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    You can just use:

    Code:
    procedure THEEClick(sender: TObject);
    begin
      case Sender of
        VarButtonName: DoSomething; 
        VarMemoName: Dosttuf; 
        EditName: dostuuf; 
      end; 
    end;
    ?

  8. #8
    Join Date
    Jan 2007
    Location
    Illinois.. >.<
    Posts
    1,158
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Yea that's essentially what i did also. I only knew how to do it using .tag.

  9. #9
    Join Date
    Jul 2007
    Location
    New Zealand FTW!
    Posts
    72
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    doh.. shouolda thoguth of that sooner

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. SCAR Tags?
    By Da 0wner in forum News and General
    Replies: 26
    Last Post: 02-11-2009, 11:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •