"Mastering Delphi 6" learning notes six

zhaozj2021-02-11  189

"Mastering Delphi 6" learning notes six

The RTL in Delphi 6 has added a lot of functions and helper class, although it is not enough to turn over the earth, but it is indeed very convenient. If there is time, it is recommended to browse the new Strutils, Dateutils, and Convutils these units, I believe that some interesting things will be found.

If you want to get information about the operating system, you can:

Case Win32Platform of

VER_PLATFORM_WIN32_WINDOWS: SHOWMESSAGE ('Windows 9x');

Ver_Platform_WIN32_NT: ShowMessage ('Windows NT');

END;

ShowMessage ('Running On Windows:' INTOSTR (Win32majorversion) '.'

INTTOSTR (Win32minorVersion)

'(BUILD' INTTOSTR (Win32BuildNumber)

')' # 10 # 13 'Update:' Win32csdversion);

There is no reason to call GetVersion or getversionEx.

Sysutils in Delphi 6 adds several useful BOOL / STR Conversion functions, as follows:

Function StrtOBOOL (Const S: String): Boolean;

Function startef (const default: boolean): boolean;

Function trysTRTOBOOL (Const S: String; Out value: Boolean): Boolean

Function BoolTostr (B: Boolean; UseBoolSTRS: Boolean = FALSE): STRING;

Don't look help, you should also understand how these functions are used. One of the BoolTostr may be a relatively commonly used. If you do not specify a UseBoolSTRS parameter, the return will be B's ORD form, for example, BoolTostr (TRUE) will return '-1'. BoolTostr (True, true) returns 'true'. The return value depends on the value of the TrueBoolSTRS / FalseBoolSTRS / DefaultTrueBoolstr declared in the sysutils unit. Unfortunately, DefaultTrueBoolStr is constant, and cannot be changed in general methods. If you want to comply with Chinese habits, then you have this:

IF Length (TrueBoolstrs) <2 THEN Begin

SetLength (TrueBoolSTRS, 2);

TrueBoolSTRS [0]: = 'true';

TrueBoolSTRS [1]: = defaulttrueBoolstr;

END;

Str: = booltostr (True, True);

ShowMessage (STR);

Other new conversion functions, such as floattocurr, floattodatetime, trystrtofloat, trysTRTOCURR, etc. are also useful in some cases.

A new function: ifthen. It has four overload versions of Integer, INT64, Double and String, which can cope with general needs, such as: SEX: = ifthen (BMale, 'Men', 'Female');

This is more than if ... then ... End is simple, it is like C ? :.

There are also many enhanced functions on floating point operation. SameValue checks if the two variables are equal (or close to the point of difference). CompareValue's feature is also similar. Divmod can complete both Div and MOD operations in a function. Roundto completed its inlet, for example,

RoundTo (1234.567, 3); // Return 1000

RoundTo (1234.567, -2); // Return 1234.57

The DateTime function has some enhancements:

Function Dayof (Const Avalue: tdatetime): Word;

Function Hourof (Const Avalue: tdatetime): Word;

Function Weekofyear (Const Avalue: TdateTime): Integer;

Function Hourofweek (Const Avalue: TdateTime): Integer;

Function Secondofhour (Const Avalue: TDATETIME): Integer;

Function Daysbetween (Const Anow, Athen: TDATETIME): Integer;

Function WithNPastDays (const there, athen: tdatetime; const adays: integer): boolean

The following example shows some new string operations:

ShowMessage (DupeString ('Hello', 3)); // Return to Hellohellohello

ShowMessage (REVERSSTRING ('Hello')); // Return Olleh

Delphi currently provides support for multiplexes. E.g,

VAR

V1, V2: VARIANT;

Begin

V1: = varcomplexcreate (10, 12);

V2: = VARCOMPLEXCREATE (10, 1);

ShowMessage (V1 V2 5);

This example also reflects the method of providing the operator overload in Object Pascal. However, due to the high efficiency of Variant and difficulties, they are generally not recommended.

转载请注明原文地址:https://www.9cbs.com/read-3859.html

New Post(0)