Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

Errors in Unit LMDHookComponent

There are two code errors in the current version 2021 in the unit LMDHookComponent. See corrections below. Without this corrections lmd components will lead to a crash if used in your software.

finalization
...
 if Assigned(HookList) then HookList.Free;

procedure TLMDCustomHookComponent.SetActive(newValue: Boolean);
....
if not NewValue then
      begin
        if HookList <> nil then
        begin
          ch := HookList.GetCtlHook(FControl);
          if ch <> nil then begin
             ch.RemoveHook(Self);
             HookList.FCtlHooks.Remove(ch)
          end;
        end;
         RestoreState;
      end

Comments

  • 3 Comments sorted by Votes Date Added
  •  if Assigned(HookList) then HookList.Free;

    This condition is not really required because TObject.Free method check that Self is not null:

    if Self <> nil then
      Destroy;

    procedure TLMDCustomHookComponent.SetActive(newValue: Boolean);

    As about the code in SetActive, you may be right. We recently changed related code, and so, some old bug in this code can become visible. Can you describe in more details the exact issue and steps to reproduce it? Or maybe you can send a small demo project to our support email?
  • It's easy to reproduce: Place a TElHTMLView Control (where the HTMLRender Class uses a hook) on a Dialog which gets created and deleted while the main program is running. Then close the main Program and the HookList which is destroyed in the unit finalizer still contains the hook to a no longer existing control and will therefore cause a exception while freeing.
  • I still cannot get any error, but logically you are right. So, I've chnged the code like this (one more "if" compared to your code):

            if HookList <> nil then
            begin
              ch := HookList.FindCtlHook(FControl);
              if ch <> nil then
              begin
                ch.RemoveHook(Self);
                if ch.FHooks.Count = 0 then
                  HookList.FCtlHooks.Remove(ch);
              end;
            end;
Sign In or Register to comment.