Borland C++ Builder 6
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try
{
AnsiString s = ParamStr(0); // I want to pass this argument
Application->Initialize();
Application->CreateForm(__classid(TForm1), &Form1); // Can't pass here?
Application->Run(); // Can't pass here either???
}
catch (Exception &exception)
如何将命令行参数/参数传递给 Form1?
CreateForm 不允许重载构造函数。
使用
CreateForm
创建表单不允许直接在 Borland C++ Builder 6 中传递附加参数。
您可以通过创建一个附加方法来设置参数来解决此问题:
class TForm1 : public TForm
{
//...
public:
void SetCommandLineArguments(const AnsiString& arguments);
//...
};
您的表单可以像这样初始化:
AnsiString s = ParamStr(0); // Get the command line argument
Application->Initialize();
Application->CreateForm(__classid(TForm1), &Form1);
Form1->SetCommandLineArguments(s);
Application->Run();