|
- o1 s4 j$ x# |# A" x; X
一.6 Q, s- B5 T. j, U
AnsiString nameString("TButton");
1 _& P( }. W% jTButton * button;, l S: n. U4 Z" X O
for(int i=0; i < ComponentCount; i++)) j( g! O4 Y* R0 A5 s* v5 _
{5 |% E7 W( B+ ^! D, z) \& X/ l
//Check to see if the component is a TButton5 h# a/ k6 L, K& J) d& x% V& t
if (Components->ClassNameIs(nameString))
7 H, o/ l. ]) c5 A) c{( ] M0 k" I" b: i9 K$ {
//cast the component to a TButton *8 M* z( o+ J F f* h) Z9 i$ g
button = (TButton *)Components;
' @% x- y( }! Z; H* S+ X O5 zbutton->Font->Name = "Courier";
4 `5 s& ]8 }0 R! V: P/ m" B. T9 l0 _/ ? ......
7 s9 C1 E7 |$ U, g) d! _+ L4 j4 G9 h# h* Z
二.
" c- x( l% I# ?& _% x- Y我想动态创建和静态创建都没有太大区别,只要它属于你的MainForm。( new TButton(this) ).
* Z: g. h! K2 k用一个需循环+ G( c1 y3 q9 n
TButton* button;1 Z* t2 W9 c7 C8 q ~% o$ w
for(int i=0;i<MainForm->ComponentCount;i++){' f# O N4 ^) V) B
if((button= dynamic_cast<TButton*>(MainForm->Components)) != NULL )
9 M, i5 T5 b' }5 H) Q' w button->Caption="Button";4 Q( c, ^3 i% q+ c
}
0 K: `- _( c: l# Y0 {, L( W |