C++Builder:将命令行参数从 WinMain 传递到 MainForm

问题描述 投票:0回答:1

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 不允许重载构造函数。

c++ c++98 c++builder-6
1个回答
0
投票

使用

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();
© www.soinside.com 2019 - 2024. All rights reserved.