【问题标题】:cxgrid ib dll delphicxgrid ib dll delphi
【发布时间】:2012-03-06 06:25:09
【问题描述】:

美好的一天,我写插件 dll 从主窗体调用 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;

在 dll 本身中,它看起来像

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 我可以做错什么吗?

【问题讨论】:

  • 在您的代码中没有提到 cxGrid(DevExpress 网格?),所以很难说。你能发布一些你已经尝试过的相关代码和一些步骤吗?
  • 您不能安全地跨 DLL 边界传递 Delphi 对象。那个 TWinControl 参数不好。为什么你需要传递它以及它的 HWND?不过不确定这与问题有关。
  • 在主程序中我有一个组件,其中 ScrollBox 并且必须从 dll 表单中放置文件,当您按下按钮“СКРЫТЬ”时,表单的天数应该在其他捕获量减少楼上,用我上面提供的代码,它可以工作,但是你不能编辑 cxGrid 这里是截图的链接s51.radikal.ru/i132/1203/da/3787a490fd8f.jpg

标签: delphi dll tcxgrid


【解决方案1】:

我以前遇到过这种情况,有几种解决方法。那是很久以前的事了,所以你必须做一些试验和错误。

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;
...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-08
    • 2017-09-18
    • 2013-03-23
    相关资源
    最近更新 更多