cxgrid ib dll delphi

时间:2012-03-06 06:25:10

标签: delphi dll tcxgrid

美好的一天,我写插件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单元格我可以做错什么吗?

1 个答案:

答案 0 :(得分: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;
...