[英]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.