Borland C++ Builder 6 : creating new objects - HOW ??
Expand Post »
Hi, I am trying to make small game , but I am confronting with a problem. I have a function that should add a new button to my form when it's called. The problem is that I don't know how to create a new object (a button, a shape or whatever...) and adding it to my form. In Java, this would be fairly simple, but how do I it here ? my header file contains the form class:
Re: Borland C++ Builder 6 : creating new objects - HOW ??
TButton's constructor needs to be passed a pointer to a TComponent (eg a parent form) that is responsible for managing the button.
It is also necessary to set various attributes: position, caption, visibility, the function to be called when the newly created button is created, etc etc. TButton is derived from TWinControl, so some inherited attributes probably also need to be set.
It would probably be easier to create a button on your form at design time, and have your function make that button visible as needed.
Re: Borland C++ Builder 6 : creating new objects - HOW ??
Ok , this sorted things out a little bit. My next problem is, how to assign each button a different function when it's pressed.For example I do something like this:
I get an "Not an allowed type" error when compiling. It seems that I can't pass a variable like this to myfunction. But, if I do like this: TestBtn->OnClick = myfunction; with myfunction looking now :
it works, but it doesn't do what I wanted it to do.But how do I know which of the ten buttons is clicked now? How can I pass this information to the function?
Re: Borland C++ Builder 6 : creating new objects - HOW ??
This works only if the buttons are clicked immediately after they're created.After that that , any button I click , it shows the same : "Button 9 clicked" (and that's logic, m_x has the latest value, and that's 9). How to do , to stick to each button it's attributes(here, it's id) ?
Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.
This thread is more than three months old
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.