TByteHelper
TShortIntHelper
TSmallIntHelper
TWordHelper
TCardinalHelper
TIntegerHelper
TInt64Helper
TUInt64Helper
TNativeIntHelper
TNativeUIntHelper
// 它們定義在 System.SysUtils, 功能基本一樣, 常用的有:
var
I: Integer;
S: string;
begin
I := I.MaxValue; // 2147483647
I := I.MinValue; // -2147483648
I := I.Size; // 4
I := I.Parse('123'); // 123
I := 255;
S := I.ToString(); // '255'
S := I.ToHexString; // FF
S := I.ToHexString(4); // 00FF
end;
TBooleanHelper
TByteBoolHelper
TWordBoolHelper
TLongBoolHelper
// 它們定義在 System.SysUtils, 基本無用.
TSingleHelper
TDoubleHelper
TExtendedHelper
// 它們定義在 System.SysUtils, 功能基本一樣, 常用的有:
var
F: Double;
S: string;
begin
F := F.MaxValue; // 1.7976931348623157081e+308
F := F.MinValue; // -1.7976931348623157081e+308
F := F.Size; // 8
F := F.Parse('3.14'); // 3.14
F := Pi * 100;
s := F.ToString(); // 314.159265358979
S := F.ToString(ffExponent, 6, 3); // 3.14159E+002
S := F.ToString(ffFixed, MaxInt, 2); // 314.16; 保留兩位小數點; 同 S := Format('%.2f', [F]);
S := F.ToString(ffCurrency, MaxInt, 4); // ¥314.1593
end;
TCharHelper
// 它們定義在 System.Character, 它可以徹底替代同單元的 TCharacter 結構體. 主要方法有:
function IsControl: Boolean;
function IsDigit: Boolean;
function IsHighSurrogate: Boolean;
function IsInArray(const SomeChars: array of Char): Boolean;
function IsLetter: Boolean;
function IsLetterOrDigit: Boolean;
function IsLower: Boolean;
function IsLowSurrogate: Boolean;
function IsNumber: Boolean;
function IsPunctuation: Boolean;
function IsSeparator: Boolean;
function IsSurrogate: Boolean;
function IsSymbol: Boolean;
function IsUpper: Boolean;
function IsWhiteSpace: Boolean;
function ToLower: Char;
function ToUpper: Char;
function ToUCS4Char: UCS4Char;
// 以后可以不用 CharInSet()了, 不過得引用 System.Character 單元
uses System.Character;
procedure TForm1.FormCreate(Sender: TObject);
begin
KeyPreview := True;
end;
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
if Key.IsInArray(['1', '2', '3', '4', '5', '6', '7', '9', '0']) then
ShowMessage('按下了數字鍵');
if Key.IsNumber then
ShowMessage('真的按下了數字鍵');
end;
System.SysUtils 還給了一個 TGuidHelper
var G: TGUID; S: string; bs: TBytes; begin G := G.NewGuid; S := G.ToString; bs := G.ToByteArray; end; // XE4 中還看到幾個 Helper, 如: TCriticalSectionHelper TConditionVariableHelper CFGregorianDateHelper TD2DMatrix3x2FHelper TDSSessionHelper TCanvasHelper TStyleManagerHelper TBitmapHelper TContextHelper TElementMarginsHelper TThemeServicesClassHelper // 這都不常用了, 不過這東西確實方便批量地擴展功能, 這或許會成為寫代碼的一種基本手法, 譬如: // System.Rtti 單元中的 TListHelper, TArrayHelper 和 System.Classes 單元中的 TUInt32Helper
