I have a component. In the component, I need to load dynamic TImageList.
This way I use today, but in all my projects, I need to add all the image, one at a time.
function NavigatorImages: TImageList;
var
vIcon: TBitmap;
I: Integer;
begin
if FNavigatorImages = nil then
begin
vIcon := TBitmap.Create;
try
FNavigatorImages := TImageList.Create (nil);
FNavigatorImages.Height := 16;
FNavigatorImages.Width := 16;
for I := 0 to 11 do
begin
vIcon.LoadFromResourceName (HInstance, 'IMAGE_' + IntToStr(I));
FNavigatorImages.AddMasked (vIcon, vIcon.Canvas.Pixels[0, FNavigatorImages.Height - 1]);
end;
finally
vIcon.Free;
end;
end;
Result := FNavigatorImages;
end;
How do I create a single resource file, Which for example, contains multiple images can be loaded into the component without adding resources in each project. You have some way?
You'll have to add it to every project you want to use it, but there are ways to make the task easier.
Create the
.resfile using a.rcfile and thebrcctool:Add the same
.resfile to every project you want to use those images (Project >> Add to Project or just edit.dprto add{R 'path/filename.res'}. If you have a common unit to all these projects (which is the case if that component you talk about is a custom one), you could also add the.resfile to that unit and the resources will be loaded to all of them..resand the.rc({$R 'output.res' 'input.rc'}), Delphi will compile your resource file automatically for you (I couldn't determine exactly when it decides to do that, but if you compile your projects a couple of times, the resources files will certainly get compiled too).Sample
.rcfile:The second parameter is the Resource-Definition Statement.
Of course, if any of those images change, you'll have to recompile the
.rcfile manually.