请教高手(100分)

X

xjk00

Unregistered / Unconfirmed
GUEST, unregistred user!
在DELPHI中如何将类类型与类实例作为参数传递进函数中:
type childform=class(fatherform)
---
public username,usercom:stirng;
---
end;
type anotherform=class()
---
public
procedure makewindowopen(windowname:string;sender:TComponentClass);
---
end;
implementation
{$R *.dfm}
procedure makewindowopen(windowname:string;sender:TComponentClass);
var
x:TComponentClass;
begin
if application.FindComponent(windowname)=nil then
begin
application.CreateForm(sender,x);
x.username:=username;
x.usercom:=usercom

x.Show;
end;
end;
以上问题出错。
 
看了这个函数你应该明白了。
Procedure OpenForm(FormClass:TFormClass;Var Fm;Aowner:TComponent);
Var
i : integer;
Child:TForm;
begin
for i := 0 to Screen.FormCount-1 do
if Screen.Forms.ClassType = FormClass then
begin
Child := Screen.Forms;
if Child.WindowState = wsMinimized then
ShowWindow(Child.Handle,SW_SHOWNORMAL);
if (NOT Child.Visible) then
Child.Visible:=True;
Child.BringToFront;
Child.SetFocus;
TForm(Fm):=Child;
Exit;
end;
Child := TForm(FormClass.NewInstance);
TForm(Fm):=Child;
Child.Create(Aowner);
Child.Show;
end;
这样用:
procedure TMainFM.M_CustClick(Sender: TObject);
Var
Cust_FM:TForm;
begin
OpenForm(TCust_FM,Cust_FM,Self);
end;
 
请教DelphiLand我建立的并不是一个普通TForm。它有几个特有的公共变量,是供用户
设置权限的username,usercom等。所以不用Var Cust_FM:TForm;
 
既然你已经做了一个类,
[red]type anotherform=class()
---
public
procedure makewindowopen(windowname:string;sender:TComponentClass);
---
end;[/red]
你为何不将这个windowname封装到其中?这可是类的基本特性之一!
 
那参数如何传递。
 
要传递的参数当然也可以封装到类中!
 
同意windbell
 

Similar threads

顶部