That's right. I prefer to use classes and records; I don't like procedural programming. In my humble opinion, using OOP the code is more readable and easier to understand. I don't know much about the performance.
By the way, I read a little about singletons and found this:
Code:
{ .: TSingleton :. }
TSingleton = class(TObject)
public
{ Public declarations }
class function NewInstance(): TObject; override;
procedure FreeInstance(); override;
class function RefCount(): Integer;
end;
(...)
var
Instance: TSingleton = nil;
Ref_Count: Integer = 0;
{ TSingleton }
procedure TSingleton.FreeInstance;
begin
Dec(Ref_Count);
if (Ref_Count = 0) then
begin
Instance := nil;
// Destroy private variables here
inherited FreeInstance();
end;
end;
class function TSingleton.NewInstance: TObject;
begin
if (not Assigned(Instance)) then
begin
Instance := inherited NewInstance();
// Initialize private variables here, like this:
// TSingleton(Result).Variable := Value;
end;
Result := Instance;
Inc(Ref_Count);
end;
class function TSingleton.RefCount: Integer;
begin
Result := Ref_Count;
end;
How do I use this for a texture manager? :?
Bookmarks