有一段程序是用循環動態生成VCL組件的然後生成新的Form,現在我有一個問題就是如何才能在新生成的Form中設置其中的任何一個組件得到焦點?
多謝!
下面是生成新Form的原碼: int FormHeight=0,FormWidth=0;
if(!ThisApp)
{
ThisApp=Application;
Application=CallingApp;
}
AutoFormOPData = new TAutoFormOPData(Application);
// start create comp
for(int i=0;iCommaText =CompArray[i];
if(AutoFormOPData->Fields=="")
{
AutoFormOPData->Fields=(stringlist->Strings[0]);
AutoFormOPData->DataType=stringlist->Strings[3];
}
else
{
AutoFormOPData->Fields=AutoFormOPData->Fields "," stringlist->Strings[0];
AutoFormOPData->DataType=AutoFormOPData->DataType "," stringlist->Strings[3];
}
if(stringlist->Strings[2]=="TEdit")
{
TLabel *label=new TLabel(AutoFormOPData);
label->Caption =stringlist->Strings[1];
label->Top =FormHeight 5;
label->Parent =AutoFormOPData;
label->Name="label" IntToStr(i);
TEdit *edit=new TEdit(AutoFormOPData);
edit->Parent=AutoFormOPData;
edit->Name=stringlist->Strings[0];
edit->Top=FormHeight;
edit->Left=stringlist->Strings[1].Length()*10;
if(((edit->Left) (edit->Width))>FormWidth)
FormWidth= (edit->Left) (edit->Width);
edit->Text ="";
FormHeight=FormHeight 21;
delete label;
delete edit; }
if(stringlist->Strings[2]=="TMemo")
{
TLabel *label=new TLabel(AutoFormOPData);
label->Caption =stringlist->Strings[1];
label->Top =FormHeight 5;
label->Parent =AutoFormOPData;
label->Name="label" IntToStr(i);
TMemo *memo=new TMemo(AutoFormOPData);
memo->Parent=AutoFormOPData;
memo->Lines->Clear() ;
memo->Name=stringlist->Strings[0];
memo->Top =FormHeight;
memo->Left =stringlist->Strings[1].Length()*10;
if(((memo->Left) (memo->Width))>FormWidth)
FormWidth= (memo->Left) (memo->Width);
FormHeight=FormHeight 105;
delete label;
delete memo;
} } TBitBtn *bitbtnok=new TBitBtn(AutoFormOPData);
bitbtnok->Kind=bkOK;
bitbtnok->Top =FormHeight 10;
bitbtnok->Caption="Ok";
bitbtnok->Left =((FormWidth)/2)-10-bitbtnok->Width;
bitbtnok->Parent=AutoFormOPData;
bitbtnok->OnClick =AutoFormOPData->BitBtn1->OnClick ; TBitBtn *bitbtncancel=new TBitBtn(AutoFormOPData);
bitbtncancel->Kind=bkCancel;
bitbtncancel->Parent=AutoFormOPData;
bitbtncancel->Top =FormHeight 10;
bitbtncancel->Left =((FormWidth)/2) 10;
bitbtncancel->Caption="Cancel";
bitbtncancel->OnClick =AutoFormOPData->BitBtn2->OnClick ;
AutoFormOPData->SQLType=SQLType;
AutoFormOPData->TableName =TableName;
AutoFormOPData->Width =FormWidth 10;
AutoFormOPData->Height=FormHeight 70;
AutoFormOPData->Caption=FormCaption;
AutoFormOPData->Position=poMainFormCenter;
AutoFormOPData->Show();