|
+ H- w' t7 x2 S6 Q+ g
一.+ a, {6 c, g! j m2 K
AnsiString nameString("TButton");
) C( u+ x. T' P0 y% sTButton * button;# t h z$ J7 J9 i( v" w3 j
for(int i=0; i < ComponentCount; i++)% {) J8 F! `4 j/ @; P5 z
{
: v; I" \: K0 u0 U1 ^. u1 o6 d. D& X: B//Check to see if the component is a TButton
0 Y" B D! K3 Y, Gif (Components->ClassNameIs(nameString))
* y; g# j0 J- T, ~3 o) C5 A& K# J{
. b7 k7 o; \: a- i//cast the component to a TButton *
. K, D" {% i+ o3 d& W- W6 w/ [button = (TButton *)Components;
* Z' a% a. l- L8 k; Dbutton->Font->Name = "Courier";
0 S( o0 R" s! o' p, V% A* `; u ......
7 F" h- k' D" p) ?7 m1 Z
: n# G( h1 r% G% ^6 P二.
, @ H' y* R, t我想动态创建和静态创建都没有太大区别,只要它属于你的MainForm。( new TButton(this) ).8 E- C( u+ ]& \6 x& B/ e
用一个需循环6 g- r# M5 {1 c& d3 K
TButton* button;+ k( @4 n$ g# U; c+ S. N- N3 [6 e
for(int i=0;i<MainForm->ComponentCount;i++){
- f1 b h3 ?5 @if((button= dynamic_cast<TButton*>(MainForm->Components)) != NULL )
$ @& } G) x k$ G% u button->Caption="Button";! V- ]8 Q- D4 B8 d
}& @" C, t+ K0 X
|