?
Solved

Passing Argument to  Delphi exe application

Posted on 2006-05-12
3
Medium Priority
?
886 Views
Last Modified: 2008-03-10
I want to write delphi application and get outside parameters
in C++ I use args variable from

 WINAPI WinMain(HINSTANCE, HINSTANCE hInstance, LPSTR args, int)
{
}

but in delphi (2005) there is no function like this

Can someone help me.

---------
Thanks
0
Comment
Question by:xtrue
  • 2
3 Comments
 
LVL 26

Accepted Solution

by:
Russell Libby earned 375 total points
ID: 16667480

Delphi exposes the following which lets you work with the command line / arguments for the running process:

- CmdLine variable
- ParamCount function
- ParamStr function

Example from the Delphi help (D5)

procedure TForm1.FormCreate(Sender: TObject);

var
  i: Integer;
  for i := 0 to ParamCount – 1 do
  begin
    if LowerCase(ParamStr(i)) = 'beep' then
      Beep(10000,1000)
    else if (LowerCase(ParamStr(i)) = 'exit' then
      Application.Terminate;
  end;
end;

------

Regards,
Russell
0
 

Author Comment

by:xtrue
ID: 16670003
THanks,

another thing, Why my file's name (pass as argument) look like

C:\Docu~1\xxxx\Desktop\abc~TXT.bit

????

I want it to completely correct, I use

HKEY_CLASSES_ROOT\*\shell\My Command\command
(default) is %Path%/My App/myapp.exe %1

Please help me again

-----------
Thanks!
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 16670396

// Exported from kernel32.dll in Win98 and higher
function GetLongPathName(lpszShortPath: PChar; lpszLongPath: PChar; cchBuffer: DWORD): DWORD; stdcall; external 'kernel32.dll' name 'GetLongPathNameA';

function GetLongFileName(FileName: String): String;
var  lpszFile:      Array [0..MAX_PATH] of Char;
begin

  // Get long path name
  SetString(result, lpszFile, GetLongPathName(PChar(FileName), @lpszFile, MAX_PATH));

end;
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question