-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLMS.Helper.Images.pas
82 lines (63 loc) · 1.65 KB
/
LMS.Helper.Images.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
unit LMS.Helper.Images;
interface
uses
System.Classes, Vcl.Controls;
type
{
Esta lista devuelve las imágenes de los recursos cargados desde cualquier unidad
}
TISMImageListFromResource = class(TImageList)
private
FLoadedBitmaps: TStringList;
public
constructor Create(Onwer: TComponent); override;
destructor Destroy; override;
function GetImageIndexByName(const aImageName: String): integer;
end;
function GetGlobalImageListFromResource: TISMImageListFromResource;
implementation
uses
Winapi.windows, forms, Vcl.Graphics;
var
_globalimagelistfromresource: TISMImageListFromResource;
function GetGlobalImageListFromResource: TISMImageListFromResource;
begin
if _globalimagelistfromresource = nil then
_globalimagelistfromresource := TISMImageListFromResource.Create
(application);
result := _globalimagelistfromresource;
end;
constructor TISMImageListFromResource.Create(Onwer: TComponent);
begin
inherited;
FLoadedBitmaps := TStringList.Create;
Height := 16;
Width := 16;
end;
destructor TISMImageListFromResource.Destroy;
begin
FLoadedBitmaps.free;
inherited;
end;
function TISMImageListFromResource.GetImageIndexByName(const aImageName
: String): integer;
var
aBitmap: TBitmap;
begin
result := FLoadedBitmaps.IndexOf(aImageName);
if result >= 0 then
exit
else
begin
if (FindResource(hInstance, PChar(aImageName), RT_BITMAP) <> 0) then
begin
aBitmap := TBitmap.Create;
aBitmap.LoadFromResourceName(hInstance, aImageName);
add(aBitmap, nil);
result := FLoadedBitmaps.add(aImageName);
end;
end;
end;
initialization
_globalimagelistfromresource := nil;
end.