Returns a substring of a string or a segment of a dynamic array.
Unit
System
Category
string handling routines
function Copy(S; Index, Count: Integer): string;
function Copy(S; Index, Count: Integer): array;
Description
S is an expression of a string or dynamic-array type. Index and Count are integer-type expressions. Copy returns a substring or sub array containing Count characters or elements starting at S[Index].
If Index is larger than the length of S, Copy returns an empty string or array.
If Count specifies more characters or array elements than are available, only the characters or elements from S[Index] to the end of S are returned.
Note: When S is a dynamic array, Copy can only be used as a parameter in a call to a procedure or function that expects an array parameter. That is, it acts like the Slice function when working with dynamic arrays.
The lower twelve bits of a Variant type code (the bits defined by the varTypeMask bit mask) define the type of the Variant. The varArray bit is set if the Variant is an array of the given type. The varByRef bit is set if the Variant is a reference to a value of the given type as opposed to an actual value.
The following table describes the meaning of each of the Variant type codes.
VarType Contents of Variant
varEmpty The Variant is Unassigned.
varNull The Variant is Null.
varSmallint 16-bit signed integer (type Smallint).
varInteger 32-bit signed integer (type Integer).
varSingle Single-precision floating-point value (type Single).
varDouble Double-precision floating-point value (type Double).
varCurrency Currency floating-point value (type Currency).
varDate Date and time value (type TDateTime).
varOleStr Reference to a dynamically allocated UNICODE string.
varDispatch Reference to an Automation object (an IDispatch interface pointer).
varError Operating system error code.
varBoolean 16-bit boolean (type WordBool).
varVariant A Variant.
varUnknown Reference to an unknown OLE object (an IUnknown interface pointer).
varByte A Byte
varStrArg COM-compatible string.
varString Reference to a dynamically allocated string. (not COM compatible)
varAny A CORBA Any value.
The value returned by VarType corresponds to the VType field of a TVarData record.
The type of a Variant can be changed using VarAsType or VarCast.
The lower twelve bits of a Variant type code (the bits defined by the varTypeMask bit mask) define the type of the Variant. The varArray bit is set if the Variant is an array of the given type. The varByRef bit is set if the Variant is a reference to a value of the given type as opposed to an actual value.
The following table describes the meaning of each of the Variant type codes.
VarType Contents of Variant
varEmpty The Variant is Unassigned.
varNull The Variant is Null.
varSmallint 16-bit signed integer (type Smallint).
varInteger 32-bit signed integer (type Integer).
varSingle Single-precision floating-point value (type Single).
varDouble Double-precision floating-point value (type Double).
varCurrency Currency floating-point value (type Currency).
varDate Date and time value (type TDateTime).
varOleStr Reference to a dynamically allocated UNICODE string.
varDispatch Reference to an Automation object (an IDispatch interface pointer).
varError Operating system error code.
varBoolean 16-bit boolean (type WordBool).
varVariant A Variant.
varUnknown Reference to an unknown OLE object (an IUnknown interface pointer).
varByte A Byte
varStrArg COM-compatible string.
varString Reference to a dynamically allocated string. (not COM compatible)
varAny A CORBA Any value.
The value returned by VarType corresponds to the VType field of a TVarData record.
The type of a Variant can be changed using VarAsType or VarCast.
1.根本就不应该存在这样的问题,如果需要限制输入格式你应该使用MaskEdit.
设置mask:= '!99/99/00;1;_';如果需要设置长日期格式则设置mask:= '!99/99/00 90:00:00;1;_'.
2.如果需要按分隔符获取字串请使用这个函数
Function tuGetBlock(SourceString:String; Spearate:String; iPos:integer):String;
var
tmpStr:String;
i:integer;
begin
TmpStr:= SourceString;
for i:=0 to iPos-1 do
begin
if pos(Spearate,TmpStr)<>0 then
begin
Result:= Copy(TmpStr,1,pos(Spearate,tmpStr)-length(Spearate));
TmpStr:= Copy(TmpStr,pos(Spearate,tmpStr)+length(Spearate),length(TmpStr)-pos(Spearate, tmpStr));
end else begin
if i = iPos-1 then Result:= TmpStr else Result:= '';
break;
end;
end;
end;
例如: iMonth = StrToInt(tuGetblock('2000/09/04','/',2));
这个函数似乎可以再优化一下,希望那位大虾指点.