|
/ e5 Z2 P1 C# l+ X4 D/ H0 c; |一.4 V6 V2 k( @7 I" m
AnsiString nameString("TButton");2 {+ v& G6 `8 o0 i. B0 x
TButton * button;
; @# u! i* X! _5 jfor(int i=0; i < ComponentCount; i++)' T6 Q. b6 c- w0 p% a
{7 y- E* e* q( o# M; e
//Check to see if the component is a TButton/ `0 s. e8 C$ t" `' y2 W. m
if (Components->ClassNameIs(nameString))
4 C$ C" T0 Q* m6 v$ C! [{$ F# y$ R- ?/ B& W
//cast the component to a TButton *
1 v5 J+ n3 Q, Dbutton = (TButton *)Components;: O% ?2 C" e( c: P4 @2 P% s% H5 M1 E
button->Font->Name = "Courier";
9 `- s) P! V$ o+ T) D' I, p8 t ......
* A% l5 e' j# R8 \1 s. M( E, z/ C" u! S" B" ]% i g; D0 e
二.) K; S9 @/ w. I7 p. u& l
我想动态创建和静态创建都没有太大区别,只要它属于你的MainForm。( new TButton(this) ).
" C0 {$ @3 g& k% w3 ~! C) d用一个需循环
* d' J" K; C) ~# ^! A6 WTButton* button;
: d* Y: b0 d& o$ J1 |5 h1 H/ \. Yfor(int i=0;i<MainForm->ComponentCount;i++){
& S6 `. ]7 ?( {$ Aif((button= dynamic_cast<TButton*>(MainForm->Components)) != NULL )
+ B7 u- p( c' [; g7 W0 R button->Caption="Button";& y0 ]& y) `) c9 g" [* e8 `
} G2 X5 o c- x8 @+ E0 M8 R
|