[Lazarus] Loading icon from Application.Icon
Vincent Snijders
vincent.snijders at gmail.com
Sun Feb 1 22:03:45 CET 2009
Guionardo Furlan schreef:
> The application don't have a main form.
> Look:
>
> program nodort;
>
> {$mode objfpc}{$H+}
>
> uses
> {$IFDEF UNIX} {$IFDEF UseCThreads}
> cthreads,
> {$ENDIF} {$ENDIF}
> Interfaces, // this includes the LCL widgetset
> Forms
> { you can add units after this }, uEvento, uTrayIcon, uResources, uConfigura,
> foConfig, uTipos;
>
> {$IFDEF WINDOWS}
> {$R nodort.rc}
> {$ENDIF}
> begin
> Application.Title := uTipos.ProgTitulo;
> Application.Initialize;
> Application.Run;
> end.
>
> The uTrayIcon unit have a class TTray:
>
> TTray = class (TComponent)
> FMenu: TPopupMenu;
> FTrayIcon: TTrayIcon;
> FTimer: TTimer;
> procedure ClickMenu (Sender: TObject);
> procedure TimerEvent(Sender: TObject);
> private
> FUltimaParada,
> FProximoAlarme: TDateTime;
> procedure CriaMenu;
> procedure CriaTray;
> procedure CriaTimer;
> procedure Configura;
> procedure AtualizaDica;
> procedure PedePraParar;
> public
> procedure Cria;
> property Menu: TPopupMenu read FMenu;
> property TrayIcon: TTrayIcon read FTrayIcon;
> end;
>
> In this unit, a global var Tray is defined and instantiated on the
> initialization clause.
>
> initialization
> Tray:=TTray.Create(Application);
> Tray.Cria; // Here comes the second-fase creation task, where have:
>
> FTrayIcon:=TTrayIcon.Create(self);
> FTrayIcon.Icon.Assign(Application.Icon);
> FTrayIcon.PopUpMenu := FMenu;
> FTrayIcon.Visible := True;
> FTrayIcon.BalloonFlags:=bfInfo;
>
> The trayicon is enabled and can be found in the traybar. The popupmenu works.
> But the icon image is empty. This is the problem.
The Application.Icon might not be initialized until you run
Application.Initialize. So you assign an empty icon to your trayicon.
Vincent
More information about the Lazarus
mailing list