|
e1 M1 U3 a2 `/ z
一./ c, {9 V2 d. a! q! I
AnsiString nameString("TButton");
3 l* W/ d7 B% E/ F# N4 r# |4 c) L; aTButton * button;
6 b2 R: i0 X# f: Z8 S2 l4 a6 `3 nfor(int i=0; i < ComponentCount; i++)
+ Q8 ~9 b$ q d{' u" H9 [+ W1 B9 c# Z
//Check to see if the component is a TButton
& r3 r! g# e8 J7 v% w! zif (Components->ClassNameIs(nameString))9 i' D5 ]1 v9 T8 ^& W9 G
{
7 C$ o* Q' P7 a5 M/ F4 t% h# y//cast the component to a TButton *" C2 r2 @. R8 J* H
button = (TButton *)Components;
% j4 N- c, ]7 M) o8 N F& x3 pbutton->Font->Name = "Courier";
( h7 A1 i4 f3 p* h8 Z: {3 m& O ......
9 U# H* F' j$ h0 ?: l7 l" b% |2 I$ u1 S3 @0 I3 q0 e8 K6 L) P7 i
二.
* v: L, T+ e' ^- u( |( U" @7 u我想动态创建和静态创建都没有太大区别,只要它属于你的MainForm。( new TButton(this) ).8 N$ D, T& i2 t- m4 z1 f( `6 _
用一个需循环
a" T8 h8 i, c. KTButton* button;( U; E1 i8 q/ ]3 ^# U h$ E8 X
for(int i=0;i<MainForm->ComponentCount;i++){" b1 E) N& c) n. ?0 T5 E1 X
if((button= dynamic_cast<TButton*>(MainForm->Components)) != NULL )
5 `- l( k$ O Z button->Caption="Button";, }' z0 F4 M/ z
}
) i) O! |& k; k9 K% E |