窗体上放置一个Memo控件,我可以将文本文件中的内容通过LoadFromFile加载进来。首先要先获得路径,于是我在窗体的初始化过程中这么写
Memo1.Lines.Add('C:\111.TXT');但是我现在想通过运行该文件的打开方式中,选择我自己的程序,程序运行自动加载该文件中的数据,于是我又这么写:Memo1.Lines.Add(ParamStr(1));
如果我在桌面上右键选中了三个文本文件,然后打开方式中运行我的程序加载数据的话For i := 1 to ParamCount do 
begin
  Memo1.Lines.Add(ParamStr(i));
end;但是这样却一下子弹出了三个我的程序来,我的目的只要求一个,就是在Memo中显示三个文件的路径名。请问我该怎么做,大家帮我一下,谢谢。

解决方案 »

  1.   

    如果写在 onCreate事件里,楼主的做法是完全没错的啊。 代码写在什么地方?
      

  2.   

    procedure   TForm1.FormCreate(Sender:   TObject);   
      var   
          sFileName:   string;   
      begin   
          if   ParamCount   >   0   then     //(*   有执行参数传入   *)   
          begin   
              sFileName   :=   ParamStr(1);   //(*   取得参数内容   *)   
              if   FileExists(sFileName)   then   
                  Memo1.Lines.LoadFromFile(sFileName)   
              else   
                  Application.MessageBox('找不到指定的档案',   '讯息',   48);   
          end;   
      end;   
    我是这么写的,然后我同时选种三个TXT文件,右键打开方式,选择我的程序来打开,但是现在却会一下子打开三个程序,我的目的是要在Memo1中现实三个路径,而不是打开三个程序来分别显示三个路径
      

  3.   

    引用:
    “我的目的只要求一个,就是在Memo中显示三个文件的路径名。请问我该怎么做,大家帮我一下”

    if   FileExists(sFileName)   then   
                  Memo1.Lines.LoadFromFile(sFileName)   
    -_-!  你做的和说的不一样。 引用:
    "大家可以在自己的机器上试一下。" 恭喜你,我这里没问题。
      

  4.   

    procedure TForm1.FormCreate(Sender: TObject);
    var
      i:integer;
    begin
      for i := 1 to ParamCount do
      begin
        Memo1.Lines.Add(ParamStr(i));
      end;
    end;
    这个是我的代码,我现在选中三个文件,右键选择我的程序打开,如何可以在一个程序中的Memo中同时显示三个文件的路径阿?
      

  5.   

    看看这两个帖子都包含你要的内容http://www.yesky.com/20000701/89833.shtmlhttp://www.wangwa.com/info/2006-12/46570.htm
      

  6.   

    unit ContextMenuHandle;
    interface
       uses Windows,ActiveX,ComObj,ShlObj,Classes;
    type
       TContextMenu = class(TComObject,IShellExtInit,IContextMenu)
       private
          FFileName: array[0..MAX_PATH] of Char;
       protected
          function IShellExtInit.Initialize = SEIInitialize; // Avoid compiler warning
          function SEIInitialize(pidlFolder: PItemIDList; lpdobj: IDataObject;
                   hKeyProgID: HKEY): HResult; stdcall;
          function QueryContextMenu(Menu: HMENU; indexMenu, idCmdFirst, idCmdLast,
                   uFlags: UINT): HResult; stdcall;
          function InvokeCommand(var lpici: TCMInvokeCommandInfo): HResult; stdcall;
          function GetCommandString(idCmd, uType: UINT; pwReserved: PUINT;
                   pszName: LPSTR; cchMax: UINT): HResult; stdcall;
    end;
    const   Class_ContextMenu: TGUID = '{19741013-C829-11D1-8233-0020AF3E97A0}';
    {全局唯一标识符(GUID)是一个16字节(128为)的值,它唯一地标识一个接口(interface)}
    var
       FileList:TStringList;
    implementation
    uses ComServ, SysUtils, ShellApi, Registry,UnitForm;
    function TContextMenu.SEIInitialize(pidlFolder: PItemIDList; lpdobj: IDataObject;
       hKeyProgID: HKEY): HResult;
    var
       StgMedium: TStgMedium;
       FormatEtc: TFormatEtc;
       FileNumber,i:Integer;
    begin
       http://www.xfbbs.com/Book/others/_25C8_25E7/default.htm果lpdobj等于Nil,则本调用失败
       if (lpdobj = nil) then begin
          Result := E_INVALIDARG;
          Exit;
       end;
       FileList:=TStringList.Create;
       FileList.Clear;
       http://www.xfbbs.com/Book/others/_25B3_25F5/default.htm始化剪贴版格式文件
       with FormatEtc do begin
          cfFormat := CF_HDROP;
          ptd := nil;
          dwAspect := DVASPECT_CONTENT;
          lindex := -1;
          tymed := TYMED_HGLOBAL;
       end;
       Result := lpdobj.GetData(FormatEtc, StgMedium);   if Failed(Result) then Exit;
       FileNumber := DragQueryFile(StgMedium.hGlobal,$FFFFFFFF,nil,0);
       for i:=0 to FileNumber-1 do begin
          DragQueryFile(StgMedium.hGlobal, i, FFileName, SizeOf(FFileName));
          FileList.Add(FFileName);
          Result := NOERROR;
       end;   ReleaseStgMedium(StgMedium);
    end;function TContextMenu.QueryContextMenu(Menu: HMENU; indexMenu, idCmdFirst,
       idCmdLast, uFlags: UINT): HResult;
    begin
      Result := 0;
      if ((uFlags and $0000000F) = CMF_NORMAL) or
         ((uFlags and CMF_EXPLORE) <> 0) then begin
        // 往Context Menu中加入一个菜单项 ,菜单项的标题为察看位图文件
        InsertMenu(Menu, indexMenu, MF_STRING or MF_BYPOSITION, idCmdFirst,
            PChar('文件操作'));
        // 返回增加菜单项的个数
        Result := 1;
      end;
    end;function TContextMenu.InvokeCommand(var lpici: TCMInvokeCommandInfo): HResult;
    var
      frmOP:TForm1;
    begin
      // 首先确定该过程是被系统而不是被一个程序所调用
      if (HiWord(Integer(lpici.lpVerb)) <> 0) then
      begin
         Result := E_FAIL;
         Exit;
      end;
      // 确定传递的参数的有效性
      if (LoWord(lpici.lpVerb) <> 0) then begin
         Result := E_INVALIDARG;
         Exit;
      end;   //文件操作窗口
      frmOP:=TForm1.Create(nil);
      http://www.xfbbs.com/Book/others/_25BD_25AB/default.htm所有的文件列表添加到文件操作窗口的列表中
      frmOP.ListBox1.Items := FileList;
      Result := NOERROR;
    end;function TContextMenu.GetCommandString(idCmd, uType: UINT; pwReserved: PUINT;
             pszName: LPSTR; cchMax: UINT): HRESULT;
    begin
       if (idCmd = 0) then begin
       if (uType = GCS_HELPTEXT) then
          {返回该菜单项的帮助信息,此帮助信息将在用户把鼠标
          移动到该菜单项时出现在状态条上。}
          StrCopy(pszName, PChar('点击该菜单项将执行文件操作'));
          Result := NOERROR;
       end
       else
          Result := E_INVALIDARG;
    end;type
       TContextMenuFactory = class(TComObjectFactory)
       public
       procedure UpdateRegistry(Register: Boolean); override;
    end;procedure TContextMenuFactory.UpdateRegistry(Register: Boolean);
    var
       ClassID: string;
    begin
       if Register then begin
          inherited UpdateRegistry(Register);
          ClassID := GUIDToString(Class_ContextMenu);
          http://www.xfbbs.com/Book/others/_25B5_25B1/default.htm注册扩展库文件时,添加库到注册表中
          CreateRegKey('*\shellex', '', '');
          CreateRegKey('*\shellex\ContextMenuHandlers', '', '');
          CreateRegKey('*\shellex\ContextMenuHandlers\FileOpreation', '', ClassID);
        //果操作系统为Windows NT的话
          if (Win32Platform = VER_PLATFORM_WIN32_NT) then
          with TRegistry.Create do
          try
             RootKey := HKEY_LOCAL_MACHINE;
             OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions', True);
             OpenKey('Approved', True);
             WriteString(ClassID, 'Context Menu Shell Extension');
          finally
             Free;
          end;
       end
       else begin
          DeleteRegKey('*\shellex\ContextMenuHandlers\FileOpreation');
          inherited UpdateRegistry(Register);
       end;
    end;