unit fmObjDemoMain;

interface

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

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    { Private declarations }
    aButton : TButton;
  public
    { Public declarations }
    procedure AppMsg(const sMessage : String);
  end;
  TgMethod = function : String of object;

var
  Form1: TForm1;

implementation

uses uObjClasses;

{$R *.dfm}

procedure TForm1.AppMsg(const sMessage: String);
begin
  Memo1.Lines.Add(sMessage);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  aBObj : TBase;
  aD1Obj : TDerived1;
  agObj : TBase;
  aObj : TObject;
  iObj : ITest;
  itt : PInterfaceTable;
  ie : TInterfaceEntry;
  iCount : Integer;
  mp : Pointer;
  ig : TGUID;
  gm : TgMethod;
begin

{
  try
    aBObj := TBase.Create;
    AppMsg('aBObj getName : ' + aBObj.getName);
    AppMsg('aBObj getStaticName : ' + aBObj.getStaticName);
    AppMsg('aBObj getObjSize : ' + IntToStr(aBObj.GetObjSize));
    AppMsg('aBObj getObjSize : ' + IntToStr(aBObj.getRC));
  finally
    aBObj.Free;
  end;
}


  try
//    aObj := TObject(TBase.NewInstance);
//    aBObj := TBase(aObj);
    aBObj := TBase(TBase.NewInstance);
//    aBObj := TBase(aObj.Create);
    AppMsg('aBObj getName : ' + aBObj.getName);
    AppMsg('aBObj getStaticName : ' + aBObj.getStaticName);
    AppMsg('aBObj getObjSize : ' + IntToStr(aBObj.GetObjSize));
    AppMsg('aBObj getRC : ' + IntToStr(aBObj.getRC));
  finally
    FreeAndNil(aBObj);
  end;


{
  try
    aD1Obj := TDerived1.Create;
    AppMsg('aBObj getName : ' + aD1Obj.getName);
    AppMsg('aBObj getStaticName : ' + aD1Obj.getStaticName);
    AppMsg('aBObj getObjSize : ' + IntToStr(aD1Obj.GetObjSize));
    AppMsg('aBObj getRC : ' + IntToStr(aD1Obj.getRC));

    iObj := aD1Obj;
    AppMsg('iObj getObjSize : ' + IntToStr(iObj.GetObjSize));
    AppMsg('iObj getRC : ' + IntToStr(aD1Obj.getRC));
    iObj := nil;
    AppMsg('iObj getRC : ' + IntToStr(aD1Obj.getRC));
  finally
    aD1Obj.Free;
  end;
}

{
  try
    agObj := TDerived1.Create;
    AppMsg('aBObj getName : ' + agObj.getName);
    AppMsg('aBObj getStaticName : ' + agObj.getStaticName);
    AppMsg('aBObj getObjSize : ' + IntToStr(agObj.GetObjSize));
    AppMsg('aBObj getRC : ' + IntToStr(agObj.getRC));


    AppMsg('iObj GetObjSize : ' + IntToStr(iObj.GetObjSize));
    AppMsg('iObj GetInterfaceName : ' + iObj.GetInterfaceName);
    AppMsg('iObj getRC : ' + IntToStr(agObj.getRC));
    iObj := nil;
    AppMsg('iObj getRC : ' + IntToStr(agObj.getRC));


  finally
    aD1Obj.Free;
  end;
}

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  if (Self.InheritsFrom(TObject) ) then
    Edit1.Text := 'True';
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  Application.CreateForm(TButton, aButton);
  aButton.Parent := Self;
  aButton.Caption := 'CreateForm';
  aButton.Show;
end;

procedure TForm1.Button4Click(Sender: TObject);
var
  aClass : TClass;
begin
  aClass := Pointer(Self);
  aClass := aClass.ClassParent;
  Memo1.Lines.Add(aClass.ClassName);
end;

end.
