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;
上面有一句Instance := TComponent(InstanceClass.NewInstance);
TForm(Instance).HandleNeeded;还有以前我在书上看到的
if PanelX.Controls[i] is TDBEdit then TDBEdit(PanelX.Controls[i]).Enabled:=true;
都有 “xxx:=类名(实例)” 这种写法 这种写法算什么??
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;
上面有一句Instance := TComponent(InstanceClass.NewInstance);
TForm(Instance).HandleNeeded;还有以前我在书上看到的
if PanelX.Controls[i] is TDBEdit then TDBEdit(PanelX.Controls[i]).Enabled:=true;
都有 “xxx:=类名(实例)” 这种写法 这种写法算什么??
if PanelX.Controls[i] is TDBEdit then TDBEdit(PanelX.Controls[i]).Enabled:=true;这句的意思就是说如果面板上的第I个控件是TDBEDIT类型时
就把它强制转换为TDBEDIT类型
设置它的ENABLED属性为TRUE;
因为如果你上面不用TDBEDIT()的话,你没法设置ENABLED属性,要让程序还没有运行的时候,知道当前设置的ENABLED属性是设置TDBEDIT类类型的,
上面的同样的
还是强制转化快一些.
>出于安全考虑的话还可以用as操作符
没必要,因为很安全.