张
张无忌
Unregistered / Unconfirmed
GUEST, unregistred user!
TBaseEvent = procedure of object;
TBase = class
private
protected
public
procedure ShowMessage
virtual;
constructor Create;
destructor Destroy
override;
end;
TClassA = class(TBase)
private
protected
public
procedure ShowMessage
override;
procedure Show
virtual;
procedure AfterConstruction
override;
constructor Create;
destructor Destroy
override;
end;
TClassB = class(TBase)
private
protected
public
procedure ShowMessage
override;
procedure Show
virtual;
constructor Create;
destructor Destroy
override;
end;
{ TBase }
constructor TBase.Create;
begin
Form1.ListBox1.Items.add('Base Create...');
end;
destructor TBase.Destroy;
begin
Form1.ListBox1.Items.add('Base Destroy...');
inherited Destroy;
end;
procedure TBase.ShowMessage;
begin
beep();
end;
{ TClassB }
constructor TClassB.Create;
begin
Form1.ListBox1.Items.add('TClassB Create...');
end;
destructor TClassB.Destroy;
begin
Form1.ListBox1.Items.add('TClassB Destroy...');
inherited Destroy;
end;
procedure TClassB.Show;
begin
beep();
end;
procedure TClassB.ShowMessage;
begin
beep();
end;
{ TClassA }
procedure TClassA.AfterConstruction;
begin
inherited;
end;
constructor TClassA.Create;
begin
Form1.ListBox1.Items.add('TClassA Create...');
inherited Create;
end;
destructor TClassA.Destroy;
begin
Form1.ListBox1.Items.add('TClassA Destroy...');
inherited Destroy;
end;
procedure TClassA.Show;
begin
beep();
end;
procedure TClassA.ShowMessage;
begin
beep();
inherited Destroy;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
a: TClassA;
Func: TBaseEvent;
FuncD, FuncE: integer;
begin
a := TClassA.Create;
try
Func := a.AfterConstruction;
FuncD := PInteger(PInteger(a)^)^
//这是ShowMessage 的地址
FuncE := PInteger(PInteger(a)^+4)^
//这是Show函数的地址,那AfterConstruction的地址在?
ListBox1.Items.Add(Format('A Size:%D',[a.InstanceSize]));
ListBox1.Items.Add(Format('Func Addr:%d,Base Addr:%d,All Get:%d', [Integer(@Func), FuncE, FuncD]));
finally
a.Free;
end;
TBase = class
private
protected
public
procedure ShowMessage
virtual;
constructor Create;
destructor Destroy
override;
end;
TClassA = class(TBase)
private
protected
public
procedure ShowMessage
override;
procedure Show
virtual;
procedure AfterConstruction
override;
constructor Create;
destructor Destroy
override;
end;
TClassB = class(TBase)
private
protected
public
procedure ShowMessage
override;
procedure Show
virtual;
constructor Create;
destructor Destroy
override;
end;
{ TBase }
constructor TBase.Create;
begin
Form1.ListBox1.Items.add('Base Create...');
end;
destructor TBase.Destroy;
begin
Form1.ListBox1.Items.add('Base Destroy...');
inherited Destroy;
end;
procedure TBase.ShowMessage;
begin
beep();
end;
{ TClassB }
constructor TClassB.Create;
begin
Form1.ListBox1.Items.add('TClassB Create...');
end;
destructor TClassB.Destroy;
begin
Form1.ListBox1.Items.add('TClassB Destroy...');
inherited Destroy;
end;
procedure TClassB.Show;
begin
beep();
end;
procedure TClassB.ShowMessage;
begin
beep();
end;
{ TClassA }
procedure TClassA.AfterConstruction;
begin
inherited;
end;
constructor TClassA.Create;
begin
Form1.ListBox1.Items.add('TClassA Create...');
inherited Create;
end;
destructor TClassA.Destroy;
begin
Form1.ListBox1.Items.add('TClassA Destroy...');
inherited Destroy;
end;
procedure TClassA.Show;
begin
beep();
end;
procedure TClassA.ShowMessage;
begin
beep();
inherited Destroy;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
a: TClassA;
Func: TBaseEvent;
FuncD, FuncE: integer;
begin
a := TClassA.Create;
try
Func := a.AfterConstruction;
FuncD := PInteger(PInteger(a)^)^
//这是ShowMessage 的地址
FuncE := PInteger(PInteger(a)^+4)^
//这是Show函数的地址,那AfterConstruction的地址在?
ListBox1.Items.Add(Format('A Size:%D',[a.InstanceSize]));
ListBox1.Items.Add(Format('Func Addr:%d,Base Addr:%d,All Get:%d', [Integer(@Func), FuncE, FuncD]));
finally
a.Free;
end;