home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 April / Chip_1997-04_cd.bin / prezent / cb / data.z / VIRTINTF.PAS < prev    next >
Pascal/Delphi Source File  |  1997-01-16  |  2KB  |  82 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Delphi Visual Component Library                 }
  5. {                                                       }
  6. {       Copyright (c) 1995,1996 Borland International   }
  7. {                                                       }
  8. {*******************************************************}
  9.  
  10. unit VirtIntf;
  11.  
  12. interface
  13.  
  14. type
  15.   TInterface = class
  16.   private
  17.     FRefCount: Longint;
  18.   public
  19.     constructor Create;
  20.     procedure Free;
  21.     function AddRef: Longint; virtual; stdcall;
  22.     function Release: Longint; virtual; stdcall;
  23.     function GetVersion: Integer; virtual; stdcall;
  24.   end;
  25.  
  26.   { TIStream - This provides a pure virtual interface to a physical stream }
  27.  
  28.   TIStream = class(TInterface)
  29.   public
  30.     function Read(var Buffer; Count: Longint): Longint; virtual; stdcall; abstract;
  31.     function Write(const Buffer; Count: Longint): Longint; virtual; stdcall; abstract;
  32.     function Seek(Offset: Longint; Origin: Word): Longint; virtual; stdcall; abstract;
  33.     function GetModifyTime: Longint; virtual; stdcall; abstract;
  34.     procedure SetModifyTime(Time: Longint); virtual; stdcall; abstract;
  35.   end;
  36.  
  37. function ReleaseException: string;
  38.  
  39. implementation
  40.  
  41. uses SysUtils;
  42.  
  43. { TInterface }
  44.  
  45. constructor TInterface.Create;
  46. begin
  47.   inherited Create;
  48.   FRefCount := 1;
  49. end;
  50.  
  51. procedure TInterface.Free;
  52. begin
  53.   if Self <> nil then Release;
  54. end;
  55.  
  56. function TInterface.AddRef: Longint;
  57. begin
  58.   Inc(FRefCount);
  59.   Result := FRefCount;
  60. end;
  61.  
  62. function TInterface.Release: Longint;
  63. begin
  64.   Dec(FRefCount);
  65.   Result := FRefCount;
  66.   if FRefCount = 0 then Destroy;
  67. end;
  68.  
  69. function TInterface.GetVersion: Integer;
  70. begin
  71.   Result := 2;
  72. end;
  73.  
  74. { Exception handling }
  75.  
  76. function ReleaseException: string;
  77. begin
  78.   Result := Exception(ExceptObject).Message;
  79. end;
  80.  
  81. end.
  82.