2012-03-06 62 views
0

美好的一天,我写的插件在DLL本身dll的 从主窗体调用DLLcxgrid IB DLL德尔福

type 
    TCreateCustomWindow=function(ParentFrame:TWinControl; ParentHandle:integer; ParentRect:TRect; var WinHandle:THandle):integer; stdcall; 

var 
CreateW:TCreateCustomWindow; 
begin 
CreateW:=GetProcAddress(FHLib,'Create_LEF'); 
if Assigned(CreateW) then 
begin 
    if Assigned(CreateW) then LEFT_OKNO:=CreateW(ScrollBox2, ScrollBox2.Handle, ClientRect, FChildHandle); 
end; 

,它看起来像

function Create_LEF(ParentFrame:TWinControl; ParentHandle:integer; ParentRect:TRect; var WinHandle:THandle):integer; stdcall; export; 
begin 
    Result:=0; 
    WinHandle:=0; 
    try 
    FD3:=TForm3.Create(nil); 
    FD3.Parent:= ParentFrame; 
    Result:=integer(FD3); 
    WinHandle:=FD3.Handle; 
    if ParentHandle<>0 then begin 
     SetParent(WinHandle,ParentHandle); 
     with FD3 do begin 
     FD3.Align:=alTop; 
     FD3.Width:=ParentFrame.Width; 
     hirina_left:=ParentFrame.Width; 
     FD3.Show; 
     end; 
    end; 
    except 
    On E:exception do MessageDlg(E.Message,mtError,[mbOK],0); 
    end; 
end; 

的问题是,我可以不是编辑单元格cxGrid可以做些什么错事吗?

+0

在你的代码中没有提及cxGrid(DevExpress网格?),所以很难说。你能发布一些你已经试过的相关代码和一些步骤吗? – Birger 2012-03-06 06:31:02

+0

您无法安全地跨DLL边界传递Delphi对象。 TWinControl参数不好。为什么你需要通过它以及HWND?不知道这与问题相关。 – 2012-03-06 06:31:28

+0

在主程序中我有一个组件ScrollBox,并且必须将这个文件从dll窗体中放置,当你按下按钮“СКРЫТЬ”时,窗体的数量应该减少,在另一个窗体上追上,用代码I提供上面,它的工作原理,但你不能编辑cxGrid下面是截图http://s51.radikal.ru/i132/1203/da/3787a490fd8f.jpg – fedormoore 2012-03-06 11:49:15

回答

0

我以前遇到过这种情况,并且有几种解决方法。这是很久以前,所以你将不得不做一些试验和错误。

function Create_LEF(ParentFrame:TWinControl; ParentHandle:integer; ParentRect:TRect; var WinHandle:THandle):integer; stdcall; export; 
begin 
    Result:=0; 
    WinHandle:=0; 
    try 
    FD3:=TForm3.Create(nil); 
    FD3.Parent:= ParentFrame; 
    Result:=integer(FD3); 
    WinHandle:=FD3.Handle; 
    if ParentHandle<>0 then begin 
     with FD3 do begin 
     ParentWindow := ParentFrame.Handle; 
     Parent := ParentFrame; 
     Align:=alTop; 
     Width:=ParentFrame.Width; 
     hirina_left:=ParentFrame.Width; 
     Show; 
     end; 
    end; 
    except 
    On E:exception do MessageDlg(E.Message,mtError,[mbOK],0); 
    end; 
end; 

这应该解决您的问题。如果没有,请尝试将DLL的Application.Handle设置为应用程序的Application.Handle。我通常使用DLL中的Init函数执行此操作。该函数将DLL的Application.Handle存储在全局变量中,并将其重新分配给应用程序的句柄,并作为参数传递给该函数。卸载该DLL时,将该DLL的application.handle分配回其原始值,否则一切都会向南。

var 
    FOldHandle: THandle; 

procedure Init(AHandle: THandle); stdcall; 
begin 
    FOldHandle := Application.Handle; 
    Application.Handle := AHandle; 
end; 

procedure UnInit; stdcall; 
begin 
    Application.Handle := FOldHandle; 
end; 
... 
+0

不幸的是它并没有帮助我... – fedormoore 2012-03-08 09:24:55