|
* L9 Q! v7 S6 ?
一.& P V+ G! S" `; q0 V- _% ]
AnsiString nameString("TButton");+ r( j2 I0 M0 H- T/ b4 @
TButton * button;7 Y b; A& f' i t, {
for(int i=0; i < ComponentCount; i++)# ~5 Q8 ^. V0 Z7 `3 q, g& n
{3 X0 T% C: X, n( x+ y% c
//Check to see if the component is a TButton: C& k7 q, ~, `+ {
if (Components->ClassNameIs(nameString))2 u: w3 Z$ e" Y8 M
{5 \, a" m9 b) K
//cast the component to a TButton *6 L/ c% d A# Q7 a
button = (TButton *)Components;, q0 \5 d- p- x: N$ V$ F
button->Font->Name = "Courier";
' `! v0 U, x/ ]$ b ......
! d a! s9 y. P# E" W$ l( |* r
9 p7 e8 W! e1 @二.
8 V1 j( G" [$ z) }- `6 N- v0 Z我想动态创建和静态创建都没有太大区别,只要它属于你的MainForm。( new TButton(this) ).
3 N' a7 e1 r/ n) G$ x用一个需循环; u# r. S* y2 H! s
TButton* button;- m: [$ S8 W" V& F y& m
for(int i=0;i<MainForm->ComponentCount;i++){
& h' v/ S: ^# I9 {5 V' f% cif((button= dynamic_cast<TButton*>(MainForm->Components)) != NULL )
$ E, K0 c+ d& F9 b' f4 p button->Caption="Button";5 U p# N: n9 { V
}- l8 K0 S3 A- p* u/ Y
|