Represents application-level information.
Application: TApplication;
TApplication Application;
By default, when a new project is created, the IDE constructs an application object and assigns it to the Application variable in the Forms unit. Application has several properties that can be used to get information about an application while it runs.
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. Change the Old Path and New Path to move files outside the Debug directory, Old File and New File will not take a relative path. */ #include <memory> //for STL auto_ptr class void __fastcall TForm1::Save1Click(TObject *Sender) { AnsiString temp1 = Edit4->Text; AnsiString temp2 = ExtractFileName(Edit1->Text); AnsiString NewFileName = temp1 + temp2; AnsiString OldFileName = Edit3->Text + ExtractFileName(Edit2->Text); AnsiString Msg = Format("Copy %s to %s", ARRAYOFCONST((OldFileName, NewFileName))); if (MessageDlg(Msg, mtCustom, TMsgDlgButtons() << mbOK << mbCancel, 0) == mrOk) { std::auto_ptr<TFileStream> OldFile(new TFileStream(OldFileName, fmOpenRead | fmShareDenyWrite)); std::auto_ptr<TFileStream> NewFile(new TFileStream(NewFileName, fmCreate | fmShareDenyRead)); NewFile->CopyFrom(OldFile.get(), OldFile->Size); } } void __fastcall TForm1::FormCreate(TObject *Sender) { Edit3->Text = ExtractFilePath(Application->ExeName); Edit4->Text = Edit3->Text; }
/* This code displays the name of your project in an edit box: */ void __fastcall TForm1::Button1Click(TObject *Sender) { Edit1->Text = Application->Title; }
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. Change the Old Path and New Path to move files outside the Debug directory, Old File and New File will not take a relative path. } procedure TForm1.FormCreate(Sender: TObject); begin Edit3.Text := ExtractFilePath(Application.ExeName); Edit4.Text := Edit3.Text; end; procedure TForm1.Save1Click(Sender: TObject); var NewFileName, OldFileName: string; temp1, temp2: string; Msg: string; NewFile: TFileStream; OldFile: TFileStream; begin temp1 := Edit4.Text; temp2 := ExtractFileName(Edit1.Text); NewFileName := temp1 + temp2; OldFileName := Edit3.Text + 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;
{ This code displays the name of your project in an edit box: } procedure TForm1.Button1Click(Sender: TObject); begin Edit1.Text := Application.Title; end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|