看了这个我有点明白了....procedure TApplication.CreateForm(InstanceClass: TComponentClass; var Reference); var Instance: TComponent; begin Instance := TComponent(InstanceClass.NewInstance); TComponent(Reference) := Instance; try Instance.Create(Self); except TComponent(Reference) := nil; raise; end; if (FMainForm = nil) and (Instance is TForm) then begin TForm(Instance).HandleNeeded; FMainForm := TForm(Instance); end; end; 有一点不明白,Create(nil)和Create(OtherCompenent)都能运做,在Create的时候传进去的 参数究竟是做什么的呀?Create的时候给它Appliction 对象为参数又是什么意思呢?
constructor TComponent.Create(AOwner: TComponent); begin FComponentStyle := [csInheritable]; if AOwner <> nil then AOwner.InsertComponent(Self); end;反向追踪到上面的代码,你应该知道,传入nil参数和其它的对象有什么区别了
var
Instance: TComponent;
begin
Instance := TComponent(InstanceClass.NewInstance);
TComponent(Reference) := Instance;
try
Instance.Create(Self);
except
TComponent(Reference) := nil;
raise;
end;
if (FMainForm = nil) and (Instance is TForm) then
begin
TForm(Instance).HandleNeeded;
FMainForm := TForm(Instance);
end;
end;
有一点不明白,Create(nil)和Create(OtherCompenent)都能运做,在Create的时候传进去的
参数究竟是做什么的呀?Create的时候给它Appliction 对象为参数又是什么意思呢?
begin
FComponentStyle := [csInheritable];
if AOwner <> nil then AOwner.InsertComponent(Self);
end;反向追踪到上面的代码,你应该知道,传入nil参数和其它的对象有什么区别了