Difference between revisions of "TObject"
From Free Pascal wiki
Jump to navigationJump to search (Created page with "TObject is the base class for any other class, either you declare it or not. It provides only some very generic methods, mostly virtual. The rationale for TObject is that in O...") |
|||
(3 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
− | TObject is the base class for any other class, | + | {{TObject}} |
+ | |||
+ | '''<syntaxhighlight lang="pascal" inline>TObject</syntaxhighlight>''' is the base [[Class|<syntaxhighlight lang="pascal" inline>class</syntaxhighlight>]] for any other <syntaxhighlight lang="pascal" inline>class</syntaxhighlight>, whether you declare it or not. It provides only some very generic [[Method|methods]], mostly [[virtual|<syntaxhighlight lang="pascal" inline>virtual</syntaxhighlight>]]. The rationale for <syntaxhighlight lang="pascal" inline>TObject</syntaxhighlight> is that in [[Object Pascal]] every <syntaxhighlight lang="pascal" inline>class</syntaxhighlight> must be derived from another, <syntaxhighlight lang="pascal" inline>TObject</syntaxhighlight> being the exception that ends the derivation chain. | ||
+ | |||
+ | The [[Constructor|<syntaxhighlight lang="pascal" inline>constructor</syntaxhighlight>]] <syntaxhighlight lang="pascal" inline> TObject.Create()</syntaxhighlight>, inherited by every other <syntaxhighlight lang="pascal" inline>class</syntaxhighlight> by default, can be hidden declaring another <syntaxhighlight lang="pascal" inline>constructor</syntaxhighlight> with the same name in the derived <syntaxhighlight lang="pascal" inline>class</syntaxhighlight>, with or without parameters. This come handy implementing the [[Singleton pattern]]. | ||
+ | |||
+ | <syntaxhighlight lang="pascal"> | ||
+ | { Defined in objpash.inc } | ||
− | |||
− | |||
constructor Create; | constructor Create; | ||
destructor Destroy; virtual; | destructor Destroy; virtual; | ||
Line 48: | Line 53: | ||
function GetHashCode: PtrInt; virtual; | function GetHashCode: PtrInt; virtual; | ||
function ToString: ansistring; virtual; | function ToString: ansistring; virtual; | ||
− | <syntaxhighlight> | + | </syntaxhighlight> |
Latest revision as of 17:23, 13 November 2019
│
English (en) │
suomi (fi) │
TObject
is the base class
for any other class
, whether you declare it or not. It provides only some very generic methods, mostly virtual
. The rationale for TObject
is that in Object Pascal every class
must be derived from another, TObject
being the exception that ends the derivation chain.
The constructor
TObject.Create()
, inherited by every other class
by default, can be hidden declaring another constructor
with the same name in the derived class
, with or without parameters. This come handy implementing the Singleton pattern.
{ Defined in objpash.inc }
constructor Create;
destructor Destroy; virtual;
class function newinstance : tobject; virtual;
procedure CleanupInstance;
procedure FreeInstance; virtual;
function SafeCallException(exceptobject : tobject; exceptaddr : codepointer) : HResult; virtual;
procedure DefaultHandler(var message);virtual;
procedure Free;
class function InitInstance(instance : pointer) : tobject;
class function ClassType : tclass;
class function ClassInfo : pointer;
class function ClassName : shortstring;
class function ClassNameIs(const name : string) : boolean;
class function ClassParent : tclass;
class function InstanceSize : SizeInt;
class function InheritsFrom(aclass : tclass) : boolean;
class function StringMessageTable : pstringmessagetable;
class function MethodAddress(const name : shortstring) : codepointer;
class function MethodName(address : codepointer) : shortstring;
function FieldAddress(const name : shortstring) : pointer;
procedure AfterConstruction;virtual;
procedure BeforeDestruction;virtual;
procedure DefaultHandlerStr(var message);virtual;
procedure Dispatch(var message);virtual;
procedure DispatchStr(var message);virtual;
function GetInterface(const iid : tguid; out obj) : boolean;
function GetInterface(const iidstr : shortstring;out obj) : boolean;
function GetInterfaceByStr(const iidstr : shortstring; out obj) : boolean;
function GetInterfaceWeak(const iid : tguid; out obj) : boolean;
class function GetInterfaceEntry(const iid : tguid) : pinterfaceentry;
class function GetInterfaceEntryByStr(const iidstr : shortstring) : pinterfaceentry;
class function GetInterfaceTable : pinterfacetable;
class function UnitName : ansistring;
function Equals(Obj: TObject) : boolean; virtual;
function GetHashCode: PtrInt; virtual;
function ToString: ansistring; virtual;