Z
zhbforce
Unregistered / Unconfirmed
GUEST, unregistred user!
关于在MDI窗体中防止子窗体重复打开的问题,改制的函数一直不能用。
请大家看以下代码:
function TfrmMain.OpenForm(var WForm:TForm):Boolean;
var
i:Integer;
FormExist:Boolean;
begin
//Determine if the form has been built.
if (WForm=nil) then
begin
Result:=false;
Exit;
end;
FormExist:=false;
for i:=0 to Screen.FormCount-1 do
begin
if Screen.Forms.ClassType=WForm.ClassType then
begin
FormExist:=true;
break;
end;
end;
if FormExist=false then
begin
Result:=false;
Exit;
end;
//If the form has been built,determine if the form is minimized or invisible
if Wform.WindowState=wsMinimized then
ShowWindow(WForm.Handle,SW_SHOWNORMAL)
else
ShowWindow(WForm.Handle,SW_SHOWNA);
if not WForm.Visible then
WForm.Visible:=True;
WForm.BringToFront;
WForm.SetFocus;
Result:=True;
end;
调用方法:
if OpenForm(AboutBox)=false then
begin
AboutBox:=TAboutBox.Create(Owner);
AboutBox.Show;
end;
为什么一到改变WFORM属性的时候,就报出访问冲突的错误,这个写法在C++Builder中却是可以的。
请大家看以下代码:
function TfrmMain.OpenForm(var WForm:TForm):Boolean;
var
i:Integer;
FormExist:Boolean;
begin
//Determine if the form has been built.
if (WForm=nil) then
begin
Result:=false;
Exit;
end;
FormExist:=false;
for i:=0 to Screen.FormCount-1 do
begin
if Screen.Forms.ClassType=WForm.ClassType then
begin
FormExist:=true;
break;
end;
end;
if FormExist=false then
begin
Result:=false;
Exit;
end;
//If the form has been built,determine if the form is minimized or invisible
if Wform.WindowState=wsMinimized then
ShowWindow(WForm.Handle,SW_SHOWNORMAL)
else
ShowWindow(WForm.Handle,SW_SHOWNA);
if not WForm.Visible then
WForm.Visible:=True;
WForm.BringToFront;
WForm.SetFocus;
Result:=True;
end;
调用方法:
if OpenForm(AboutBox)=false then
begin
AboutBox:=TAboutBox.Create(Owner);
AboutBox.Show;
end;
为什么一到改变WFORM属性的时候,就报出访问冲突的错误,这个写法在C++Builder中却是可以的。