|
<< Click to Display Table of Contents >> Navigation: Forum > Please support THandlers.Delete method in unit IW.Content.Handlers.pas |
03-13-2024, 10:14 AM:
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.
04-04-2024, 04:15 AM:
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....
04-04-2024, 07:22 PM:
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?