Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Button array

Status
Not open for further replies.

22255565

Programmer
Joined
Jun 13, 2003
Messages
4
Location
PT
Good Morning,
I'm starting using borland delphi 6.0 in my university, I had used Visual Basic, but delphi is similar.But I have a problem, in VB6 , if I copy and paste a button it creates a button array. for example button1(1) will be the name of the pasted object. But in delphi I cannot make the same, but I need to do that. If anyone Knows how to do that I will aprecciate the help.

Thanks

Esmaluco
 
Why do you want a button array? What is your goal?

You can handle collections of components in two ways: iterate theough all the components on the form and test for TButtons; or make an explicit array in code (e.g. a TList of the buttons you want).

If these techniques interest you, reply and I will be more explicit.

Cheers
 
You cant as in VB make an array of button at design time, but u can at run time.

2 choices:

1- Place all your buttons on your form, (they wont be an array but each a single objet). In your code .. make an array of TButton
//var
// MyArray : array[0..4] of TButton;
then on the form create event write asign your form button to the array.
// MyArray[0]:=Button1;
// .....
// MyArray[4]:=Button5;
thats it

2- Dont put your button on your form
in your code make an array of Tbutton
//var
// MyArray : array[0..4] of TButton;
in form create event create the buttons
//for cpt=0 to 4 do
//{ Myarray[cpt]:=TButton.create(self)
/*self for current FORM because its a form event*/
//Myarray[cpt].parent:=self;
//Myarray[cpt].onclick:=MyOnClickCode;
/*here set other attribute (i.e top, left, caption..)*/
}
U just have to create the MyOnClickCode; function with the same parameter that onclick usualy use and thats it..

i know there is other way to do it.. but those r easy, efficient and fast to code..

jb

 
Thanks. Really Thanks I will use the 1 choice jb it simple and efficient.

:) - Thanks Again
 
A third approach: Put all the buttons on in the designer, in FormCreate put a routine that puts them into an array.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top