dll中的form Dock到主窗体 TabSheet中的ScrollBox中后,
DLL中form 上的pagecontrol 报错:Control 'PageControl' has no parent window
form1.Dock(TScrollBox(psParent),form1.BoundsRect);
如果不加这句就不会,但是这句是一定要的.
怎么解决.
DLL中form 上的pagecontrol 报错:Control 'PageControl' has no parent window
form1.Dock(TScrollBox(psParent),form1.BoundsRect);
如果不加这句就不会,但是这句是一定要的.
怎么解决.
function GetParentForm(Control: TControl): TCustomForm;
begin
while Control.Parent <> nil do Control := Control.Parent;
//这句is判断通不过,因为Control虽然是TCustomForm,但是它是exe中的,而TCustomForm类型信息是dll中的
if Control is TCustomForm then
Result := TCustomForm(Control) else
Result := nil;
end;function ValidParentForm(Control: TControl): TCustomForm;
begin
Result := GetParentForm(Control);
if Result = nil then
raise EInvalidOperation.CreateFmt(SParentRequired, [Control.Name]);
end;
function GetParentForm(Control: TControl): TCustomForm;
begin
while Control.Parent <> nil do Control := Control.Parent;//问题出在这里,因为在dll里不认的主调form的类是否是从Tform继承,
if Control is TCustomForm then
Result := TCustomForm(Control)
else
Result := nil;
end;作了如下修改function GetParentForm(Control: TControl): TCustomForm;
var
cName: String;
begin
while Control.Parent <> nil do Control := Control.Parent;
if Control is TCustomForm then
Result := TCustomForm(Control)
else
begin
if upperCase(Control.ClassName) = '这里是主调form的类名' then
Result := TForm(Control)
else
Result := nil;
end;
end;