Results 1 to 6 of 6

Thread: TButton Type.

  1. #1
    Join Date
    May 2008
    Posts
    1,345
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default TButton Type.

    I'm looking to add two properties to the TButton type, but whenever I try to add them, it gives me a duplicate identifier (obviously) error, because it's declared twice.

    I need to add these properties to the TButton type, if possible:

    SCAR Code:
    Mine : Boolean;
    Number : Integer;

    Any possible way? :/.

    ~Sandstorm

  2. #2
    Join Date
    Nov 2007
    Location
    Chile
    Posts
    1,901
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    You will to make another type, because you cannot add properties to a type:
    scar Code:
    TButtonEdit = Record
        Button : TButton;
        Mine : Boolean;
        Number : Integer;
      End;


  3. #3
    Join Date
    May 2008
    Posts
    1,345
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Alright, two more questions:

    1. How would I use the Button property? ThisIsATButtonEdit.Button?

    Like that?

    2. I have an array of array of TButtons right now. How to I set the array length of, say, TBArray[0]?

    I want the array to go up to a user specified number, but it always returns a runtime error.

    ~Sandstorm

  4. #4
    Join Date
    Nov 2007
    Location
    Chile
    Posts
    1,901
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    1. Yes you would, like TButtonEdit.Button

    2. Change:
    Button : TButton;
    to
    Button : Array Of TButton (or Array[x..y])


  5. #5
    Join Date
    May 2008
    Posts
    1,345
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Ok, thanks for the help! One last question.

    I'm looking to dynamically add or remove buttons from a form, based on user specified numbers.

    This is what I have so far, for adding the buttons in:

    SCAR Code:
    Try
      Begin
        For I := 1 To StrToInt(Edit1.text) Do
        Begin
          SetArrayLength(Buttons[I].Mine[I], StrToInt(Edit2.text));
          SetArrayLength(Buttons[I].Button[I], StrToInt(Edit2.text));
          SetArrayLength(Buttons[I].Number[I], StrToInt(Edit2.text));
        End;
        For C := 0 To StrToInt(Edit1.text) Do
          For I := 0 To StrToInt(Edit2.text) Do
          Begin
            With Buttons[I].Button[I] Do
            Begin
              Parent := Wagh;
              Left := 8;
              Top := 6;
              Width := 19;
              Height := 19;
              TabOrder := 8;
            End;
          End;
      End;
      Except
      Begin
        Edit1.Text := 'Please enter a number!';
        Edit2.Text := 'Please enter a number!';
      End;
      Finally
      End;

    The only problem is that it throws a runtime error which I have yet to figure out.

    If you spot anything wrong with that, let me know!

    This is how I declared TButtonEdit as a type:

    SCAR Code:
    Type TButtonEdit = Record
        Button : Array of TButton;
        Mine : Array of Boolean;
        Number : Array of Integer;
    End;

    Here's how I declared Buttons:

    SCAR Code:
    Buttons : Array of TButtonEdit;

    ~Sandstorm

  6. #6
    Join Date
    Nov 2007
    Location
    Chile
    Posts
    1,901
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    scar Code:
    For I := 1 To StrToInt(Edit1.text) Do
        Begin
          SetArrayLength(Buttons[i].Mine[i], StrToInt(Edit2.text));
          SetArrayLength(Buttons[i].Button[i], StrToInt(Edit2.text));
          SetArrayLength(Buttons[i].Number[i], StrToInt(Edit2.text));
        End;
    to:

    scar Code:
    SetArrayLength(Buttons, StrToInt(Edit2.text));
    And then you start setting the length of buttons.


Thread Information

Users Browsing this Thread

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

Posting Permissions

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