delphi常用函数三

来源:互联网 发布:苹果有淘宝卖家版吗 编辑:程序博客网 时间:2024/05/24 07:22

TList

TList stores an array of pointers.

Unit

Classes

Description

TList, which stores an array of pointers, is often used to maintain lists of objects. TList introduces properties and methods to

Add or delete the objects in the list.

Rearrange the objects in the list.

Locate and access objects in the list.

Sort the objects in the list.

TStringList

TStringList maintains a list of strings.

Unit

Classes

Description

Use a string list object to store and manipulate a list of strings. TStringList implements the abstract properties and methods introduced by TStrings, and introduces new properties, events, and methods to

Sort the strings in the list.

         Prohibit duplicate strings in sorted lists.

         Respond to changes in the contents of the list.

         Control whether strings are located, sorted, and identified as duplicates in a case-sensitive or case-insensitive manner.

Calling conventions

When you declare a procedure or function, you can specify a calling convention using one of the directives register, pascal, cdecl, stdcall, and safecall. For example,

function MyFunction(X, Y: Real): Real; cdecl;

 ...

Calling conventions determine the order in which parameters are passed to the routine. They also affect the removal of parameters from the stack, the use of registers for passing parameters, and error and exception handling. The default calling convention is register.

 

The register and pascal conventions pass parameters from left to right; that is, the leftmost parameter is evaluated and passed first and the rightmost parameter is evaluated and passed last. The cdecl, stdcall, and safecall conventions pass parameters from right to left.

         For all conventions except cdecl, the procedure or function removes parameters from the stack upon returning. With the cdecl convention, the caller removes parameters from the stack when the call returns.

 

The register convention uses up to three CPU registers to pass parameters, while the other conventions pass all parameters on the stack.

The safecall convention implements exception  “firewalls.”  On Windows, this implements interprocess COM error notification.

 

The table below summarizes calling conventions.

Directive  Parameter order      Clean-up  Passes parameters in registers?

register    Left-to-right         Routine                                    Yes

pascal       Left-to-right              Routine                             No

cdecl         Right-to-left              Caller                                             No

stdcall      Right-to-left              Routine                                         No

safecall    Right-to-left              Routine                                         No

The default register convention is the most efficient, since it usually avoids creation of a stack frame. (Access methods for published properties must use register.) The cdecl convention is useful when you call functions from shared libraries written in C or C++, while stdcall and safecall are recommended, in general, for calls to external code. On Windows, the operating system APIs are stdcall and safecall. Other operating systems generally use cdecl. (Note that stdcall is more efficient than cdecl.)

The safecall convention must be used for declaring dual-interface methods. The pascal convention is maintained for backward compatibility. For more information on calling conventions, see Program control.

The directives near, far, and export refer to calling conventions in 16-bit Windows programming. They have no effect in 32-bit applications and are maintained for backward compatibility only.

Character pointers

The fundamental types PAnsiChar and PWideChar represent pointers to AnsiChar and WideChar values, respectively. The generic PChar represents a pointer to a Char (that is, in its current implementation, to an AnsiChar). These character pointers are used to manipulate null-terminated strings. (See Working with null-terminated strings.)

TResourceStream

TResourceStream is a memory stream that provides access to the compiled resources in aWindows application.

Unit

Classes

Description

Use TResourceStream to read the resources of aWindows application. An instance of TResourceStream holds the value of a single resource in a memory buffer where it is accessible to the application.

The global ReadComponentRes function uses TResourceStream to access the compiled resources used by the application.

MkDir procedure

Creates a new subdirectory.

Unit

System

Category

I/O routines

procedure MkDir(const S: string); overload;

procedure MkDir(P: PChar); overload;

Description

MkDir creates a new subdirectory with the path specified by string S or P. The last item in the path cannot be an existing file name.

Note:        {$I+} handles run-time errors using exceptions. When using {$I-}, use IOResult to check for an I/O error.

Example

uses Dialogs;

begin

  {$I-}

  { Get directory name from TEdit control }

  MkDir(Edit1.Text);

  if IOResult <> 0 then

    MessageDlg('Cannot create directory', mtWarning, [mbOk], 0)

  else

    MessageDlg('New directory created', mtInformation, [mbOk], 0);

end;

TSysCharSet type

Represents a set of characters that are used as separators when parsing a string.

Unit

SysUtils

type TSysCharSet = set of Char;

Description

TSysCharSet is a set containing special characters that can be used to parse a string. The elements of the set vary, depending on the type of parsing performed.

原创粉丝点击