DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: diga
今日帖子: 28
在线用户: 12
导航: 论坛 -> DELPHI技术 斑竹:liumazi,sephil  
作者:
男 ylp9802 (ylp9802) ★☆☆☆☆ -
普通会员
2004/2/3 9:17:27
标题:
怎样得到当前程序的路径?? 浏览:1765
加入我的收藏
楼主: 各位仁兄,在delphi中有没函数可以直接得到我当前所调用的可执行程序所在的路径??谢谢!!
----------------------------------------------
-
作者:
男 bjdribllec ( ) ★☆☆☆☆ -
盒子活跃会员
2004/2/3 9:25:04
1楼: GetDir
----------------------------------------------
-
作者:
男 ylp9802 (ylp9802) ★☆☆☆☆ -
普通会员
2004/2/3 9:39:55
2楼: 谢谢,上楼那位仁兄!!
----------------------------------------------
-
作者:
男 river (HZG) ★☆☆☆☆ -
盒子活跃会员
2004/2/3 10:53:50
3楼: unit GetDIRFrm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TGetDirForm = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Button1: TButton;
    Label3: TLabel;
    Edit3: TEdit;
    Edit4: TEdit;
    Label4: TLabel;
    Button2: TButton;
    Memo1: TMemo;
    Button3: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Edit4Change(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  GetDirForm: TGetDirForm;

implementation

{$R *.dfm}

procedure TGetDirForm.Button1Click(Sender: TObject);
var
  TmpPath: array[0..40] of char;
begin
  GetWindowsDirectory(@TmpPath, 40);
  Edit1.Text := TmpPath;
  GetSystemDirectory(@TmpPath, 40);
  Edit2.Text := TmpPath;
  Edit3.Text := Application.ExeName;
  GetTempPath(40, @TmpPath);
  Edit4.Text := TmpPath;
end;

procedure TGetDirForm.FormCreate(Sender: TObject);
begin
  Edit1.Text := ';
  Edit2.Text := ';
  Edit3.Text := ';
  Edit4.Text := ';
  Memo1.Text := ';
end;

procedure TGetDirForm.Button2Click(Sender: TObject);
begin
  with Memo1.Lines do
  begin
    Clear;
    Add('Windows Directory: ' + Edit1.Text);
    Add('System Directory: ' + Edit2.Text);
    Add(Edit2.Text);
    Add(ExtractFileDrive(Application.ExeName));
    Add(ExtractShortPathName(Application.ExeName));
    Add(Application.ExeName);
    Add(ExtractFileName(Application.ExeName));
    Add(ExtractFileExt(Application.ExeName));
    Add('Copyright By River 2003 hzg@ytpu.com');
  end;
end;

procedure TGetDirForm.Edit4Change(Sender: TObject);
begin
  if Edit4.Text <> ' then
    Button2.Enabled := True;
end;

procedure TGetDirForm.Button3Click(Sender: TObject);
var
  hCurWindow: HWnd;
  WinText: array[0..255] of char;
begin
  hCurWindow := GetWindow(Handle, GW_HWNDFIRST);
  while hCurWindow <> 0 do
  begin
    if GetWindowText(hCurWindow, @WinText, 255) > 0 then
    begin
      Memo1.Lines.Clear;
      Memo1.Lines.Add(StrPas(@WinText));
    end;
    hCurWindow := GetWindow(Handle, GW_HWNDNEXT);
  end;
end;

end.
----------------------------------------------
尽 吾 志 而 无 悔
www.2ccc.com
作者:
男 waterstone (waterstone) ★☆☆☆☆ -
盒子活跃会员
2004/2/3 13:04:51
4楼: 我晕,有那么复杂吗?

当前程序路径:
    caption:=extractfilepath(application.exename);
----------------------------------------------
我来自农村广阔的田野我的每一个动作都很夸张http://waterstone.51r.com
作者:
男 laoli ( ) ★☆☆☆☆ -
普通会员
2004/2/3 14:54:46
5楼: 我晕,有那么复杂吗?

当前程序路径:
 
caption:=ParamStr(0);
----------------------------------------------
-
作者:
男 river (HZG) ★☆☆☆☆ -
盒子活跃会员
2004/2/3 15:16:48
6楼: 上面的程序可以得到好多目录
如System32 , windows , temp , Application Path 等等
不过要是只取应用程序的目录,那当然用laoli的了
Label1.Caption := ParamStr(0); 
呵呵!
----------------------------------------------
尽 吾 志 而 无 悔
www.2ccc.com
作者:
男 chinahth (淡若浮云) ★☆☆☆☆ -
盒子活跃会员
2004/2/3 16:33:04
7楼: 如我当前执行的程序路径为:
D:/HHH/RS/AAA/RSAAA.EXE
也就是说我用caption:=ParamStr(0);得到的为:D:/HHH/RS/AAA/RSAAA.EXE,而我想要的是:D:/HHH/RS,又改怎么做呢?
----------------------------------------------
-
作者:
男 forumzcb (zcb) ★☆☆☆☆ -
盒子活跃会员
2004/2/3 17:23:34
8楼: 用extractfilepath(application.exename)就可以了
----------------------------------------------
-
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行66.40625毫秒 RSS