Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread TIconLibrary
Fri, Feb 8 2019 12:40 AMPermanent Link

Allen Hunt

I have a lot of gifs to be used as animated icons (TAnimatedIcon).  There are too many for them to be loaded at run-time.  Is there a way to add icons to the icon library at run-time?

Best regards,
Allen
Sat, Feb 9 2019 1:36 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Allen,

<< I have a lot of gifs to be used as animated icons (TAnimatedIcon).  There are too many for them to be loaded at run-time.  Is there a way to add icons to the icon library at run-time? >>

Sure, you can use this function to do so:

procedure CreateIcon(const AName: String);
var
  TempInterface: TInterface;
  TempState: TInterfaceState;
begin
  TempInterface:=InterfaceManager.Interfaces.FindInterfaceByClassName(TIconLibrary.ClassName);
  if Assigned(TempInterface) then
     begin
     if (not Assigned(TempInterface.States.FindState(AName))) then
        begin
        TempState:=TempInterface.States.NewState(AName);
        with TempState do
           begin
           RootElement:=TElement.Create('Icon');
           with RootElement do
              begin
              Name:='Icon'; // Must reset the name here - EWB will change it to 'Root'
              with ApplyProperties do
                 begin
                 Background:=True;
                 Height:=True;
                 Width:=True;
                 end;
              Background.Image.Name:=AName+'.png';
              Height:=32;
              Width:=32;
              end;
           end;
        end;
     end;
end;

To test:

procedure TForm1.Button10Click(Sender: TObject);
begin
  CreateIcon('application');
  Icon1.Icon.IconName:='application';
end;

I'm assuming a .png extension, so change it to .gif or whatever you need (or add an extension parameter).  Also, the root element naming behavior is a little wonky, so I'm probably going to fix that, but it won't affect your code, other than to make the explicit Name property assignment extraneous.  I'm also taking advantage of the GC in the browser by not explicitly freeing the element that I create, so I'm cheating a little in that regard.

Tim Young
Elevate Software
www.elevatesoft.com
Mon, Feb 11 2019 12:53 AMPermanent Link

Allen Hunt

Tim,

That's great!  Thank you!

Best regards,
Allen
Image