`
wsql
  • 浏览: 11778566 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
文章分类
社区版块
存档分类
最新评论

delphi常用函数五

 
阅读更多

1、 CompareStr function

Compares two strings case sensitively.

Unit

SysUtils

Category

string handling routines

function CompareStr(const S1, S2: string): Integer;

Description

CompareStr compares S1 to S2, with case-sensitivity. The return value is less than 0 if S1 is less than S2, 0 if S1 equals S2, or greater than 0 if S1 is greater than S2. The compare operation is based on the 8-bit ordinal value of each character and is not affected by the current locale.

2、 TCustomListView.AlphaSort

Sorts the items in the list view.

function AlphaSort: Boolean;

Description

Call AlphaSort to sort the items in the manner maintained automatically when the SortType property is not stNone. If an OnCompare event handler is assigned, AlphaSort uses that event handler to define the sort order. Otherwise, AlphaSort sorts all list items alphabetically in ascending order. If successful, the method returns True.

3、 TCustomListView.OnCompare

Occurs to when two items need to be compared during a sort of the list.

type TLVCompareEvent = procedure(Sender: TObject; Item1, Item2: TListItem; Data: Integer; var Compare: Integer) of object;

property OnCompare: TLVCompareEvent;

Description

Write an OnCompare event handler to implement a sort order for the list. An OnCompare event handler is called when the SortType property is stData or stBoth, when the AlphaSort method is called, or when the CustomSort method is called without a SortProc parameter.

The OnCompare event handler compares the list items passed as the Item1 and Item2 parameters. If Item1 is the same as Item2 in the sort order, set the Compare parameter to 0. If Item1 is less than Item2, set the Compare parameter to a value less than 0. If Item1 is greater than Item2, set the Compare parameter to a value greater than 0. The Data parameter is 0 when the event handler is called to maintain the sort order of a list view with a SortType of stData or stBoth. Similarly, when OnCompare occurs in response to the AlphaSort method, the Data parameter is 0. When OnCompare occurs in response to the CustomSort method, the Data parameter is the value of the LParam parameter of CustomSort.

4、 TCustomDrawGrid.OnDrawCell

Occurs when a cell in the grid needs to be drawn.

type

TDrawCellEvent = procedure (Sender: TObject; ACol, ARow: Longint; Rect: TRect; State: TGridDrawState) of object;

property OnDrawCell: TDrawCellEvent;

Description

Write an OnDrawCell event handler to draw the contents of all the cells in the grid. Draw on the cell using the methods of the Canvas property. The Rect parameter indicates the location of the cell on the canvas. The Col and Row parameters indicate the column and row indexes of the cell that should be drawn. The State parameter indicates whether the cell has input focus, whether the cell is selected, and whether the cell is a fixed (nonscrolling) cell.

If the OnDrawCell event handler is not assigned, all cells in the draw grid will appear empty. If the DefaultDrawing property is True, the draw grid paints the background color of the cell before the OnDrawCell event, and draws a focus rectangle around the selected cell after the OnDrawCell event handler finishes drawing the contents of the cell. If the DefaultDrawing property is False, the OnDrawCell event handler should paint the background of the cell and provide all visual indication of selection and focus.

5、 TStringGrid

TStringGrid represents a grid control designed to simplify the handling of strings and associated objects.

Unit

QGrids

Description

Add a TStringGrid object to a form to present textual data in a tabular format. TStringGrid provides many properties to control the appearance of the grid, as well as events and methods that take advantage of the tabular organization of the grid in responding to user actions.

TStringGrid introduces the ability to associate an object with each string in the grid. These objects can encapsulate any information or behavior represented by the strings that are presented to the user.

If the strings to be presented in a grid represent field values from the records in a dataset, use TDBGrid instead.

6、 Variant types

Sometimes it is necessary to manipulate data whose type varies or cannot be determined at compile time. In these cases, one option is to use variables and parameters of type Variant, which represent values that can change type at runtime. Variants offer greater flexibility but consume more memory than regular variables, and operations on them are slower than on statically bound types. Moreover, illicit operations on variants often result in runtime errors, where similar mistakes with regular variables would have been caught at compile time. You can also create custom variant types.

By default, Variants can hold values of any type except records, sets, static arrays, files, classes, class references, and pointers. In other words, variants can hold anything but structured types and pointers. They can hold interfaces, whose methods and properties can be accessed through them. (See Object interfaces.) They can hold dynamic arrays, and they can hold a special kind of static array called a variant array. (See Variant arrays.) Variants can mix with other variants and with integer, real, string, and Boolean values in expressions and assignments; the compiler automatically performs type conversions.

Variants that contain strings cannot be indexed. That is, if V is a variant that holds a string value, the construction V[1] causes a runtime error.

You can define custom Variants that extend the Variant type to hold arbitrary values. For example, you can define a Variant string type that allows indexing or that holds a particular class reference, record type, or static array. Custom Variant types are defined by creating descendants to the TCustomVariantType class.

A variant occupies 16 bytes of memory and consists of a type code and a value, or pointer to a value, of the type specified by the code. All variants are initialized on creation to the special value Unassigned. The special value Null indicates unknown or missing data.

The standard function VarType returns a variant’s type code. The varTypeMask constant is a bit mask used to extract the code from VarType’s return value, so that, for example,

VarType(V) and varTypeMask = varDouble

returns True if V contains a Double or an array of Double. (The mask simply hides the first bit, which indicates whether the variant holds an array.) The TVarData record type defined in the System unit can be used to typecast variants and gain access to their internal representation. See the online Help on VarType for a list if codes, and note that new type codes may be added in future implementations of Object Pascal.

Variant type conversions

Variants in expressions

Variant arrays

Other variant types

7、 TDataSet.First

Moves to the first record in the dataset.

procedure First;

Description

Call First to make the first record in the dataset active. First posts any changes to the active record and:

Clears the record buffers.

Fetches the first record and makes it the active record.

Fetches any additional records required for display, such as those needed to fill out a grid control.

Sets the Bof property to True.

Broadcasts the record change so that data controls and linked detail sets can update.

Note: TDataSet uses internal, protected methods to reposition the active record and to fetch additional records required for display. In TDataSet, these internal methods are empty stubs. Descendant classes implement these methods to enable the First method to work.

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics