1.基本數據類型
1)Delphi自帶了一些對基本類型的操作函數,如Ord ,Pred,Succ ,High,Low
2)枚舉類型
聲明 type Suit = (Club, Diamond, Heart, Spade);//where Ord(Club) returns 0, Ord(Diamond) returns 1...
如果枚舉類型的名稱和類型名重復的使用方法:
type TSound = (Click, Clack, Clock)
procedure TForm1.DBGridEnter(Sender: TObject);
var Thing: TSound;
begin
...
Thing := MyUnit.Click;
end;
指定枚舉類型的值
//例1
type Size = (Small = 5, Medium = 10, Large = Small + Medium);
var X: Size;
X := Small; // Ord(X) = 5
Y := Size(6); // Ord(X) = 6
Inc(X); // Ord(X) = 7
//例2
type SomeEnum = (e1, e2, e3 = 1);//Ord(e1) returns 0, Ord(e2) returns 1, and Ord(e3) also returns 1;
3)區間類型(Subrange Types)
聲明方式
type
SomeNumbers = -128..127;
Caps = 'A'..'Z';
2.字符串和字符
字符串轉換成大寫
var I: Integer;
begin
I := Length(MyString);
while I > 0 do
begin
MyString[I] := AnsiUpperCase(MyString[I]);
I := I - 1;
end;
end;
字符串賦值
MyString := 'Hello world!';
MyString := 'Hello' + 'world';
MyString := MyString + '!';
MyString := ' '; { space }
MyString := ''; { empty string }
Short Strings的范圍 0到255
使用指針
const TempString: array[0..12] of Char = 'Hello world!';
var P: PChar;
...
P := @TempString[0];