⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uacclasses.pas

📁 多数代码可以直接在Delphi6和Delphi7环境下运行。部分涉及.NET技术内容的代码
💻 PAS
字号:
unit uACClasses;

interface

uses SysUtils, uInterfaces, Windows;

type
  TAOImple = class(TAggregatedObject, IImplInterface)
    //IImplInterface
  private
    FUSDRate : Double;
    FRMBRate : Double;

    function GetUSDRate : Double; stdcall;
    function GetRMBRate : Double; stdcall;
    procedure SetUSDRate(const dRate : Double); stdcall;
    procedure SetRMBRate(const dRate : Double); stdcall;
  public
    function ConvertToUSD(const iNTD : Integer) : Double; stdcall;
    function ConvertToRMB(const iNTD : Integer) : Double; stdcall;
  end;

  TController = class(TObject, IInterface, IImplInterface)
  private
    aAOObj : TAOImple;
//    FImple : IImplInterface;
    FRefCount : Integer;
  protected
    { IInterface }
    function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
    function _AddRef: Integer; stdcall;
    function _Release: Integer; stdcall;
  public
    Constructor Create;
    Destructor Destroy; override;
    Property MyImpl : TAOImple read aAOObj implements IImplInterface;
  end;

implementation

uses fmMain2;

{ TController }

function TController._AddRef: Integer;
begin
  Result := InterlockedIncrement(FRefCount);
end;

function TController._Release: Integer;
begin
  Result := InterlockedDecrement(FRefCount);
//  if Result = 0 then
//    Destroy;
end;

constructor TController.Create;
begin
  aAOObj := TAOImple.Create(Self);
//  FImple := aAOObj;
  aAOObj.SetUSDRate(34.8);
  aAOObj.SetRMBRate(4.05);
end;

destructor TController.Destroy;
begin
//  if Assigned(aAOObj) then
//    FreeAndNil(aAOObj);
  Form1.AppMsg('TController Destroyed At : ' + DateTimeToStr(Now));
  inherited;
end;

function TController.QueryInterface(const IID: TGUID; out Obj): HResult;
begin
  if GetInterface(IID, Obj) then
    Result := 0
  else
    Result := E_NOINTERFACE;
end;

{ TAOImple }

function TAOImple.ConvertToRMB(const iNTD: Integer): Double;
begin
  Result := iNTD / FRMBRate;
end;

function TAOImple.ConvertToUSD(const iNTD: Integer): Double;
begin
  Result := iNTD / FUSDRate;
end;

function TAOImple.GetRMBRate: Double;
begin
  Result := FRMBRate;
end;

function TAOImple.GetUSDRate: Double;
begin
  Result := FUSDRate;
end;

procedure TAOImple.SetRMBRate(const dRate: Double);
begin
  FRMBRate := dRate;
end;

procedure TAOImple.SetUSDRate(const dRate: Double);
begin
  FUSDRate := dRate;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -