View Issue Details

IDProjectCategoryView StatusLast Update
0032973FPCFCLpublic2018-01-13 11:05
ReporterMartokAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityN/A
Status resolvedResolutionfixed 
Product VersionProduct Build 
Target Version3.2.0Fixed in Version3.1.1 
Summary0032973: Patch, fcl-image: Ability to unregister Image Handlers from TImageHandlersManager
DescriptionIt would be useful to be able to unregister a handler from TImageHandlersManager, for example when overriding a format with a different implementation.

Attached is a suggested patch.
Steps To ReproduceExample usage:

initialization
  ImageHandlers.UnregisterImageHandlers('JPEG Graphics', true, true);
  ImageHandlers.RegisterImageReader ('JPEG Graphics (Turbo)', 'jpg;jpeg', TFPReaderJPEGTurbo);
TagsNo tags attached.
Fixed in Revision37953
FPCOldBugId
FPCTarget
Attached Files
  • fclimage-unregister.patch (1,557 bytes)
    --- fpimage.pp	Tue Jul 25 15:00:20 2017
    +++ fpimage.pp	Sun Jan 07 19:42:22 2018
    @@ -262,6 +262,7 @@
                        AReader:TFPCustomImageReaderClass);
           procedure RegisterImageWriter (const ATypeName,TheExtensions:string;
                        AWriter:TFPCustomImageWriterClass);
    +      procedure UnregisterImageHandlers(const ATypeName: string; ARemoveReader: boolean; ARemoveWriter: boolean);
           property Count : integer read GetCount;
           property ImageReader [const TypeName:string] : TFPCustomImageReaderClass read GetReader;
           property ImageWriter [const TypeName:string] : TFPCustomImageWriterClass read GetWriter;
    
    --- fphandler.inc	Tue May 02 18:45:00 2017
    +++ fphandler.inc	Sun Jan 07 20:45:06 2018
    @@ -112,6 +112,30 @@
         end;
     end;
     
    +procedure TImageHandlersManager.UnregisterImageHandlers(const ATypeName: string; ARemoveReader: boolean;
    +  ARemoveWriter: boolean);
    +var r : integer;
    +    ih: TIHData;
    +begin
    +  if not ARemoveReader and not ARemoveWriter then
    +    exit;
    +  r := FData.count;
    +  repeat
    +    dec (r);
    +  until (r < 0) or (compareText (TIHData(FData[r]).FTypeName, ATypeName) = 0);
    +  if r >= 0 then begin
    +    ih:= TIHData(FData[r]);
    +    if ARemoveReader then
    +      ih.FReader:= nil;
    +    if ARemoveWriter then
    +      ih.FWriter:= nil;
    +    if not Assigned(ih.FReader) and not Assigned(ih.FWriter) then begin
    +      FData.Delete(r);
    +      ih.Free;
    +    end;
    +  end;
    +end;
    +
     function TImageHandlersManager.GetCount : integer;
     begin
       result := FData.Count;
    

Activities

Martok

2018-01-07 20:47

reporter  

fclimage-unregister.patch (1,557 bytes)
--- fpimage.pp	Tue Jul 25 15:00:20 2017
+++ fpimage.pp	Sun Jan 07 19:42:22 2018
@@ -262,6 +262,7 @@
                    AReader:TFPCustomImageReaderClass);
       procedure RegisterImageWriter (const ATypeName,TheExtensions:string;
                    AWriter:TFPCustomImageWriterClass);
+      procedure UnregisterImageHandlers(const ATypeName: string; ARemoveReader: boolean; ARemoveWriter: boolean);
       property Count : integer read GetCount;
       property ImageReader [const TypeName:string] : TFPCustomImageReaderClass read GetReader;
       property ImageWriter [const TypeName:string] : TFPCustomImageWriterClass read GetWriter;

--- fphandler.inc	Tue May 02 18:45:00 2017
+++ fphandler.inc	Sun Jan 07 20:45:06 2018
@@ -112,6 +112,30 @@
     end;
 end;
 
+procedure TImageHandlersManager.UnregisterImageHandlers(const ATypeName: string; ARemoveReader: boolean;
+  ARemoveWriter: boolean);
+var r : integer;
+    ih: TIHData;
+begin
+  if not ARemoveReader and not ARemoveWriter then
+    exit;
+  r := FData.count;
+  repeat
+    dec (r);
+  until (r < 0) or (compareText (TIHData(FData[r]).FTypeName, ATypeName) = 0);
+  if r >= 0 then begin
+    ih:= TIHData(FData[r]);
+    if ARemoveReader then
+      ih.FReader:= nil;
+    if ARemoveWriter then
+      ih.FWriter:= nil;
+    if not Assigned(ih.FReader) and not Assigned(ih.FWriter) then begin
+      FData.Delete(r);
+      ih.Free;
+    end;
+  end;
+end;
+
 function TImageHandlersManager.GetCount : integer;
 begin
   result := FData.Count;

Michael Van Canneyt

2018-01-13 11:05

administrator   ~0105733

Thanks for this patch, it was something that was buried in my ToDo list since a long time :)

I made the boolean parameters optional (default True).

Issue History

Date Modified Username Field Change
2018-01-07 20:47 Martok New Issue
2018-01-07 20:47 Martok File Added: fclimage-unregister.patch
2018-01-12 08:30 Michael Van Canneyt Assigned To => Michael Van Canneyt
2018-01-12 08:30 Michael Van Canneyt Status new => assigned
2018-01-13 11:05 Michael Van Canneyt Fixed in Revision => 37953
2018-01-13 11:05 Michael Van Canneyt Note Added: 0105733
2018-01-13 11:05 Michael Van Canneyt Status assigned => resolved
2018-01-13 11:05 Michael Van Canneyt Fixed in Version => 3.1.1
2018-01-13 11:05 Michael Van Canneyt Resolution open => fixed
2018-01-13 11:05 Michael Van Canneyt Target Version => 3.2.0