|
8 w% W# Y& w B4 g一.8 i. W9 F4 L& G# Z2 K
AnsiString nameString("TButton");
) c" U6 P, m( F5 ~4 x- ?, U! ITButton * button;1 G2 V( h; _6 q f
for(int i=0; i < ComponentCount; i++) a. w+ j {; G' D' r5 D3 o: ], Y
{5 H. @: z/ r3 G" X) A7 Z" E
//Check to see if the component is a TButton
+ m7 \) Y% H6 _$ R4 V4 q* G& iif (Components->ClassNameIs(nameString)). b( M2 _/ m4 R* h
{
# |7 N% T0 j9 K//cast the component to a TButton *0 \7 k. h1 v7 Y/ z
button = (TButton *)Components;
2 m" o6 D! _: c2 u* }button->Font->Name = "Courier";# g1 U" N% e3 z
......
# k( C+ d, v1 }9 q5 m7 `- b. i/ _
二.
# v! M, c- A6 ~6 p我想动态创建和静态创建都没有太大区别,只要它属于你的MainForm。( new TButton(this) ). X9 Y- z: v3 Q6 g5 I9 Z
用一个需循环
1 v& H! Y, [4 ?# h; |- \. fTButton* button;, t9 o9 j3 q# z: U7 [ L& R; Y
for(int i=0;i<MainForm->ComponentCount;i++){( x! [3 I# _& U/ ^2 l3 I
if((button= dynamic_cast<TButton*>(MainForm->Components)) != NULL )
8 k0 `. C7 y5 F8 T) } button->Caption="Button";' Y0 t5 x6 O/ X5 j
}' L1 N6 E) P# g0 I u
|