🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #10431

Re: Counting number of instances of a class imported from a DLL

#10431
From: Constantine Yannakopoulos
Date: Thu, 08 Apr 2004 09:28
61 lines
2593 bytes
Author := "NICs";

| Assume that we have a class TMyObject which will be exported from a
| DLL in Windows or a dynamic object in Linux.
| [A] How to define a DLL and its equivalent in Linux to export a class
| ? (Can somone give us a skeleton code)
| [B] How to create multiple instances of the imported the class from a
| DLL?  (Can somone give us a skeleton code)

Why can't you use a runtime package? After all r/t packages *are*
dll's/so's.

| [C] How to count number of instances of a class imported from a DLL?
| (Note that DLL (and its equivalent in Linux ) can be used by more
| than one application in the same time)

The class must provide this functionality. Define a global variable
InstanceCount in the unit where the class is implemented and then
override the methods AfterConstruction and BeforeDestruction of your
class to InterlockedIncrement and InterlockedDecrement it respectively.
Then add a class method to your class that returns the value of the
global variable.

interface

type
  TMyClass = class
  ...
  public
    procedure AfterConstruction; override;
    procedure BeforeDestruction; override;
    class function GetInstanceCount: Integer;
  end;

implementation

var
  InstanceCount: Integer = 0;

procedure TMyClass.AfterConstruction;
begin
  inherited; 
  InterlockedIncrement(InstanceCount);
end;

procedure TMyClass.BeforeDestruction;
begin
  inherited; 
  InterlockedDecrement(InstanceCount);
end;


class function TMyClass.GetInstanceCount: Integer;
begin
  Result := InstanceCount;
end;

HTH

-- 
Constantine
Technical Details
Message-ID: <40750d2b@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <407427ee$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fb250,5239208c54b6ae87
X-Google-Attributes: gidfb250,public
X-Google-Thread: 10cc67,5239208c54b6ae87
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2004-04-08 01:39:29 PST
From: "Constantine Yannakopoulos" <kyan@deltasingular.remove.this.gr>
Subject: Re: Counting number of instances of a class imported from a DLL
Newsgroups: borland.public.cppbuilder.nativeapi,borland.public.kylix.linuxapi
References:  <407427ee$1@newsgroups.borland.com>
User-Agent: XanaNews/1.16.2.2
NNTP-Posting-Host: 62.1.187.233
Message-ID: <40750d2b@newsgroups.borland.com>
Date: 8 Apr 2004 01:28:27 -0800
X-Trace: newsgroups.borland.com 1081412907 62.1.187.233 (8 Apr 2004 01:28:27 -0800)
Lines: 61
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail