701F-96EC-4201-9266-57F982805B6E}'']
function Scroll(Info : pchar) : integer;
end;
TIBall = class(TObject)
public
constructor Create; virtual; abstract;
destructor Destroy; virtual; abstract;
function Play(info : pchar) : integer; virtual; abstract;
end;
TBallClass = class of TIBall;
implementation
end.
IncDemo.inc源文件:
type
TCar = class(TObject)
public
function Run(info: pchar): integer; virtual; {$IFNDEF INCTEST} abstract; {$ENDIF}
end;
ProDLLDemo.dpr源文件:
library ProDLLDemo;
uses
SysUtils, Classes,
UnitDLLDemo in ''UnitDLLDemo.pas'',
UnitIDest in ''UnitIDest.pas'';
{$R *.res}
function GetNewspaper : TNewspaper;
begin
result := TNewspaper.Create;
end;
function GetCircle : ICircle;
begin
result := TCircle.Create;
end;
function GetBall : TBallClass;
begin
result := TBall;
end;
function GetCar : TCar;
begin
result := TCar.Create;
end;
exports
GetNewspaper,
GetCircle,
GetBall,
GetCar;
end.
UnitDLLDemo.pas源代码:
unit UnitDLLDemo;
{$DEFINE INCTEST}
interface
uses Sysutils, UnitIDest;
{$I IncDemo.inc}
{ ----- 利用纯虚和抽象类实现 ----- }
type
TPaper = class(TObject)
end;
TNewspaper = class(TPaper)
public
constructor Create;
destructor Destroy;
function Read(info: pchar): integer; virtual;
end;
{ ----- 利用接口实现 ----- }
type
TShape = class(TInterfacedObject)
end;
TCircle = class(TShape, ICircle)
public
constructor Create;
destructor Destroy;
function Scroll(info: pchar): integer;
end;
{ ----- 利用类引用实现 ----- }
type
TBall = class(TIBall)
public
constructor Create;override;
destructor Destroy;override;
function Play(info : pchar) : integer; override;
end;
implementation
{ TNewspaper }
constructor TNewspaper.Create;
begin
inherited Create;
end;
destructor TNewspaper.Destroy;
begin
inherited;
end;
function TNewspaper.Read(info: pchar): integer;
var
str: string;
begin
if info <> nil then
begin
str := self.ClassName;
strCopy(info, PChar(str));
end;
result := 1;
end;
{ TCircle }
constructor TCircle.Create;
begin
inherited Create;
end;
destructor TCircle.Destroy;
begin
inherited;
end;
function TCircle.Scroll(info: pchar): integer;
var
str: string;
begin
if info <> nil then
begin
str := self.ClassName;
strCopy(info, PChar(str));
end;
result := 2;
end;
{ TBall }
constructor TBall.Create;
begin
// inherited Create;
end;
destructor TBall.Destroy;
begin
// inherited;
end;
function TBall.Play(info: pchar): integer;
var
str: string;
begin
if info <> nil then
begin