关于DLL组件问题。提示:Control '' has no parent window ( 积分: 200 )

  • 主题发起人 主题发起人 tengjian1981
  • 开始时间 开始时间
T

tengjian1981

Unregistered / Unconfirmed
GUEST, unregistred user!
我在DLL程序中写了一个过程:
procedure OpenForm(mainForm:TForm;DS:Tdataset);stdcall;
var
Form1: TForm;
ptr:PLongInt;
QuickRep1: TQuickRep;
begin
ptr:=@(Application.MainForm);
ptr^:=LongInt(mainForm);
Form1:=TForm.Create(mainForm);
QuickRep1:=TQuickRep.CreateParented();
QuickRep1:=TQuickRep.Create(Form1);
QuickRep1.DataSet:=DS;
QuickRep1.ReportTitle:='DLL';
QuickRep1.Zoom:=100;
QuickRep1.PreviewModal;
end;
但是在另外的程序中调用是提示“Control '' has no parent window”
而我把这个过程直接写在程序中,不用通过DLL来调用就不报错!

望高手来赐教,在线等
 
我在DLL程序中写了一个过程:
procedure OpenForm(mainForm:TForm;DS:Tdataset);stdcall;
var
Form1: TForm;
ptr:PLongInt;
QuickRep1: TQuickRep;
begin
ptr:=@(Application.MainForm);
ptr^:=LongInt(mainForm);
Form1:=TForm.Create(mainForm);
QuickRep1:=TQuickRep.CreateParented();
QuickRep1:=TQuickRep.Create(Form1);
QuickRep1.DataSet:=DS;
QuickRep1.ReportTitle:='DLL';
QuickRep1.Zoom:=100;
QuickRep1.PreviewModal;
end;
但是在另外的程序中调用是提示“Control '' has no parent window”
而我把这个过程直接写在程序中,不用通过DLL来调用就不报错!

望高手来赐教,在线等
 
调用的程序是:
procedure TForm1.Button1Click(Sender: TObject);
var
DS:TDataSet;
begin
DS:=DataSource1.DataSet;
PrintForm(Application.MainForm,DS);
end;
 
把Form1:=TForm.Create(mainForm);
改成
Form1:=TForm.Create(Self);
试试
 
QuickRep1:=TQuickRep.Create(Form1);这里也不行吧。
 
TO:一诺
改成
Form1:=TForm.Create(Self);
编译都通不过。

TO:newsmile
QuickRep1:=TQuickRep.Create(Form1);
这里有什么问题?还望说详细点
 
form1的父窗体是谁呢?当窗体中引用本身的时候要用self代替窗体名的。尤其是那些form1,form2之类。
 
form1是新创建的窗口。
我的做法是:将exe程序中Application.MainForm作为参数传到dll中,然后创建一个新的窗口form1,在这个里面做打印预览。
 
>> ptr:=@(Application.MainForm);
>> ptr^:=LongInt(mainForm);

楼主真是高手呢,连Application.MainForm这个只读属性都能改!PFPF...我太PF楼主了[:D][:D][:D][:D]

TApplication.MainForm
Identifies which form in the application is the main window.

property MainForm: TForm;

Description

Use MainForm to determine the form that acts as the application’s main window. The main form is the first form created in the main body of the application. When the main form closes, the application terminates.

When a new project is created, Form1 automatically becomes the value of the MainForm property. To assign a different form to the MainForm property, use the Forms page of the Project|Options dialog box at design time. [red]MainForm cannot be modified at runtime; it is read-only.[/red]

好像调用DLL中的窗体时是传Application.Handle的吧[8D][8D][8D]
 
TO:thx1180
其实原来的代码是一个用dll打开子窗口的案例
dll代码:
procedure OpenForm(mainForm:TForm;DS:Tdataset);stdcall;
var
Form1: TForm;
ptr:PLongInt;
QuickRep1: TQuickRep;
begin
ptr:=@(Application.MainForm);
ptr^:=LongInt(mainForm);
Form1:=TForm.Create(mainForm);
Form1.Show;
end;

exe程序代码:
procedure TForm1.Button2Click(Sender: TObject);
var
DS:TDataSet;
begin
DS:=DataSource1.DataSet;
OpenForm(Application.MainForm,DS);//为了调MDICHILDend;
end;
运行没有任何问题,而且好多人都认可的代码。我不知道哪有问题,我只是在dll的form1中创建QuickRep1才产生问题的
 
建议楼主去看看《delphi 5开发人员指南》第九章,对DLL讲得很清楚。
 
我来测试一下,顺便学习。
帮楼主顶
 
我只是临时用一下,简单的dll我会做。现在是想用dll做一个组件,好象有点难度啊
 
多人接受答案了。
 
后退
顶部