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

📄 invunit.pas

📁 详细讲述如何用delphi进行com编程
💻 PAS
字号:
unit InvUnit;

interface

uses
  SysUtils, IntfUnit;

type
  TInventoryItemOrder = (iioPartNumber, iioDescription,
    iioUnitPrice, iioInStock);

  IInventoryItem = interface
    ['{FFCD24F1-4FE8-11D3-B84D-0040F67455FE}']
    function GetPartNumber: string;
    function GetDescription: string;
    function GetInStock: Integer;
    function GetUnitPrice: Double;
  end;

  TInventoryItem = class(TInterfacedObject, IInventoryItem, ICompare)
  private
    FPartNumber: string;
    FDescription: string;
    FInStock: Integer;
    FUnitPrice: Double;
  public
    constructor Create(APartNumber: string; ADescription: string;
      AInStock: Integer; AUnitPrice: Double);
    function CompareWith(ACompare: ICompare; ASortBy: Integer): Integer;
    function GetPartNumber: string;
    function GetDescription: string;
    function GetInStock: Integer;
    function GetUnitPrice: Double;
  end;

implementation

{ TInventoryItem }

function TInventoryItem.CompareWith(ACompare: ICompare;
  ASortBy: Integer): Integer;
var
  Inv: IInventoryItem;
begin
  Result := 0;

  Inv := ACompare as IInventoryItem;

  case ASortBy of
    Ord(iioPartNumber):
      Result := CompareStr(FPartNumber, Inv.GetPartNumber);

    Ord(iioDescription):
      Result := CompareStr(FDescription, Inv.GetDescription);

    Ord(iioInStock):
      Result := FInStock - Inv.GetInStock;

    Ord(iioUnitPrice):
      if FUnitPrice < Inv.GetUnitPrice then
        Result := -1
      else if FUnitPrice > Inv.GetUnitPrice then
        Result := 1
      else
        Result := 0;
  end;
end;

constructor TInventoryItem.Create(APartNumber, ADescription: string;
  AInStock: Integer; AUnitPrice: Double);
begin
  inherited Create;

  FPartNumber := APartNumber;
  FDescription := ADescription;
  FInStock := AInStock;
  FUnitPrice := AUnitPrice;
end;

function TInventoryItem.GetDescription: string;
begin
  Result := FDescription;
end;

function TInventoryItem.GetInStock: Integer;
begin
  Result := FInStock;
end;

function TInventoryItem.GetPartNumber: string;
begin
  Result := FPartNumber;
end;

function TInventoryItem.GetUnitPrice: Double;
begin
  Result := FUnitPrice;
end;

end.

⌨️ 快捷键说明

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