AChildForm :=TAChildForm.Create(application);
//移去DBGrid
AChildForm.RemoveControl(AchildForm.DBGrid1);
AChildForm.show;
修改一下可否,
AChildForm :=TAChildForm.Create(nil);
with AChildForm do
begin
RemoveControl(DBgrid1);
Show;
end;
//移去DBGrid
AChildForm.RemoveControl(AchildForm.DBGrid1);
AChildForm.show;
修改一下可否,
AChildForm :=TAChildForm.Create(nil);
with AChildForm do
begin
RemoveControl(DBgrid1);
Show;
end;
可以,但没解决问题,该application 为nil 没什么区别!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs,DB,unit2, StdCtrls,QGrids;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
TAChildForm=Class(TChildForm)
StringGrid1:TStringGrid ;
private
{ Private declarations}
public
constructor Create(AOwner:TComponent);override;
destructor Destroy;override;
{ Public declarations }
end;
var
Form1: TForm1;
AChildForm:TAChildForm;
implementation{$R *.dfm}{TAChildForm }constructor TAChildForm.Create(AOwner: TComponent);
begin
inherited;
end;
destructor TAChildForm.Destroy;
begin
inherited;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
AChildForm :=TAChildForm.Create(application);
AChildForm.RemoveControl(AchildForm.DBGrid1);
StringGrid1:= TStringGrid.Create(AChildForm);
with StringGrid1 do
begin
Parent:=AChildForm;
SetBounds(50,50,100,100);
caption:= StringGrid1.ClassName;
end;
AChildForm.show;
end;
end.unit Unit2; //同上不变测试结果:出现的错误是不相容的类型:‘TwidgetControl'and'TAChildForm'
光标停在Parent:=AChildForm;奇怪的是我用TLabel 去代替TStringGrid则没问题。
原贴内容:
VAR StringGrid1: TStringGrid;
Begin
StringGrid1:= TStringGrid.Create(self);
with StringGrid1 do
begin
Parent:=self;//出错不相容的类型‘TwidgetControl'and'TForm'
SetBounds(50,50,100,100);
caption:= StringGrid1.ClassName;
StringGrid1.Align:=alClient;
end;
end; 请不要引用以Q开头的文件,这代码就不会出错。
我用delphi6测试