请问如何得到软件所在的目录?等待中。。。。。。。 不要告诉我用getcurrentdir,因为getcurrentdir获得的是系统当前的目录,若是在程序中使用了opendialog之类的东西之后,用getcurrentdir获得的目录就变成了刚刚opendialog打开后的那个目录。有什么方法能够获得程序运行所在的目录而不受opendialog之类的东西的影响? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //可以看到这个实例子procedure TForm1.Save1Click(Sender: TObject);var NewFileName: string; Msg: string; NewFile: TFileStream; OldFile: TFileStream;begin NewFileName := ExtractFilePath(Application.ExeName) + ExtractFileName(Edit1.Text); Msg := Format('Copy %s to %s?', [Edit1.Text, NewFileName]); if MessageDlg(Msg, mtConfirmation, mbOKCancel, 0) = mrOK then begin OldFile := TFileStream.Create(Edit1.Text, fmOpenRead or fmShareDenyWrite); try NewFile := TFileStream.Create(NewFileName, fmCreate or fmShareDenyRead); try NewFile.CopyFrom(OldFile, OldFile.Size); finally FreeAndNil(NewFile); end; finally FreeAndNil(OldFile); end; end;end; 用ExtractFilePath(Application.ExeName);这是取得可执行程序的路径,相当于d:\project\最后一个字符是'\',用GetCurrentdir();是取得的当前活动目录,有时用这个可以正常运行,因为你在程序运行中没有对其它目录进行操作,如果你在程序运行时对其它目录进行操作的话,这个程序,肯定出错。 请问如何设置TQRRichText的字体。 问个狠的,想象中..... 请告诉我什么才是真正的多层分布式系统 新手很多问题需要请教:关于colorbox的一个! 兄弟们,帮个忙,我是‘改’还是‘不改’? 这周抢分太厉害,决定放点分,呵呵~~ 使用inforPower的Dbgrid,如何在输入完一条之后自动增加一行? 为什么mediaplay的close属性不起作用呢? 如何监控各种窗体的滚动条? 图表DBCHART的series使用 谁能详细解释一下TBits类的用法? 有没有办法让DBGRID的picklist达到Combobox的csDropDownList效果.
procedure TForm1.Save1Click(Sender: TObject);var
NewFileName: string;
Msg: string;
NewFile: TFileStream;
OldFile: TFileStream;
begin
NewFileName := ExtractFilePath(Application.ExeName) + ExtractFileName(Edit1.Text);
Msg := Format('Copy %s to %s?', [Edit1.Text, NewFileName]);
if MessageDlg(Msg, mtConfirmation, mbOKCancel, 0) = mrOK then
begin
OldFile := TFileStream.Create(Edit1.Text, fmOpenRead or fmShareDenyWrite);
try
NewFile := TFileStream.Create(NewFileName, fmCreate or fmShareDenyRead); try
NewFile.CopyFrom(OldFile, OldFile.Size);
finally
FreeAndNil(NewFile);
end;
finally
FreeAndNil(OldFile);
end;
end;end;
这是取得可执行程序的路径,相当于d:\project\
最后一个字符是'\',
用GetCurrentdir();是取得的当前活动目录,
有时用这个可以正常运行,因为你在程序运行中没有对其它目录进行操作,
如果你在程序运行时对其它目录进行操作的话,
这个程序,肯定出错。