请问下,我要编写一个程式用于打开文件,应该要写么写代码? 我现写一个程式,就是在左侧memo中输入文件路径及文件名,点击按钮后可以打开相对应的文件,请问代码应该要怎么写,要用到哪些控件啊?(有点像WINDOWS的运行功能)我找资料找不到..如果高手可以将其中的关键部分加以说明的话就再好不过了.谢谢我在学习DELPHI是个初学者,希望可以了解更深入一些. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 memo.lines.loadformfile(path+name)纯文本格式的 procedure TForm1.Button1Click(Sender: TObject);beginWinExec(pchar('cmd /C '+memo1.Text),SW_HIDE);end; 在接口处的uses list里,加上 shellapi 单元调用ShellExecute(hWnd: HWND; Operation, FileName, Parameters,Directory: PChar; ShowCmd: Integer): HINST; stdcall;例子: begin ShellExecute(handle, 'open', 'http://www.baidu.com', nil, nil, SW_SHOWNORMAL); shellexecute(handle,'open','d:\a.txt',nil,nil,sw_shownormal); shellexecute(handle,'open',pansichar(trim(memo1.Text)),nil,nil,sw_shownormal);end; uses ShellAPI;...procedure TForm1.Button1Click(Sender: TObject);begin try ShellExecute(handle, 'open', PAnsiChar(trim(memo1.Text)),nil,nil,SW_SHOWNORMAL); except Application.MessageBox('打开文件错误','错误'); end;end;... WinExec,适合调用DOS程序ShellExecute,Windows程序用这个,相当于开始,运行CreateProcess,启动程序进程,可以有更多的控制 谢谢大家的回答,可能我表达的不太清楚,我要的是在memo中输入后可以直接打开的....smallhand的回答最贴近我的想法,但如果有ShellExecute(handle, 'open', PAnsiChar(trim(memo1.Text)),nil,nil,SW_SHOWNORMAL);的说明就更好了 rundll32.exe 请问 delphi 能 不能 执行 字符串 表达式 ?????????? win2000下怎么自定义纸张大小,怎么我自定义的纸张大小只能打印出一半 一个关于一个界面上有二三百个Edit的问题! 怎样用Delphi做串口通讯程序。请给指条路啊!急! 我的dll報錯了,請教各位!!! 如何实现20位卡号(string)的递增??? 在WORD文档里,如何取得光标所在位置的行和列? delphi与matlab的接口问题 面试时大家都向面试官问一些什么问题? 200RMB 求 Delphi 窗体代码 转换正则数据! 顶者有分! 求取网卡真实物理地址的代码
纯文本格式的
begin
WinExec(pchar('cmd /C '+memo1.Text),SW_HIDE);
end;
ShellExecute(handle, 'open', 'http://www.baidu.com', nil, nil, SW_SHOWNORMAL);
shellexecute(handle,'open','d:\a.txt',nil,nil,sw_shownormal);
shellexecute(handle,'open',pansichar(trim(memo1.Text)),nil,nil,sw_shownormal);
end;
ShellAPI;
...
procedure TForm1.Button1Click(Sender: TObject);
begin
try
ShellExecute(handle, 'open', PAnsiChar(trim(memo1.Text)),nil,nil,SW_SHOWNORMAL);
except
Application.MessageBox('打开文件错误','错误');
end;
end;
...
ShellExecute,Windows程序用这个,相当于开始,运行
CreateProcess,启动程序进程,可以有更多的控制
smallhand的回答最贴近我的想法,但如果有ShellExecute(handle, 'open', PAnsiChar(trim(memo1.Text)),nil,nil,SW_SHOWNORMAL);
的说明就更好了