線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2344
推到 Plurk!
推到 Facebook!

傳參數給Application

答題得分者是:RaynorPao
JosephLiu77
一般會員


發表:11
回覆:8
積分:3
註冊:2003-02-06

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-08-15 16:50:09 IP:200.56.xxx.xxx 未訂閱
如果寫一個Console Application可以直接傳參數並執行EXE C:\>Console.exe str1 str2 str3 可是如果是一個含有Form的Application的話,要如何傳參數並執行EXE C:\>Project1.exe str1 str2 str3 我不知道Project1要怎麼接收參數? 請各位大大幫忙,謝謝
RaynorPao
版主


發表:139
回覆:3622
積分:7025
註冊:2002-08-12

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-08-15 16:53:52 IP:203.73.xxx.xxx 未訂閱
引言: 如果寫一個Console Application可以直接傳參數並執行EXE C:\>Console.exe str1 str2 str3 可是如果是一個含有Form的Application的話,要如何傳參數並執行EXE C:\>Project1.exe str1 str2 str3 我不知道Project1要怎麼接收參數? 請各位大大幫忙,謝謝 < face="Verdana, Arial, Helvetica"> JosephLiu77 你好: 可以利用 ParamCount、ParamStr 來達成目的 (試試以下的範例程式碼) < class="code"> void __fastcall TForm1::FormCreate(TObject *Sender) { for(int i=1; i<=ParamCount(); i ) { ShowMessage(ParamStr(i)); } } -- Enjoy Researching & Developing --
------
-- 若您已經得到滿意的答覆,請適時結案!! --
-- 欲知前世因,今生受者是;欲知來世果,今生做者是 --
-- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 --
axsoft
版主


發表:681
回覆:1056
積分:969
註冊:2002-03-13

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-08-15 17:13:25 IP:61.218.xxx.xxx 未訂閱
JosephLiu77您好:
我也來提供不一樣的方法,透過GetCommandLine() API函數來取得 :
void __fastcall TForm1::FormCreate(TObject *Sender)
{
 ShowMessage(GetCommandLine());  
}    從C  Builder選單中選擇 Run | Parameters,以可以對你的寫的應用程式Project下參數,然後按Run就可以了    如果您下的Command是
c:\Progarm Files\CBuilder5\Projects\Project1.exe" p1 p2 p3    ShowMessage也相對會顯示
"c:\Progarm Files\CBuilder5\Projects\Project1.exe p1 p2 p3"    不過應用上還是用ParamStr(i)加上ParamCount()比較方便取用一點,看需求而定 
    <><>HAVE A NICE DAY FOR YOU    發表人 - axsoft 於 2003/08/15  17:27:56
        
dllee
站務副站長


發表:321
回覆:2519
積分:1711
註冊:2002-04-15

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-08-15 20:45:57 IP:61.224.xxx.xxx 未訂閱
那我也來提供一個不一樣的,請參考:    ■【BCB】【分享】程式轉向 http://delphi.ktop.com.tw/topic.php?TOPIC_ID=20771    原始碼如下:
/*---------------------------------------------------------------------------//
// ReDirection.cpp   Program ReDirection                               //
//                                                                           //
// Aug,23,2002       Version 0.1  by : Lee, Dong-Liang //
//---------------------------------------------------------------------------*/    #include 
#pragma hdrstop
#include 
//---------------------------------------------------------------------------
USERES("ReDirection.res");
//---------------------------------------------------------------------------
#pragma argsused
WINAPI WinMain(HINSTANCE hCurInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
  char lpRedirection[256]="C:\\HE7\\HE7.exe";      if(strlen(lpCmdLine)>0)
    MessageBox(
      hPrevInstance,         // handle of owner window
      lpCmdLine,             // address of text in message box
      "Redirection v0.1",    // address of title of message box
      MB_OK                  // style of message box
    );      ShellExecute(hCurInstance, // handle to parent window
    "open",                  // pointer to string that specifies operation to perform
    lpRedirection,           // pointer to filename or folder name string
    lpCmdLine,               // pointer to string that specifies executable-file parameters
    NULL,                    // pointer to string that specifies default directory
    SW_SHOWNORMAL            // whether file is shown when opened
  );      return 0;
}
我的方法算是最不方便的 <>沒空更新的網頁... href="http://dllee.adsldns.org">http://dllee.adsldns.org 介紹Shells,LiteStep,GeoShell....
------
http://www.ViewMove.com
JosephLiu77
一般會員


發表:11
回覆:8
積分:3
註冊:2003-02-06

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-08-17 22:27:42 IP:212.217.xxx.xxx 未訂閱
< >哇,好多種方法,感謝各位大大的指導< >
系統時間:2024-05-03 5:08:21
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!