Sixth chapter-Document management (iii) (1)

Source: Internet
Author: User

2. Draw each Self painting project

This is done during the Tabset OnDrawTab event process. The parameters of this event-handling process include the index of the item to be drawn, the artboard, the area to be drawn, whether it is selected, and so on. Here we only take advantage of the first three parameters. In fact, with the last parameter, we can perform some special visual effects on the selected label. This work is left to the reader to complete.

Procedure Tfmform.drivetabsetdrawtab (Sender:tobject; Tabcanvas:tcanvas;

R:trect; Index:integer; Selected:boolean);

Var

Bitmap:tbitmap;

Begin

Bitmap: = Tbitmap (Drivetabset.tabs.objects[index]);

With Tabcanvas do

Begin

Draw (R.left, R.top + 4, Bitmap);

TextOut (R.left + 2 + bitmap.width, R.top + 2, Drivetabset.tabs[index]);

End

End

Realization of basic function of 6.4.5 file management

In the child window's File menu, you define the basic functions of document management, which are:

Open: Opens or runs a file (double-click the file from the File list box to achieve the same effect)

Move: Files moving between different directories

Copy: File copy

Delete: File deletion

Rename: File name change

Properties: Displaying file properties

6.4.5.1 File Open

The file-opening feature allows you to run an executable file or to open the file in an application associated with it. The file is always associated with the application that created it, and this association can be modified in Windows File Manager. Note that the association of the file is the prefix of the suffix, so the modification of a file association will affect all files of the same suffix name.

The key to the implementation of the file opening feature is the use of Windows API function ShellExecute. Because the parameters of the Windows API function require that the string type is Pchar, and Delphi generally uses a string type with an end flag, it is convenient for us to redefine this function as follows.

function Executefile (const FileName, Params, defaultdir:string;

Showcmd:integer): Thandle;

Var

Zfilename, Zparams, zdir:array[0..79] of Char;

Begin

Result: = ShellExecute (Application.MainForm.Handle, Nil,

Strpcopy (Zfilename, FileName), Strpcopy (Zparams, Params),

Strpcopy (Zdir, DefaultDir), showcmd);

End

The above functions are defined in the Fmxutils unit. Fmxutils is a custom code unit.

The reader can consult the online Help file for specific meanings of the parameters in ShellExecute.

Strpcopy copies a Pascal-type string into a Pchar type string with no terminator.

During the Open1click event processing of a child window:

Procedure Tfmform.open1click (Sender:tobject);

Begin

with FileList do

Executefile (FileName, ', Directory, sw_show);

End

If filelist allows the display of directories (that is, the filetype attribute adds a ftdirectory), then for a directory, the open meaning should be to display subdirectories and files underneath it. The program is modified as follows.

Procefure Tfmform.open1click (Sender:tobject);

Begin

with FileList do

Begin

If Hasattr (filename,fadirectory) Then

Directoryoutline.directory: = FileName

Else

Executefile (FileName, ', Directory,sw_show ');

End

End

Where hasattr is a custom function in a fmxutils unit that detects whether a specified file has an attribute.

function hasattr (const filename:string; Attr:word): Boolean;

Begin

Result: = (filegetattr (FileName) and Attr) = Attr;

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.