Sixth chapter-Document management (iii) (3)

Source: Internet
Author: User
Tags file copy

6.4.5.3 a consistent interface

File copy, file movement, file name change, and changes to the back. The current directory is formally represented from a source file to a target file. Thus, a unified user interface, the Changeform dialog box, can be used

These four menu items share a click event process and determine the title and display of the dialog box that will be opened by checking the sender parameters. When the user presses the OK key to close and the destination file (directory) is not empty, the program pops up a message dialog box asking the user to confirm further and then perform the appropriate action.

The common event-handling process Filechange The following list of procedures:

Procedure Tfmform.filechange (Sender:tobject);

Var

Changeform:tchangeform;

Isfile:boolean;

Begin

Changeform: = Tchangeform.create (Self);

Isfile: = True;

With Changeform do

Begin

If Sender = Move1 then Caption: = ' move '

else if Sender = Copy1 then Caption: = ' Copy '

else if Sender = Rename1 then Caption: = ' Rename '

else if Sender = ChangeDirectory1 Then

Begin

caption:= ' Change Directory ';

Isfile:=false;

End

else Exit;

If Isfile Then

Begin

Currentdir.caption: = filelist.directory;

Fromfilename.text: = Filelist.filename;

Tofilename.text: = ';

End

Else

Begin

Currentdir.caption: = Drivetabset.tabs[drivetabset.tabindex];

Fromfilename.text: = directoryoutline.directory;

Tofilename.text: = ';

End

if (ShowModal <> idCancel) and (Tofilename.text <> ") Then

Confirmchange (Caption, Fromfilename.text, Tofilename.text);

End

End

The custom private procedure used in this confirmchange is used to perform the appropriate action:

Procedure Tfmform.confirmchange (const acaption, FromFile, tofile:string);

Begin

If Messagedlg (Format ('%s%s to%s ', [Acaption, FromFile, ToFile]),

Mtconfirmation, [Mbyes, Mbno], 0) = Idyes Then

Begin

If acaption = ' move ' Then

MoveFile (FromFile, ToFile)

else if acaption = ' Copy ' Then

CopyFile (FromFile, ToFile)

else if acaption = ' Rename ' Then

RenameFile (FromFile, ToFile)

else if acaption = ' Change Directory ' then

Changedirectory (ToFile);

Filelist.update;

End

End

6.4.5.4 Display file properties

When the program executes the Click event Processing for a Properties menu item, it first pops up a Tfileattrform Type dialog box that shows the file's properties

Reset file properties When the user modifies and confirms the program.

The Click event Process for the Properties menu item is as follows:

Procedure Tfmform.properties1click (Sender:tobject);

Var

Attributes, Newattributes:word;

Fileattrform:tfileattrform;

Begin

Fileattrform: = Tfileattrform.create (self);

Showfileattr (fileattrform,filelist.filename,filelist.directory);

End

The implementation of the process showfileattr is as follows:

Procedure Tfmform.showfileattr (fileattrform:tfileattrform;

afilename,directory:string);

Var

Attributes,newattributes:word;

Begin

With Fileattrform do

Begin

Filename.caption: = Afilename;

Filepath.caption: = Directory;

Changedate.caption: = Datetimetostr (FileDateTime (afilename));

Attributes: = Filegetattr (Afilename);

readonly.checked: = (Attributes and fareadonly) = Fareadonly;

archive.checked: = (Attributes and faarchive) = faarchive;

system.checked: = (Attributes and fasysfile) = Fasysfile;

hidden.checked: = (Attributes and Fahidden) = Fahidden;

If ShowModal <> IdCancel Then

Begin

Newattributes: = Attributes;

If readonly.checked then newattributes: = Newattributes or Fareadonly

else newattributes: = Newattributes and not fareadonly;

If archive.checked then newattributes: = Newattributes or faarchive

else newattributes: = Newattributes and not faarchive;

If system.checked then newattributes: = Newattributes or Fasysfile

else newattributes: = Newattributes and not fasysfile;

If hidden.checked then newattributes: = Newattributes or Fahidden

else newattributes: = Newattributes and not fahidden;

If Newattributes <> Attributes Then

Filesetattr (Afilename, newattributes);

End

End

End

The function used in the above procedure is defined in the Fmxutils cell and returns a variable of the Tdatatime type Filedatatime.

function FileDateTime (const filename:string): System.tdatetime;

Begin

Result: = Filedatetodatetime (Fileage (FileName));

End

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.