在Delphi XE中将类作为过程的参数传递 [英] Passing a class as a parameter of a procedure in Delphi XE
本文介绍了在Delphi XE中将类作为过程的参数传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要做的是这样的事情:
what i need to do is something like this:
procedure A(type_of_form);
var form: TForm;
begin
form := type_of_form.Create(application);
form.showmodal;
freeandnil(form);
end;
我为每个动态创建的表单执行了以下操作:
I did this for every dynamically created form:
form1 := TForm1.Create(application);
form1.showmodal;
freeandnil(form1);
我将在过程A中执行的操作比较复杂,但问题在于如何进行创建形式有些一般。也许带@运算符的东西……我真的不知道。
What i will do inside procedure A is more complex, but the problem resides in how to make the creation of the form somewhat general. Perhaps something with @ operator... i really do not know.
感谢您的任何建议!
Thanks for any suggestion!
推荐答案
procedure Test(AMyFormClass: TFormClass);
var
form: TForm;
begin
form := AMyFormClass.Create(Application); // you can use nil if you Free it in here
try
form.ShowModal;
finally
form.Release; // generally better than Free for a Form
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Test(TForm2);
end;
这篇关于在Delphi XE中将类作为过程的参数传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文