雨
雨中雪
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
function openForm(const AClassName : string;const AOwner : TComponent=nil):TForm;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses unit2;
{$R *.dfm}
function Tform1.OpenForm(
const AClassName : string;
const AOwner : TComponent=nil
):TForm;
//根据窗口类名建立窗口
var
i : integer;
frmTemp : TForm;
cmpOwner : TComponent;
begin
Screen.Cursor := crHourGlass;
try
for i := 0 to Screen.FormCount -1 do
if Screen.Forms.ClassName = AClassName then
begin
frmTemp := Screen.Forms;
if frmTemp.WindowState=wsMinimized then
frmTemp.WindowState:=wsNormal;
frmTemp.BringToFront;
frmTemp.Setfocus;
Result := frmTemp;
Exit;
end;
if Assigned(AOwner) then
cmpOwner := AOwner
else
cmpOwner := Application;
Result := nil;
if Assigned(GetClass(AClassName)) and FindClass(AClassName).InheritsFrom(TForm) then
try
Result := TForm(FindClass(AClassName).NewInstance);
Result.Create(cmpOwner);
except
end;
finally
Screen.Cursor := crDefault;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
openform('form2',self);
end;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
function openForm(const AClassName : string;const AOwner : TComponent=nil):TForm;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses unit2;
{$R *.dfm}
function Tform1.OpenForm(
const AClassName : string;
const AOwner : TComponent=nil
):TForm;
//根据窗口类名建立窗口
var
i : integer;
frmTemp : TForm;
cmpOwner : TComponent;
begin
Screen.Cursor := crHourGlass;
try
for i := 0 to Screen.FormCount -1 do
if Screen.Forms.ClassName = AClassName then
begin
frmTemp := Screen.Forms;
if frmTemp.WindowState=wsMinimized then
frmTemp.WindowState:=wsNormal;
frmTemp.BringToFront;
frmTemp.Setfocus;
Result := frmTemp;
Exit;
end;
if Assigned(AOwner) then
cmpOwner := AOwner
else
cmpOwner := Application;
Result := nil;
if Assigned(GetClass(AClassName)) and FindClass(AClassName).InheritsFrom(TForm) then
try
Result := TForm(FindClass(AClassName).NewInstance);
Result.Create(cmpOwner);
except
end;
finally
Screen.Cursor := crDefault;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
openform('form2',self);
end;
end.