bool TForm1::CreateForm(TForm *CForm)
{
int No;
bool FormExist=false;
if (CForm==NULL)
return false;
for (No=0;No<Screen->FormCount;No++)
{
if (Screen->Forms[No]->ClassType()==CForm->ClassType())
{
FormExist=true;
break;
}
}
if(FormExist==false)
return false;
if (CForm->WindowState==wsMinimized)
ShowWindow(CForm->Handle,SW_SHOWNORMAL);
else
ShowWindow (CForm->Handle,SW_SHOWNA);
if (!CForm->Visible)
CForm->Visible=true;
CForm->BringToFront();
CForm->SetFocus();
return true;}
//--------------------------------------------void __fastcall TForm1::Button1Click(TObject *Sender)
{
if ((!CreateForm(Form2)))
{
Form2 = new TForm2(Application);
Form2->Show();
}}
这是c++代码。请问怎么使在delphi中不重复创建mdi子窗体
{
int No;
bool FormExist=false;
if (CForm==NULL)
return false;
for (No=0;No<Screen->FormCount;No++)
{
if (Screen->Forms[No]->ClassType()==CForm->ClassType())
{
FormExist=true;
break;
}
}
if(FormExist==false)
return false;
if (CForm->WindowState==wsMinimized)
ShowWindow(CForm->Handle,SW_SHOWNORMAL);
else
ShowWindow (CForm->Handle,SW_SHOWNA);
if (!CForm->Visible)
CForm->Visible=true;
CForm->BringToFront();
CForm->SetFocus();
return true;}
//--------------------------------------------void __fastcall TForm1::Button1Click(TObject *Sender)
{
if ((!CreateForm(Form2)))
{
Form2 = new TForm2(Application);
Form2->Show();
}}
这是c++代码。请问怎么使在delphi中不重复创建mdi子窗体
解决方案 »
- 大家这种情况是怎么处理的?
- 如何设置公式
- 怎样用程序让鼠标单击
- 刷卡程序,关于焦点问题
- 使用fastreport打印报表后的事件如何写?急
- access数据库插入数据时报错,请高手指点!!!
- 请教,我有一个toolbar,上面有四个toolbutton,问题!
- ADOCommand and ADOQuery and ADODataset and ADOStroedProc 怎么用的, 急
- 怎样配置三层交换机(100¥),解决问题后在送上100大洋
- 请问如何根据现有的协议(如IPX)用DELPHI来编写通信程序。并将数据库的某数据块传送的连接的终端?????
- 菜不菜都进来帮帮忙?
- 调用Dll的问题
form.Show;
delphi里应该这样判断
if Form1<>nil then
beginend;
Form1:=TForm1.Create(Application);
Form1.show;
if not Assigned(Form1) then
Form1:=TForm1.Create(Application);
Form1.show;
{*
单元说明 创建模式窗口,和非模式窗口的类。
作者 易一 E-Mail: [email protected]
创建时间 2005年5月20日
及最后修改时间
修改人修改时间及
修改说明
*}
unit ShowFormClass;interfaceuses
SysUtils, Classes, Forms;type
TShowFormClass = class(TComponent)
private
{ Private declarations }
//保存要创建的窗体的类名
FFrmName:string;
//判断窗体是否存在。
function IsFormExist:boolean;
//得到窗体。
function GetForm:TForm;
//创建一个类
function CreateAClass(const AClassName: string): TForm;
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner: TComponent); virtual;
destructor Destroy; override;
//创建并显示窗体。模式窗体。
procedure ShowModalForm(const AStrForm:string);
//创建并显示窗体。非模式窗体。
procedure ShowModalLessForm(const AStrForm:string); published
{ Published declarations }
end;procedure Register;implementation
procedure Register;
begin
RegisterComponents('Yeeyee', [TShowFormClass]);
end;constructor TShowFormClass.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
end;destructor TShowFormClass.Destroy;
begin
inherited Destroy;
end;function TShowFormClass.GetForm:TForm;
var
i:integer;
begin
for i := 0 to (Application.ComponentCount - 1) do
begin
if (Application.Components[i] is TForm) then
begin
//注意,关键判断这个类型名称是否存在。
if (application.Components[i] as TForm).ClassType.ClassName = FFrmName then
begin
Result:=(application.Components[i] as TForm);
exit;
end
end;
end;
end;function TShowFormClass.IsFormExist:boolean;
var
i:integer;
begin
Result:=False;
for i := 0 to (Application.ComponentCount - 1) do
begin
if (Application.Components[i] is TForm) then
begin
//注意,关键判断这个类型名称是否存在。
if (application.Components[i] as TForm).ClassType.ClassName = FFrmName then
begin
Result:=True;
exit;
end
end;
end;
end;//创建一个类
function TShowFormClass.CreateAClass(const AClassName: string): TForm;
var
LFormClass : TFormClass;
LForm: TForm;
begin
LFormClass := TFormClass(FindClass(AClassName));
LForm := LFormClass.Create(Application);
Result := LForm;
end;//创建并显示窗体。模式窗体。
procedure TShowFormClass.ShowModalLessForm(const AStrForm:string);
var
LForm: TForm;
begin
FFrmName:=AStrForm;
//窗体不存在,则创建。
if not IsFormExist then
begin
LForm := CreateAClass(FFrmName);
LForm.Show;
end
else
begin
//存在,则得到窗体。带到最前头。
LForm:=GetForm;
LForm.BringToFront;
end;
end;//创建并显示窗体。模式窗体。
procedure TShowFormClass.ShowModalForm(const AStrForm:string);
var
LForm: TForm;
begin
FFrmName:=AStrForm;
LForm := CreateAClass(FFrmName);
try
LForm.ShowModal;
finally
LForm.Free;
end;
end;end.//调用单元
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
ShowModalLessForm('TForm2');
end;procedure TForm1.BitBtn2Click(Sender: TObject);
begin
ShowModalLessForm('TForm3');
end;
(*
procedure TForm1.BitBtn3Click(Sender: TObject);
begin
ShowForm(TForm2);
end;procedure TForm1.BitBtn4Click(Sender: TObject);
begin
ShowForm(TForm3);
end;
*)
initialization
begin
RegisterClasses([TForm2,TForm3]);
end;finalization
begin
UnRegisterClasses([TForm2,TForm3]);
end;
var Temp1:TForm;
I:integer;
Exist:Boolean;
begin
Exist:=False;
for I:=0 to Screen.FormCount-1 do
begin
if Screen.Forms[I].Caption='Temp1' then Exist:=True;
end;
if Exist then
begin
showmessage('窗口已经被创建!');
end
else
begin
Temp1:=TForm.Create(self);
Temp1.Caption:='Temp1';
end;
end;
如果可以做成dll免费帮我弄下呀。我对delphi还不太熟悉呀。谢谢拉。