Name
Is Keyword
Syntax
Object referenceisClass reference
Description
The is operator tests whether the type of an
object reference is the same as a given class reference or is a
descendant of that class. It returns True if the object has the same
type or is derived from the class type; it returns False
otherwise.
Tips and Tricks
To test the type of an interface, call
QueryInterfaceor theSupportsfunction in theSysUtilsunit.The
isoperator calls the object’sInheritsFrommethod.If you have tested an object’s type with the
isoperator, you do not need to use theasoperator. Use a plain type cast for better performance.The
isoperator requires an object reference as the left-hand operand. To test a class reference, call theInheritsFrommethod ofTObject.
Example
// Double-click any edit box to clear it. Set the OnDblClick handler
// for all edit boxes to this procedure.
procedure TForm1.EditDblClick(Sender: TObject);
begin
if Sender is TCustomEdit then
TCustomEdit(Sender).Clear;
end;See Also
| As Keyword, Class Type, TObject Type |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access