Skip to content

Commit daf0198

Browse files
committed
Add TGIFImage class helper
This class helper was added to replace direct loading of GIFs from resources that was removed from 3rd party TGIFImage when it was ported to the Delphi VCL
1 parent b1ae57a commit daf0198

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

Src/UClassHelpers.pas

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111

1212
unit UClassHelpers;
1313

14+
{ TODO: Separate different helpers into their own units, within a ClassHelpers
15+
scope. E.g. ClassHelpers.Controls, ClassHelper.Graphics }
1416

1517
interface
1618

1719

1820
uses
1921
// Delphi
20-
Controls, Menus, ImgList, Graphics, ActnList;
22+
Controls, Menus, ImgList, Graphics, ActnList, GIFImg;
2123

2224

2325
type
@@ -70,6 +72,21 @@ TActionListHelper = class helper for TCustomActionList
7072
procedure Update;
7173
end;
7274

75+
type
76+
/// <summary>Class helper that adds a method to TGIFImage that adds a similar
77+
/// method to one present in 3rd party TGIFImage to load an image from
78+
/// resources.</summary>
79+
TGIFImageHelper = class helper for TGIFImage
80+
public
81+
/// <summary>Load a GIF image from given resource.</summary>
82+
/// <param name="Module">HINSTANCE [in] Module containing resource.</param>
83+
/// <param name="ResName">string [in] Name of resource to be loaded.
84+
/// </param>
85+
/// <param name="ResType">PChar [in] Type of resource to be loaded.</param>
86+
procedure LoadFromResource(const Module: HMODULE; const ResName: string;
87+
const ResType: PChar);
88+
end;
89+
7390

7491
implementation
7592

@@ -174,5 +191,20 @@ procedure TActionListHelper.Update;
174191
Action.Update;
175192
end;
176193

194+
{ TGIFImageHelper }
195+
196+
procedure TGIFImageHelper.LoadFromResource(const Module: HMODULE;
197+
const ResName: string; const ResType: PChar);
198+
var
199+
Stm: TResourceStream;
200+
begin
201+
Stm := TResourceStream.Create(Module, ResName, ResType);
202+
try
203+
LoadFromStream(Stm);
204+
finally
205+
Stm.Free;
206+
end;
207+
end;
208+
177209
end.
178210

0 commit comments

Comments
 (0)