|
4 u0 g8 e9 R) b2 N. y* p
一./ H. O9 q9 G- @
AnsiString nameString("TButton");
0 g! H6 e( c, M8 @/ m$ [/ F# {TButton * button;7 S/ m2 E; |; y6 [/ V
for(int i=0; i < ComponentCount; i++)6 P7 g* @8 L, v5 s' R
{0 q; q& `* c' J
//Check to see if the component is a TButton: f& ]5 j+ p* c) v! V+ Z4 c
if (Components->ClassNameIs(nameString))
* R+ G( H% l. b8 c/ q3 z{0 [- [" w( x2 f3 i
//cast the component to a TButton *
: [! D+ q j* l. n+ `5 b% S/ ?, @button = (TButton *)Components;
3 G. J; G" X7 f, ?# \! ubutton->Font->Name = "Courier";- E {( D0 G2 `- m
......
* b) p% P. Y& s, Y7 x1 f. _6 G1 a8 j+ |$ c' y' N% W
二.
4 f& G; l+ K% X, o, i我想动态创建和静态创建都没有太大区别,只要它属于你的MainForm。( new TButton(this) ).
: q/ J& D3 H' _- U用一个需循环, R; ~/ g5 V5 F/ U2 G
TButton* button; q+ l1 l& Q5 {+ k( O& v
for(int i=0;i<MainForm->ComponentCount;i++){
+ I; ]/ Q$ X$ tif((button= dynamic_cast<TButton*>(MainForm->Components)) != NULL )- I" @: ]9 x9 g6 l
button->Caption="Button";
* H' J" G; x4 F/ Y! G}
2 \5 }& Q5 I8 H |