Intrinsic methods
Besides the many functions of TVariant, there is also a class helper (or type helper) registered for variants. This provides some simple but handy functions that helps you determine what a variant contains quickly.
The variant type helper is defined in qtx.sysutils.pas, and looks like this:
TVariantHelper = helper for variant
function Valid: boolean;
function Defined: boolean;
function UnDefined: boolean;
function Equals(Reference: variant):Boolean;
function IsObject: boolean;
function IsArray: boolean;
function IsInteger: boolean;
function Isfloat: boolean;
function IsBoolean: boolean;
function IsString: boolean;
function IsSymbol: boolean;
function IsFunction: boolean;
function IsUInt8Array: boolean;
function DataType: TVariantExportType;
end;
The above helper means that you can call all the methods on any variant, which is really helpful when dealing with external JavaScript libraries:
// Create a HTML DIV element
var FHandle: THandle;
FHandle := TQTXBrowser.CreateElement("div");
// Check if the reference is valid
if FHandle.Valid then
begin
// Manually set the bounds on the DIV element
FHandle.style["left"] := TInt32.ToPxStr(10);
FHandle.style["top"] := TInt32.ToPxStr(10);
FHandle.style["width"] := TInt32.ToPxStr(100);
FHandle.style["height"] := TInt32.ToPxStr(100);
end;