Results 1 to 7 of 7

Thread: dynamic button trouble

  1. #1

    dynamic button trouble

    I have a few problems with the buttons in my game.

    Currently I have a class button that looks a bit like the following

    Code:
    TButton = class
      private
        (..)
        FOnClick  : TNotifyEvent;
        procedure doClick; dynamic;
      public
        (..)
        property OnClick  : TNotifyEvent read FOnClick write FOnClick;
      end;
    I also have a list that hold these buttons.

    At initialization I create an x number of buttons
    Code:
    buttonlist.addButton(x, y, width, height, title);
    What I need now, is to attach predesigned procedures or functions to these dynamically created buttons.

    My first quess was to create a new class that holds all these procedures and then do something like
    Code:
    ButtonList[1].OnClick := btnEvents.changeMouse;
    but somehow thats not really working.

    I was kinda hoping someone has any thoughts on how to solve this.

    Thanks a bunch!

  2. #2

    dynamic button trouble

    Can you clarify what you mean by it does not work? Does it not work at compile-time or run-time?
    <br /><br />There are a lot of people who are dead while they are still alive. I want to be alive until the day I die.<br />-= Paulo Coelho =-

  3. #3

    dynamic button trouble

    You've got a very 'OOP' way of making your buttons work there..

    I'd go a more traditionalist route and use Function Pointers..

    Just define:
    Code:
    Type
           ClickProc = procedure&#40;x,y&#58; integer&#41;;
    Or something like that..
    Then inside your class:

    Code:
       OnClick&#58; ClickProc
    Then you just write a procedure that conforms to the procedure(x,y) format and set it equal to ClickProc... (IIRC of course!)
    My site: DelphiTuts.com (coming soon)...

    Download Font Studio 4.21 here.

  4. #4

    dynamic button trouble

    Quote Originally Posted by Nitrogen
    You've got a very 'OOP' way of making your buttons work there..
    I'd go a more traditionalist route and use Function Pointers..
    Events are essentially just fancy function pointers the only difference being that you qualify them as being "of object" when you declare them.
    <br /><br />There are a lot of people who are dead while they are still alive. I want to be alive until the day I die.<br />-= Paulo Coelho =-

  5. #5

    dynamic button trouble

    Quote Originally Posted by savage
    Can you clarify what you mean by it does not work? Does it not work at compile-time or run-time?
    Well, everything does compile. However the moment I click a button, any button, the game simply ends. I went through the code, but there's nothing that should end the game just like that. Weird thing is I'm not getting any errors too.

    From your reply I take it I am on the right path though, so at least I'm not doing anything odd, in a oo way that is.

    Nitrogen, thanks for the suggestion. Going to give that a try as well.

  6. #6

    dynamic button trouble

    I think you got the wrong thread

  7. #7

    dynamic button trouble

    Ooops deleted.
    <br /><br />There are a lot of people who are dead while they are still alive. I want to be alive until the day I die.<br />-= Paulo Coelho =-

Bookmarks

Posting Permissions

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