在 FormCreate 事件中加入
procedure TForm1.FormCreate(Sender: TObject);
var
v: Variant;
t: TVarType;
I: integer;
begin
with Memo1.Lines do
begin
Clear;
t := VarType(v); // 取得 Variant Type
if t = varEmpty then begin
Add('Empty Type'); // 初始為 Empty Type
end;
if VarIsEmpty(v) then begin
Add('Is Empty'); // 初始值為 Empty
end;
if VarIsClear(v) then begin
Add('Is Clear'); // Clear
end;
v := VarArrayCreate([0, 3], varVariant); // 建立陣列 array[0..3] of Variant
v[0] := 'Hello World';
v[1] := 1234.56;
v[2] := Now;
v[3] := Null; // 設為 Null
if VarIsArray(v) then begin
Add('Is Array, Length: ' +
IntToStr(VarArrayHighBound(v, 1) - VarArrayLowBound(v, 1)));
end;
for i := VarArrayLowBound(v, 1) to VarArrayHighBound(v, 1) do
begin
Add(Format('v[%d]: %s',[i, QuotedStr(VarToStr(v[i]))])); // 轉成字串
end;
if VarIsStr(v[0]) then begin
Add('v[0] Is String');
end;
if VarIsFloat(v[1]) then begin
Add('v[1] Is Float');
end;
if VarIsType(v[2], varDate) then begin
Add('v[2] Is Date');
end;
if VarIsNull(v[3]) then begin
Add('v[3] Is Null');
end;
VarClear(v); // 清為 Empty
if VarIsClear(v) and VarIsEmpty(v) then begin
Add('Is Clear and Empty'); // Clear
end;
end;
end;
沒有留言:
張貼留言