|
( u. v2 E+ f8 t
一.( N9 a+ R- X' f4 N0 K0 g
AnsiString nameString("TButton");# h* f+ Q% N- M7 ]
TButton * button;; ~' N/ A% z0 y8 Q5 L X) i1 [
for(int i=0; i < ComponentCount; i++)
3 R$ n0 I* g1 N9 b$ `{
# ^1 n* Y5 S2 a! N6 @//Check to see if the component is a TButton. O4 S1 W) [6 j8 _% x2 ]$ |
if (Components->ClassNameIs(nameString))
7 D0 w ^& d7 K3 _{% i2 B# g: z! d8 x6 n
//cast the component to a TButton *
' w% ^% f" q' g: i/ ]button = (TButton *)Components;
7 w8 t0 U5 _' w4 K, g4 o Lbutton->Font->Name = "Courier";% D3 ]% U& k0 G0 E
...... & n# W1 c( T* c$ _" h: c
+ @7 H9 C: i7 Z1 c
二.
1 q& n% g9 |; [我想动态创建和静态创建都没有太大区别,只要它属于你的MainForm。( new TButton(this) ).
4 y* Y" @! S- I/ R; Q2 a用一个需循环1 A _$ s8 I" D$ M; N; s
TButton* button;
, w0 H: n0 c0 A3 _8 Y9 L% D( ^for(int i=0;i<MainForm->ComponentCount;i++){
2 [- y& T( G) }, y9 d: f* oif((button= dynamic_cast<TButton*>(MainForm->Components)) != NULL )
2 C5 a5 T& t0 t9 ` button->Caption="Button";
! c) s; v7 a# D: v# {}
( L" Z$ Q2 H; z2 Q+ S! j J. [ |