萧月禾:
您的这道题可象是绕口令一样,两个FORM是继承,BASE,BASE1又继承,头都被你搞大了!
其实很简单,跟BASE BASE是否被继承没有关系的,你是想让TFORM2有一个与TFORM1相同名称的属性,只要在TFORM2中按正常的方法重新定义一个TBASE1(或是其他类型如Base:Integer,都是可以的),这样TForm1中的属性Base就只能在Form1中使用,而TFrom2中的Base就能在Form2中发挥正常的功能了,你要的是这样吗?下面是代码"
==================================================================
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TBase = class(TObject)
public
procedure s;
end;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
Fbase: Tbase;
{ Private declarations }
public
{ Public declarations }
published
property base: Tbase read Fbase write Fbase;
end;
var
Form1: TForm1;
implementation
procedure TBase.s;
begin
showmessage('base');
end;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
base.s;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FBase:=TBase.create;
end;
end.
=========================================================================
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Unit1, StdCtrls;
type
TForm2 = class(TForm1)
Button2: TButton;
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
FBase: TBase;
function GetBase: TBase;
{ Private declarations }
public
{ Public declarations }
published
property Base read FBase write FBase;
end;
TBase1 = class(tbase)
public
procedure s;
end;
var
Form2: TForm2;
implementation
procedure TBase1.s;
begin
showmessage('base1');
end;
{$R *.dfm}
procedure TForm2.Button2Click(Sender: TObject);
begin
inherited;
TBase1(base).s;
end;
function TForm2.GetBase: TBase;
begin
if not Assigned(FBase) then
FBase:=TBase1.Create;
Result := FBase;
end;
procedure TForm2.FormCreate(Sender: TObject);
begin
inherited;
FBase:=TBase1.create;
end;
end.
=========================================
其实是ModalMake Code Explorer告诉我的:>)