Application到底该如何理解??

THEBEST 2005-08-22 04:26:53
TFPortSet *FPortSet; //TFPortSet是另一个窗口类型.

void __fastcall TMainForm::FormShow(TObject *Sender) //TMainForm是主窗口类型.
{
FPortSet = new TFPortSet(Application) ;
FPortSet->ShowModal() ;
// ....
}

请问用Application作为默认构造参数是什么意思?这个Application到底该如何理解呢?
...全文
160 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yifei1900 2005-09-03
  • 打赏
  • 举报
回复
楼主似乎问的是为什么需要传入一个Application,
Maconel(Maconel) 的回答比较合意,

在VCL类的继承层次中,在TComponent开始有一个ReadOnly的Owner属性,在构造函数中,提供一个Owner来对它初始化,

如Maconel(Maconel)所讲的,它的意义在于一个控件的Owner销毁时,自动会销毁它所Owner的控件

我们很多情况下会动态创建窗体,如下:
(1).TForm2 Form2 = new TForm2(this);//当前类作为Form2的Owner,当前类销毁时会通知Form2注销
(2).TForm2 Form2 = new TForm2(Application);//Application作为Form2的Owner,Application是在Forms.hpp中定义的一个全局的变量,是VCL应用程序的根
(3).TForm2 Form2 = new TForm2(NULL);//Form2没有Owner,注意了,这种情况一定要自己手动delete它.

ccrun.com 2005-09-02
  • 打赏
  • 举报
回复
TApplication类的详细描述:

http://ccrun.com/article/go.asp?i=116&d=qc4322
jemyzhang 2005-09-02
  • 打赏
  • 举报
回复
application其实就是一个真正的主窗口,只是大小为0,程序的主循环就是在这个对象里面,就跟mfc的winapp类似
THEBEST 2005-09-02
  • 打赏
  • 举报
回复
"TComponent* Owner这个参数,表示这个类的主人,注意,不是父窗体。"这句话不太理解.
怎么突然冒出TComponent* Owner来?哪里来的TComponent* Owner的?和上面我给出的有什么样的联系呢?

下属窗体?是不是MyButton是Form1的下属窗体这样理解?那为什么用它来初始化就是它的下属窗体的呀?

那Application会自动释放的是吧?


由于小弟没接触BCB多久,还望再指点一下.:P
Maconel 2005-08-22
  • 打赏
  • 举报
回复
TComponent* Owner这个参数,表示这个类的主人,注意,不是父窗体。
它的用处是,当类的主人被释放时,会自动的释放他的下属窗体,而不用你自己手动去释放。
比如
TButton* MyButton = new TButton(Form1);
...
如果按照c++的用法,在使用完毕MyButton后,应该自己去释放它:
delete MyButton;
但是有了TComponent* Owner后,就不用你自己去delete了,你根本不用去管它。
当Form1被释放时,Form1会自动地释放MyButton。

同理,楼主所说的Application,也是和Form1一样的用处,当Application被释放时,它会替你删掉你创建的实例。
当然,你仍然可以自己去delete你创建的对象,如果你自己delete掉了,他的owner就不会去管它了。
Sunpursue 2005-08-22
  • 打赏
  • 举报
回复
Pass a Component and an integer to create the form while bypassing the streaming system that loads a form抯 properties and descendants from a .DFM file. The second parameter (Dummy) serves only to distinguish this constructor from the first. This constructor is rarely used for form objects. When using this syntax, stream in an external .DFM to bind the visual components with their classes. WriteComponentResFile and ReadComponentResFile must bracket the constructor call. The following code sequence

1. streams out an external .DFM file
2. creates a new form disassociated from any .DFM resource file
3. streams in the external .DFM file and binds it to this new form:

WriteComponentResFile("Temp.dfm", Form1);

?
Form2 = new TForm(Application,1);

ReadComponentResFile("Temp.dfm", Form2);

Pass a window handle as a parameter to embed the form in a non-VCL window. This syntax is used when the form is implemented as an ActiveX control that is embedded in a non-VCL window.

13,822

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧