简体   繁体   中英

cxgrid ib dll delphi

Good day, I write plugins dll from the main form call the 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;

in the dll itself, it looks like

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;

the problem is that I can not edit cells cxGrid can I do something wrong?

I have encountered this before, and there are a couple of ways around it. It was a long time ago, so you will have to do a bit of trial and error.

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;

That should fix your problem. Failing that, try setting DLL's Application.Handle to the application's Application.Handle. I usually do this with an Init function in the DLL. This function stores the the DLL's Application.Handle in a global variable and reassigns it to the application's handle, passed as a parameter to the function. When you unload the DLL, you assign the DLL's application.handle back to its original value, otherwise everything goes South.

var
    FOldHandle: THandle;

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM