请问C++ builder里可以在打开窗口时传参数吗?---在线等待

freefishlala 2003-04-14 04:01:34
我不想用全局变量,可是又必须在打开关闭窗口时传递参数,请问如何做到呢?
...全文
63 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
freefishlala 2003-04-15
  • 打赏
  • 举报
回复
说的没错,上面这段帮助虽然我也没完全明白,不过我换成非整型参数之后就可以了,多谢多谢。
写成员函数的方法我还没试,不知道从程序性能和稳定性来看,哪种方法会更好些呢?
big_d 2003-04-15
  • 打赏
  • 举报
回复
在在线帮助看到以下说明,第二个为int型重载时,需要以下处理了。
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);
free1949 2003-04-14
  • 打赏
  • 举报
回复
在CBC5.0中重载Form构造函数时,最后一位参数不能为int 型。
gdyt007 2003-04-14
  • 打赏
  • 举报
回复
這麽多方法
學習ing
哈哈!
bigwhiteshark(大白鲨:BCB反派人物)
你的信譽分怎麽加了又減了
真是服了你
IT-司马青衫 2003-04-14
  • 打赏
  • 举报
回复
我一般不去写构造函数
无论是静态还动态生成

我会做个成员函数来初始些东西
:
class TForm2 public:TForm
{
public:
void __fastcall Init(int i);
}

void __fastcall Form1::ButtonClick(TObject *Sender)
{
TForm2 *Form2=new TForm2(NULL);
Form2->Init(8868);
Form2->Show();
//or
if(Form2->ShowModal()==mrOk)
{
int id=Form2->GetSelectNameID();
}
}

big_d 2003-04-14
  • 打赏
  • 举报
回复
没有看到已经有人提出这个了,跟你报错的内容一致。
这个问题是去年有个刚学BCB的同事问我,当时我告诉他重载构造函数,这么巧他就是出现上面的情况,当时我也没有搞清楚,只是查找了form.hpp看到已经有个内联虚函数,可能跟这个有关,后来我让他重载成其他形式,问题也算“解决”,就没有再去找原因。今天看到这个,我突然记起来,所以想问问如何解释。
freefishlala 2003-04-14
  • 打赏
  • 举报
回复
你报的错是什么内容的?
big_d 2003-04-14
  • 打赏
  • 举报
回复
不过处理一个__fastcall TfrmInSth::TfrmInSth(TForm *frmLast,int nMyvalue ):TForm(Owner) 就好像有问题。
我在form.hpp中
/* TCustomForm.CreateNew */ inline __fastcall virtual TForm(Classes::TComponent* AOwner, int Dummy):TCustomForm(AOwner, Dummy) { }
我想既然是virtual,应该没有问题了。我想知道这个是怎么回事了?(只传递一个TForm,int时候)
freefishlala 2003-04-14
  • 打赏
  • 举报
回复
To Behard:

我按照你说的重载了构造函数
__fastcall TfrmModi::TfrmModi(TComponent* Owner, int choice)
: TForm(Owner)
可是运行的时候在以下地方报错
/* TCustomForm.Create */ inline __fastcall virtual TForm(Classes::TComponent* AOwner) : TCustomForm(AOwner) { }
显示stack overflow,这是为什么呢?需要把以前的构造函数删掉吗,谢谢!
lifuming 2003-04-14
  • 打赏
  • 举报
回复
如果是同事系统,可以建一个public变量来处理
Behard 2003-04-14
  • 打赏
  • 举报
回复
__fastcall TfrmInSth::TfrmInSth(TForm *frmLast, TComponent* Owner, char *filename)
: TForm(Owner)
{
m_frmMain = frmLast;
StrCopy ( m_strFileName, filename );
}

调用:
TfrmInSth *frmInSth = new TfrmInSth ( this, NULL, StatusBar1->Panels->Items[3]->Text.c_str() );
frmInSth->Show();
Behard 2003-04-14
  • 打赏
  • 举报
回复
直接重载构造函数
__fastcall TfrmMain(TComponent* Owner);
改为:
__fastcall TfrmMain(TComponent* Owner,int cmdline....);

13,825

社区成员

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

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