|
4 v: w; \/ S: V4 g: P% T. S3 h
一.' R* u3 I0 @4 V4 e4 x) {. ~
AnsiString nameString("TButton");: V# {7 @, |2 H
TButton * button;
! t( l/ R/ e) Yfor(int i=0; i < ComponentCount; i++)
8 n9 c3 F/ Z* g4 Y0 R5 ]{2 S4 T. E! \- n B, O& i
//Check to see if the component is a TButton& ~; [, ^7 D+ @8 h$ C9 o9 |
if (Components->ClassNameIs(nameString))
; L# p4 t8 k! t) d) r, q% p3 ~{
$ e, d: V4 f+ r2 C2 R7 t7 p! ?//cast the component to a TButton *
. B( E7 ?2 f5 M9 kbutton = (TButton *)Components;
' a4 t5 Q/ D) B& ~button->Font->Name = "Courier";
4 c& V& g Q4 p, N3 }4 x4 R+ t ...... 5 s# Y g0 e: p( N
5 `. _; ?" K2 a/ f% v+ V二.
8 H, e4 {: j7 q: Q4 b$ @我想动态创建和静态创建都没有太大区别,只要它属于你的MainForm。( new TButton(this) ).9 `& Y- h5 t9 ^/ E8 f% P
用一个需循环
m* v" y* x: ^( Z$ J* Z# STButton* button;
0 O2 J8 h7 M; k' x" p+ ]9 g+ wfor(int i=0;i<MainForm->ComponentCount;i++){; `6 ]# d* b: z( l9 a
if((button= dynamic_cast<TButton*>(MainForm->Components)) != NULL )- Y+ S" e# s+ S5 S
button->Caption="Button";
" V: T- I9 J8 f$ z) C; e: Z}9 r7 m. W, }- F: a- L$ s
|