fmmain.pas

来自「这是不可多得的源代码」· PAS 代码 · 共 109 行

PAS
109
字号
unit fmMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  TFooObject = class(TObject)
  private
    aIntf : IInterface;
    A : array of Integer;
    iFileHandle: Integer;
  public
    Destructor Destroy;
    Constructor Create;
//    Destructor DTOR;
  end;

  PPTypeInfo = ^PTypeInfo;
  PTypeInfo = ^TTypeInfo;
  TTypeInfo = packed record
    Kind: Byte;
    Name: ShortString;
   {TypeData: TTypeData}
  end;

  TFieldInfo = packed record
    TypeInfo: PPTypeInfo;
    Offset: Cardinal;
  end;

  PFieldTable = ^TFieldTable;
  TFieldTable = packed record
    X: Word;
    Size: Cardinal;
    Count: Cardinal;
    Fields: array [0..0] of TFieldInfo;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  obj : TFooObject;
  InitTable: Pointer;
  FT: PFieldTable;
  aPtr : TClass;
begin
  obj := TFooObject.Create;
  try
    SetLength(obj.A, 1);
    obj.A[0] := 1;

    ShowMessage(obj.ClassName);
    ShowMessage(IntToStr(obj.A[0]));

//    aPtr := obj.ClassType;
//    InitTable := PPointer(Integer(aPtr^) + vmtInitTable)^;
//    FT := PFieldTable(Integer(InitTable) + Byte(PTypeInfo(InitTable).Name[0]));
//    ShowMessage(IntToStr(FT.Count));

  finally // wrap up
//    FreeAndNil(obj);
    obj.Free;
//    obj.DTOR;
  end;    // try/finally
end;

{ TFooObject }


destructor TFooObject.Destroy;
begin
  FileClose(iFileHandle);
  aIntf := nil;
  inherited;
end;


constructor TFooObject.Create;
begin
  iFileHandle := FileOpen('test.dat', fmCreate or fmOpenReadWrite);
end;

{
destructor TFooObject.DTOR;
begin
  FileClose(iFileHandle);
  inherited Destroy;
end;
}
end.

⌨️ 快捷键说明

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