|
, Y% G7 N' f7 v8 S8 j+ W8 V
一.: a f/ {+ |: O
AnsiString nameString("TButton");
" R8 m2 ?. i" ~3 A1 CTButton * button;3 z, z1 R3 _- `- x# |' j
for(int i=0; i < ComponentCount; i++); U6 H0 J1 s( W. P6 s8 c$ l
{* t2 p2 o+ X0 ~/ J; \; y3 w. h& R
//Check to see if the component is a TButton
* V7 v9 ?2 k5 k2 jif (Components->ClassNameIs(nameString))% n9 E6 o0 Z# k$ v3 r) n
{, k0 ?; ]2 A" ?! G" ?( [9 V
//cast the component to a TButton *: r- i. ], ^2 M4 s1 H) D$ h, o
button = (TButton *)Components;
& G/ T, l' [9 w$ X8 z- n9 F8 d Nbutton->Font->Name = "Courier";% z2 i" i* G# K4 ]8 G; E2 ?$ P- m* u
......
# D; v# a6 n7 e1 ^
. @& a- M0 i' ~ c二.) b& I; w4 U5 g/ a
我想动态创建和静态创建都没有太大区别,只要它属于你的MainForm。( new TButton(this) ).: x c. @; y9 w8 m6 M W
用一个需循环1 f1 a( V3 y/ a9 L- R3 P) ~) T4 g
TButton* button;
( x1 }3 b6 j+ L6 t7 O& H+ Qfor(int i=0;i<MainForm->ComponentCount;i++){
5 J& i) U7 L& }: M$ {: kif((button= dynamic_cast<TButton*>(MainForm->Components)) != NULL )
9 e0 u+ D" U$ z0 H4 f button->Caption="Button";
2 s% G' J3 N* @2 T}7 G$ M; P& Y: R( _6 O
|