Atozed Forums
Please support THandlers.Delete method in unit IW.Content.Handlers.pas - Printable Version

+- Atozed Forums (https://www.atozed.com/forums)
+-- Forum: Atozed Software Products (https://www.atozed.com/forums/forum-1.html)
+--- Forum: IntraWeb (https://www.atozed.com/forums/forum-3.html)
+---- Forum: English (https://www.atozed.com/forums/forum-16.html)
+----- Forum: IntraWeb General Discussion (https://www.atozed.com/forums/forum-4.html)
+----- Thread: Please support THandlers.Delete method in unit IW.Content.Handlers.pas (/thread-3944.html)



Please support THandlers.Delete method in unit IW.Content.Handlers.pas - ccy - 03-13-2024

In unit IW.Content.Handlers.pas, THandlers.Add method is available but there is no Delete method to remove TContentBase handler.

It is useful for application deployed with dynamic packages so we can write something like this:

Code:
initialization
  THandlers.Add('/register/', '', TContent_Register.Create);
finalization
  THandlers.Delete('/register/', '');
end.

A patch for reference:

Code:
unit IW.Content.Handlers.Patch;

interface

uses
  IW.Content.Handlers;

type
  THandlersHelper = class helper for THandlers
    class procedure Delete(const aPath, aDocument: string);
  end;

implementation

uses
  System.SysUtils,
  IW.Common.Strings, IWServerControllerBase;

class procedure THandlersHelper.Delete(const aPath, aDocument: string);
var i: Integer;
    xPath: string;
begin
  TIWServerControllerBase.CheckLockGlobal('Handlers.Delete');
  if (aPath = '') and (aDocument = '') then begin
    raise Exception.Create('Path and Document cannot both be empty.');
  end;

  // xPath
  //   -Path + Document: /mypath/mydoc.html
  //   -Path + Extension: /mypath/*.zat
  //   -Path: /mypath/
  //   -Document: mydoc.html
  //   -Extension: *.zat
  if aPath = '' then begin
    xPath := aDocument;
  end else begin
    if not IWStartsText('/', aPath) then begin
      raise Exception.Create('Path must start with /');
    end else
    if (Length(aPath) > 1) and not IWEndsText('/', aPath) then begin   // if aPath = '/', StrUtils.EndsText() returns false for EndsText('/', aPath)!!!
      raise Exception.Create('Path must end with /');
    end;
    xPath := aPath + aDocument;
  end;

  if mList.Find(xPath, i) then
    mList.Delete(i);
end;

end.



RE: Please support THandlers.Delete method in unit IW.Content.Handlers.pas - Alexandre Machado - 04-04-2024

Hi,

I created a new ticket with this request. It's not hard to implement but at the same time requires adding another lock to the THandlers class which is not ideal. I'll think about it....


RE: Please support THandlers.Delete method in unit IW.Content.Handlers.pas - Alexandre Machado - 04-04-2024

BTW, your helper class is correct, however it doesn't consider locking, i.e there is no safe way to add or delete handlers at runtime from multiple sessions which can cause problems.

Do you unload the package before the application finishes, i.e., you would keep the application running after unloading a package that unregisters a content handler?