将箭头键和Tab键传递到DLL中的Delphi表单



当Delphi Form在DLL中被声明和实例化,并且由宿主应用程序加载的DLL中,箭头键和Tab键不会跨宿主/DLL边界传递。这意味着可能在窗体上使用的TEdit框和TMemo控件将不会响应这些击键。是否有办法确保这些按键从主应用程序表单传递到dll中的表单?注意,可能有多个dll,每个dll都包含一个表单。KeyPreview没有区别。

看看这个问题,以及你之前的问题,我想说你的基本问题是你没有使用运行时包。

如果你使用的是运行时包,那么你将拥有一个VCL实例,模块边界将无关紧要。

如果没有运行时包,您将拥有单独的VCL实例。要使VCL表单导航正常工作,需要将每个控件识别为VCL控件。当您有多个VCL实例时,这是不可能的。

DLL中的窗体缺少此支持,以及对菜单快捷键(操作)的支持。您可以编写一些代码来模拟此行为。

////////////////////////////////////////////////////////////////
// If you display a form from inside a DLL/COM server, you will miss
// the automatic navigation between the controls with the "TAB" key.
// The "KeyPreview" property of the form has to be set to "True".
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
var
  bShift: Boolean;
begin
  // Check for tab key and switch focus to next or previous control.
  // Handle this in the KeyPress event, to avoid a messagebeep.
  if (Ord(Key) = VK_TAB) then
  begin
    bShift := Hi(GetKeyState(VK_SHIFT)) <> 0;
    SelectNext(ActiveControl, not(bShift), True);
    Key := #0; // mark as handled
  end;
end;

最新更新