c++windowsc++builderfiremonkeyc++builder-xe7

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:

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

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)

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. How do I get the file name?

Since now, Thank you A LOT.


Solution

  • You can use System::ParamCount() and System::ParamStr() to retrieve the command line arguments from anywhere (including FMXMain(), without modifying it). Here's an example using it from a form's OnShow event handler to populate a TMemo control, for instance:

    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.

    You can test it by using the Run->Parameters menu item in the IDE. Add some values as parameters and run the application.