0

目前在我的应用程序中,用户能够创建停靠到页面控件的窗口(目前还没有控件)。每个编辑器都有一组与之关联的工具箱。该设置在编辑器构建时重置,并在工具箱关闭和打开时进行修改。当页面控件更改选项卡时,工具箱的状态被保存,它们被关闭,然后新选项卡的工具箱被恢复。

当您更改选项卡时,我的应用程序正在崩溃(起初似乎是随机的)。我相信这是当您非常快速地更改选项卡(双击的速度)时,PageControl.OnChange 事件中工具箱的处理在下一个 PageControl.OnChange 事件开始之前没有完成,我最终得到了两个并行运行的事件'。我的问题是:

1) 这听起来像一个合理的理论吗?我知道有一个 GUI 处理线程 delphi 是否通过调度新线程来处理事件来工作?

2) 你会建议如何解决这个问题?保留消息直到第一种方法完成(这是一种非常快速的方法,所以真的不应该有任何使用滞后)?

这是一些代码,以防有人想从另一个角度看待这个问题。

这是 onchange 事件的代码。

procedure TMainForm.PageDockingAreaChange(Sender: TObject);
var
  count : integer;

  // Shortcut variables
  FormShortcut : TForm;
  WelcomeShortcut : TWelcomePageForm;
  BaseEditorShortcut : TBaseEditor;

begin

  // Set nil values
  FormShortcut := nil;
  WelcomeShortcut := nil;
  BaseEditorShortcut := nil;

  // Create shortcut value
  FormShortcut := Self.GetActiveForm;
  if (FormShortcut is TWelcomePageForm) then WelcomeShortcut := TWelcomePageForm(FormShortcut);
  if (FormShortcut is TBaseEditor) then BaseEditorShortcut := TBaseEditor(FormShortcut);

  // Hide all tabs when welcome page is visible
  if (WelcomeShortcut <> nil) then
    begin

      // Clear any existing toolboxes
      Self.ToolboxClearAll;

    end;
  {endif}

  // Try to execute toolbox setup
  try

    // Load toolbox state
    Self.ToolboxSetup(BaseEditorShortcut);

  except

    // Display fatal error to the user
    ShowMessage('Fatal Error : Unable to load toolboxes.');

  end;

  // Update last active editor
  if (BaseEditorShortcut = nil) then
    Self.LastActiveEditor := nil
  else
    Self.LastActiveEditor := BaseEditorShortcut;
  {endif}

end;

此方法关闭所有工具箱并依次释放它们。

procedure TMainForm.ToolboxClearAll;
var
  count : integer;
begin

  // Save toolbox state if needed
  if Assigned(Self.LastActiveEditor) then
    Self.LastActiveEditor.SaveToolboxState;

  // Close and free all toolboxes
  for count := 0 to length(Self.ActiveToolboxes)-1 do
    Self.ToolboxCloseAndFree(Self.ActiveToolboxes[count]);

  // Reset array size (should already be done though)
  SetLength(Self.ActiveToolboxes, 0);

end;
4

0 回答 0