i want to be able to create dynamic buttons.

so ive used the code :

TButton* Btn = new TButton(this);

my first question is:
how do i assign a function to the dynamic button?!

my second question is how can i put the code into a loop as to be able to create multiple buttons frmo the one "add" button? the new method dosnt allow for a variable name to be used as the name for the object that i want to create!?
eg.

void abuttonfucntion()
{
static numvar;
char button Btn + numvar;
TButton*  button = new TButton(this);
...button position/style code...
}

thanks for any help! =)

OnIIcE

bump

EDIT:

void __fastcall Tfrm_Main::BitBtn1Click(TObject *Sender)
{
static int x;
static int y;
static int BtnCount;
static int first;
int PanelHeight = plc_Holder->Height;


TButton* Btn = new TButton(this);
Btn->Parent = frm_Main;
AnsiString BtnCountAsChar = (AnsiString)BtnCount;
AnsiString BtnName = "SndBtn" + BtnCountAsChar;
Btn->Name = BtnName;

Btn->Caption = "New Sound";


Btn->OnClick = SoundFileButton(this);



if(first == 0)
{
 Btn->Top = 10;
 Btn->Left = 5;
 first = 1;
 y = 5;
 x = 10;
}
else
{
Btn->Top = x;
Btn->Left = y;
}

x = x + 25;
BtnCount++;

}

this is the code ive got for making my buttons.
i want each button to have the same functionality, but be able to differntiate between each one!
how can i make my function tell what button is using it? i dont understand the TObject sender so dont know if that will help?
basicly i want to be able to create a new "button" that will be able to load in a file, but each button will enable the user to work with the file that was brought in by the button selected.
so i want to be able to get information from the button - but dont know how!

also how can i call a destrutor for the objects? since they are dynamic i cant get around having another button with delete Btn; as Btn isnt created at runtime so it dosnt complie...also since my code makes multiple buttons with Btn will it delete all of them, or will they have to be named (in my code i change the name so you can tell the difference)

please help sombody!

hi
this code for graphics programming or dos console

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.