Sixth chapter-Document management (ii) (2)

Source: Internet
Author: User
Tags integer

6.2.8 Results Synthesis

The evaluation results of different methods can be synthesized according to certain formulae. When the user presses the "Calculate" button, the system calculates and writes the composite result to the HAZATTR read-only edit box.

In order to ensure the correctness of the results, the hazattr edit box is emptied after each increment, modification and deletion operation is confirmed.

6.2.9 Edit dialog box input check

When the user clicks the Add or Modify button, the system pops up an edit dialog box that allows the user to enter or modify the contents of the record. One of the three edit boxes, one combo list box corresponds to the TMethod four fields. Because the TMethod result field must be a decimal number between [0,1], type and range checking should be done when the user presses the OK key to close the dialog box.

In VB I did the same work, then need to user input key code to judge one by one. But this approach is cumbersome and difficult to do satisfactorily (such as the inability to support editing keys well). And the Object Pascal provides a better way. The key to this approach is its type conversion function Val:

Procedure Val (Str:string;var V; var code:integer);

V is the integer or real number converted by Str. If the string is illegal, the error position is returned to code, otherwise the code is 0. The string is illegal and does not throw a conversion exception.

If the number of conversions is beyond our range, explicitly set the code to-1. Finally, it is unified to determine whether the input is legal by detecting the code for 0来.

We put the input check in the Onclosequery Event process of the dialog box. If the entry is illegal, prevent the dialog box from closing and place the input focus in the result edit box. However, if the user presses the Cancel button, this check is redundant. This defines a Boolean variable iscancel, which is set to False when the dialog box is generated. True if the user presses Cancel, at which point the Onclosequery event is not checked for input.

The list of Onclosequery event-handling procedures for the dialog box is as follows:

Procedure Teditform.formclosequery (Sender:tobject; var canclose:boolean);

Var

Res:real;

K:integer;

Begin

If Iscancel = False Then

Begin

Val (result.text,res,k);

if (res > 1) or (res < 0) Then K: =-1;

If k <> 0 Then

Begin

Messagedlg (' Illegal input! ', mtwarning,[mbok],0);

Result.text: = ';

Canclose: = False;

Result.setfocus;

End

End

End

6.2.10 file and system shutdown

File shutdown requires the CloseFile procedure to be invoked:

CloseFile (Methodfile);

and reset the state of the system.

When the system shuts down, first detects if there is an open file. If so, close the file first. This is implemented in the Onclosequery event of the main window.

The list of programs that implement file closings is as follows:

Procedure Trecfileform.closebuttonclick (Sender:tobject);

Begin

If Fileopened Then

Begin

CloseFile (Methodfile);

fileopened: = False;

Cleargrid;

openbutton.enabled: = True;

newbutton.enabled: = True;

closebutton.enabled: = False;

Recfileform.caption: = formcaption;

End

End

The list of procedures to be checked before system shutdown is as follows:

Procedure Trecfileform.formclosequery (Sender:tobject;

var canclose:boolean);

Begin

If Fileopened Then

CloseFile (Methodfile);

End

Summary of 6.2.11 record files

The examples we cite are simple, but basically cover the main aspects of document operation. The key problem here is to apply the file management function provided by Delphi flexibly. At the same time, in order to ensure the robustness of the program to catch and deal with the exception. In the development of database application technology today, the importance of recording documents may be reduced, but the object we are dealing with the simple problem it is still useful.

The example given here can only process one file at a time. But readers can easily change it to an MDI program. Although it does not seem necessary for the actual situation here.

6.3 Application of File control

The biggest feature of Delphi file management is the provision of a set of file manipulation controls. With these controls we can quickly develop a filename browsing system. The strong contrast between its powerful function and the lack of the required writing code is the embodiment of dephi vitality.

6.3.1 file controls and their interrelationships

The dedicated file control provided by Delphi is shown in the following table.

Table 6.4 Delphi Special File Control ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Control name Feature

─────────────────────────────────────

Drivecombobox Drive Combo list box. Used to select the current drive

FileListBox file list box. Used to display files in the current directory and select the current file

Filtercombobox File type combo list box. Use to select the type of display file

Directoryoutline Directory tree (6.4 section specifically)

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

The first four of the above controls are on the system page of the component Palette (part selection Board), directoryoutline in the Samples page of component Palette.

The above file control plus the file edit box, the table of Contents label box (in fact, the general edit box, the label box) can constitute a complete file operating system. The connection between them is almost without code support, as long as the corresponding properties can be set.

The properties of the Fileedit, Dirlabel, FileListBox, Filefiltercomlolist, Directorylistbox, and drivecombolist six controls are related as follows:

Drivecombolist. Dirlist: = Directorylistbox;

Directorylistbox.dirlabel: = Dirlabel;

Directorylistbox.filelist: = FileListBox;

Filefiltercombolist.filelist: = FileListBox;

Filelistbox.fileedit: = Fileedit;

The above contacts can be completed at design time. Just open the selection list box of the appropriate property to select it. You can also use the assignment statement above to establish a connection at run time.

The key attributes of a file control are basically reflected in the above contact. In addition, Filefiltercombolist has a filter property that is used to set the selection of the combo list box; FileListBox has a mask property that sets the type of display file. This allows FileListBox to display specific files as needed when separated from the Filefiltercombolist application. In section 6.4 We will apply this functionality.

The methods and events of the file control are basically inherited from the ListBox and ComboBox. But there is a Applyfilepath method in FileListBox that is useful, and we'll give it in the back.

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.