|
( @# W( S5 d ^ p1 J2 s& _4 H
一.9 x* f0 J5 q9 c8 {, D! }9 }' \2 p
AnsiString nameString("TButton");
3 P; g! E- |7 `' v/ {2 ^. U5 ITButton * button;4 i/ V, }5 F2 Q* C5 E8 `1 Z+ E" l
for(int i=0; i < ComponentCount; i++)
/ _1 m6 c c" ~: R. g2 o8 f6 D @{
; O% P8 T+ l) f8 x' I# u' e" ?//Check to see if the component is a TButton
6 A7 l5 E8 u) ?( ]; z( g0 b/ tif (Components->ClassNameIs(nameString))4 m1 S u3 B' a* x
{
5 L' t! d# [+ ]3 m8 g; G5 a) ~//cast the component to a TButton *
- l+ v, D* O0 x! }: ]8 U" m9 gbutton = (TButton *)Components; z+ d9 \$ z& M9 E! R2 W
button->Font->Name = "Courier";
7 x" m# o2 C) X% E ......
; q0 E. s9 a6 p( {. Q, D7 @# n3 x) u8 p5 D4 w/ n
二.) C1 l( ^% u2 E8 ~# q. ], s2 ]
我想动态创建和静态创建都没有太大区别,只要它属于你的MainForm。( new TButton(this) ).
3 e, r# x" F8 y; h; t+ F5 @$ v+ L用一个需循环
% G9 p; L, ~3 {+ o2 hTButton* button;4 k$ ]$ s8 d, w4 G! g# n
for(int i=0;i<MainForm->ComponentCount;i++){
, ^8 Z% ^; c0 J+ Q7 Yif((button= dynamic_cast<TButton*>(MainForm->Components)) != NULL )
; P% o7 f$ `# O( z5 |: f button->Caption="Button";
9 t: A0 v) e* l% A; W% u) D; `}
{+ ]$ Q7 c# G) k |