intfunit.pas
来自「《Delphi COM深入编程》原书光盘」· PAS 代码 · 共 84 行
PAS
84 行
unit IntfUnit;
interface
uses
Classes, SysUtils, Dialogs;
type
IFormattedNumber = interface
['{2DE825C1-EADF-11D2-B39F-0040F67455FE}']
function FormattedString: string;
function GetName: string;
end;
TFormattedInteger = class(TInterfacedObject, IFormattedNumber)
private
FValue: Integer;
public
constructor Create(AValue: Integer);
destructor Destroy; override;
function FormattedString: string;
function GetName: string;
end;
TFormattedHexInteger = class(TFormattedInteger, IFormattedNumber)
public
destructor Destroy; override;
function FormattedString: string;
function GetName: string;
end;
implementation
uses
MainForm;
{ TFormattedInteger }
constructor TFormattedInteger.Create(AValue: Integer);
begin
inherited Create;
FValue := AValue;
end;
destructor TFormattedInteger.Destroy;
begin
Form1.Memo1.Lines.Add('TFormattedInteger.Destroy');
inherited Destroy;
end;
function TFormattedInteger.FormattedString: string;
begin
Result := 'The integer is ' + IntToStr(FValue);
end;
function TFormattedInteger.GetName: string;
begin
Result := 'TFormattedInteger.GetName';
end;
{ TFormattedHexInteger }
destructor TFormattedHexInteger.Destroy;
begin
Form1.Memo1.Lines.Add('TFormattedHexInteger.Destroy');
inherited Destroy;
end;
function TFormattedHexInteger.FormattedString: string;
begin
Result := 'The hex integer is $' + IntToHex(FValue, 4);
end;
function TFormattedHexInteger.GetName: string;
begin
Result := 'TFormattedHexInteger.GetName';
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?