简体   繁体   English

Windows - 使用可视化库FMXMain获取参数

[英]Windows - Get arguments with visual library FMXMain

I'm trying to get the arguments declared in ProjectName.cpp file (the file of the application) wich contains the following autogenerated code: 我正在尝试获取在ProjectName.cpp文件(应用程序的文件)中声明的参数,其中包含以下自动生成的代码:

extern "C" int FMXmain()
{
    try
    {
        Application->Initialize();
        Application->CreateForm(__classid(TfrmPrincipal), &frmPrincipal);
        Application->CreateForm(__classid(TfrmCarregar), &frmCarregar);
        Application->CreateForm(__classid(TfrmCodigo), &frmCodigo);
        Application->CreateForm(__classid(TfrmConfig), &frmConfig);
        Application->CreateForm(__classid(TfrmImgConf), &frmImgConf);
        Application->CreateForm(__classid(TfrmSobre), &frmSobre);
        Application->CreateForm(__classid(TfrmTradutor), &frmTradutor);
        Application->Run();
    }
    catch (Exception &exception)
    {
        Application->ShowException(&exception);
    }
    catch (...)
    {
        try
        {
            throw Exception("");
        }
        catch (Exception &exception)
        {
            Application->ShowException(&exception);
        }
    }
    return 0;
}

I just would like to get the arguments when the application is launched, so i've tried to change the declaration of the function to: 我只想在启动应用程序时获取参数,所以我试图将函数的声明更改为:

extern "C" int FMXmain(String argv)

and

extern "C" int FMXmain(wchar_t* argv[]) // as I may need wide char support (TCHAR doesn't seems to be useful in this case)

or (the default) 或(默认)

extern "C" int FMXmain(char* argv[])

The only doubt I have is how to pass the value I get to the main form. 我唯一的疑问是如何将我得到的值传递给主表单。 Should I pass it after creation or after the application is already running? 我应该在创建后或应用程序运行后传递它吗? How do I do it? 我该怎么做?

OBS: Main form: frmPrincipal OBS:主要形式:frmPrincipal

If I'm making something wrong, please tell me. 如果我弄错了,请告诉我。 PS.: I'm just trying to get the file path after double click on it (I've already gotten the function wich will link my application to the registry) PS。:我只是想在双击它之后获取文件路径(我已经获得了将我的应用程序链接到注册表的功能)

References that helped me a little bit: 参考文献对我有所帮助:

WIKI Double Click on Your File(extension) & open it with your EXE(application) Opening c++ program by double clicking associated file. WIKI 双击您的文件(扩展名)并使用您的EXE(应用程序)打开它 通过双击相关文件打开c ++程序。 How do I get the file name? 我如何获得文件名?

Since now, Thank you A LOT. 从现在开始,谢谢你很多。

You can use System::ParamCount() and System::ParamStr() to retrieve the command line arguments from anywhere (including FMXMain() , without modifying it). 您可以使用System :: ParamCount()System :: ParamStr()从任何地方(包括FMXMain()检索命令行参数,而无需修改它)。 Here's an example using it from a form's OnShow event handler to populate a TMemo control, for instance: 这是一个使用表单的OnShow事件处理程序来填充TMemo控件的示例,例如:

void __fastcall TForm1::FormShow(TObject *Sender)
{
  Memo1->Lines->Clear();
  for(int i = 0; i < System::ParamCount(); ++i)
  {
    Memo1->Lines->Add(System::ParamStr(i));
  }
}

ParamStr(0) is always the fully-qualified executable name of the application itself. ParamStr(0)始终是应用程序本身的完全限定的可执行文件名。

You can test it by using the Run->Parameters menu item in the IDE. 您可以使用IDE中的Run-> Parameters菜单项对其进行测试。 Add some values as parameters and run the application. 添加一些值作为参数并运行应用程序。

Embarcadero Firemonkey is a bit like Delphi: you can get command line parameters (argc/argv) from the special functions: Embarcadero Firemonkey有点像Delphi:您可以从特殊函数获取命令行参数(argc / argv):

  • ParamCount() ParamCount()

  • ParamStr(). ParamStr这()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我们如何在Visual Studio的Windows中包含bgi库? - how do we include bgi library in windows with visual studio? 在 Windows 10 上使用 Visual Studio 2019 获取 Boost 1.71.0 库的错误 - Getting error for Boost 1.71.0 library with Visual Studio 2019 on windows 10 创建并将静态库链接到Visual Basic Windows Forms应用程序 - Creating and linking a static library to visual basic windows forms application 在没有Visual Studio的Windows上安装C ++ Boost库 - Installing C++ Boost library on Windows without Visual Studio 如何在Windows上使用Visual C ++强制加载链接库 - How to force a linked library to load using Visual C++ on Windows 如何在Visual Studio中的库编译时获取链接器错误? - How to get linker errors at library compile-time in Visual Studio? 如何让 OpenGL 在 Windows 上使用 Visual Studio Code? - How do I get OpenGL to work with Visual Studio Code on Windows? 如何使用Visual Studio检测并获得Windows服务的代码覆盖率? - How to instrument and get code coverage of a Windows service with Visual Studio? 函数参数的 Visual Studio 缩进 - Visual studio indentaion of function arguments 如何从Windows库的GUID获取PIDL? - How to get a PIDL from a Windows library's GUID?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM