Note the TMySharedObjectClass can be replaced by TLogLogger or whatever you like. Please note the above is not thread-safe, and there may be better ways of reference-counting (such as using Interfaces), but this is a simple example which should get you started. GetMySharedObject : TMySharedObjectClass begin Destroy beginĭec ( FMySharedObjectRefCount ) if ( FMySharedObjectRefCount < 1 ) then Inc ( FMySharedObjectRefCount ) end destructor TM圜lass. Create begin if not Assigned ( FMySharedObject ) thenįMySharedObject := TMySharedObjectClass. pointer overload static class function CreateBlockWithProcedure(. They are allowed to apply one method to multiple classes and extend more than one class functionality and characteristics. They provide lots of inherited functions and features that can be added to provide unique features. Property MySharedObject : TMySharedObjectClass read GetMySharedObject end constructor TM圜lass. Dynamically calling a function from a shared library can only be accomplished in Go using cgo and, even then, the function pointer returned by dlsym can only be called via a C bridging function as calling C function pointers directly from Go is not currently supported. The example shows that a sub-class can extend the bicycle class that contains mountain bike, etc. (Edit: I re-read the question and moved reference count into TM圜lass - as you may not be able to edit the TMySharedObjectClass class you want to share, if it comes from someone else's library) TM圜lass = class ( TObject )įMySharedObject : TMySharedObjectClass varįOtherNonClassField1 : integer function GetMySharedObject : TMySharedObjectClass Ĭonstructor Create destructor Destroy override You need to end the block with "var" if you wish to include other fields after it (otherwise the block may be ended by a "private", "public", "procedure" etc specifier).
The keywords you are looking for are "class var" - this starts a block of class variables in your class declaration. Function MinValue(a, b : Integer) : Integer begin // Return the lowest of 2 numbers if a b then Result : a else Result : b end // Main line code procedure TForm1.