RAD Studio VCL Reference
|
Contains the file name of the application's executable file including path information.
property ExeName: string;
__property AnsiString ExeName;
Use ExeName to obtain the name of the executable file for the application. ExeName is the fully-qualified name, including the path to the application's executable.
The name of the application is the root name of the project with an .EXE extension. By default, this name is PROJECT1.EXE. To change the ExeName, save the project by the desired new root name and rebuild the application. ExeName will reflect the change to the project file name.
ExeName is a read-only property.
C++ Examples:
/* This example copies a specified old file to a new file. Add a TSaveDialog to the form. Also add two TEdits, two TLabels and a TButton with the OnClick event named Save1Click. Files can be saved to and from the app directory by using relative paths. */ void __fastcall TForm1::Save1Click(TObject *Sender) { AnsiString NewFileName = ExtractFilePath(Application->ExeName) + ExtractFileName(Edit1->Text); AnsiString OldFileName = ExtractFilePath(Application->ExeName) + ExtractFileName(Edit2->Text); AnsiString Msg = Format("Copy %s to %s", ARRAYOFCONST((OldFileName, NewFileName))); if (MessageDlg(Msg, mtCustom, TMsgDlgButtons() << mbOK << mbCancel, 0) == mrOk) { TFileStream *OldFile = new TFileStream(OldFileName, fmOpenRead); try { TFileStream *NewFile = new TFileStream(NewFileName, fmCreate); try { NewFile->CopyFrom(OldFile, OldFile->Size); } __finally { FreeAndNil(&NewFile); } } __finally { FreeAndNil(&OldFile); } } } void __fastcall TForm1::FormCreate(TObject *Sender) { Label3->Caption = "Current directory: " + ExtractFilePath(Application->ExeName); }
Delphi Examples:
{ This example copies a specified old file to a new file. Add a TSaveDialog to the form. Also add two TEdits, two TLabels and a TButton with the OnClick event named Save1Click. Files can be saved to and from the app directory by using relative paths. } procedure TForm1.FormCreate(Sender: TObject); begin Label3.Caption:= 'Current directory: ' + ExtractFilePath(Application.ExeName); end; procedure TForm1.Save1Click(Sender: TObject); var NewFileName, OldFileName: string; Msg: string; NewFile: TFileStream; OldFile: TFileStream; begin NewFileName := ExtractFilePath(Application.ExeName) + ExtractFileName(Edit1.Text); OldFileName := ExtractFilePath(Application.ExeName) + ExtractFileName(Edit2.Text); Msg := Format('Copy %s to %s?', [OldFileName, NewFileName]); if MessageDlg(Msg, mtCustom, mbOKCancel, 0) = mrOK then begin OldFile := TFileStream.Create( OldFileName, 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;
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
|
What do you think about this topic? Send feedback!
|