Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2009-01

Loading icon from Application.Icon

11 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Guionardo Furlan

Hello "lazarentos",

I've an TTrayIcon instance and need to use the same icon defined in the Application.Icon.
I've tried:
* TrayIcon.Assign(Application.Icon)
* TrayIcon.LoadFromResourceName(HInstance, 'trayicon'); // Included an resource file with the icon i want

Both don't worked. No errors, but the TrayIcon.icon is empty.

* TrayIcon.LoadFromFile('icon.ico');

This worked. But I don't want to send an icon file with the installation.

Any sugestion?

Thank's for any help.

Timeo hominem unius libri Cogito ergo sum - Carpe diem []s Guionardo Furlan http://guionardo.blogspot.com

Reply by email

Felipe Monteiro de Carvalho
to Guionardo Furlan

Which operating system, fpc and lazarus versions?

Does the example application work for you? It's in examples/trayicon and it loads the icon from the LFM (inside the executable)

Felipe Monteiro de Carvalho

Reply by email

Guionardo Furlan
to Felipe Monteiro de Carvalho

Windows XP SP3
FPC 2.2.2
Lazarus 0.9.26

Yes, when I insert an TTrayIcon in a form and define the icon, everything is all right.
But, I need to dynamically create the ttrayicon and load the icon data from a resource.
Now, I tested the LoadFromLazarusResource method (with the lazres tool) and it worked.

Thanks

2009/1/31 Felipe Monteiro de Carvalho :

Show quoted text 12 lines
Which operating system, fpc and lazarus versions? Does the example application work for you? It's in examples/trayicon and it loads the icon from the LFM (inside the executable) -- Felipe Monteiro de Carvalho _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus
Timeo hominem unius libri Cogito ergo sum - Carpe diem []s Guionardo Furlan http://guionardo.blogspot.com

Reply by email

Felipe Monteiro de Carvalho
to Guionardo Furlan

Can you post a very simple, but complete, example which fails?

The code you showed on the first e-mail was too short to check if your code is wrong or if it's a bug in TIcon.

Felipe Monteiro de Carvalho

Reply by email

Héctor Fiandor Rosario
to Paul Ishenin

Dear Paul Ishenin:
I want to know if in my 0.9.27 I can insert a gif (moving chetach) in my application first form.

thanks in advance,

Ing. H?ctor F. Fiandor

Show quoted text 23 lines
Guionardo Furlan wrote: > Windows XP SP3 > FPC 2.2.2 > Lazarus 0.9.26 > In 0.9.27 we've made rather big icon rework. Please test with either 0.9.27 snapshot or with svn version. I think your problem is solved. Best regards, Paul Ishenin. _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus __________ Informaci?n de ESET Smart Security, versi?n de la base de firmas de virus 3744 (20090106) __________ ESET Smart Security ha comprobado este mensaje. http://www.eset.com

---------------------------------------
Red Telematica de Salud - Cuba
CNICM - Infomed

Reply by email

Guionardo Furlan
to Felipe Monteiro de Carvalho: Can you post a very simple, but complete, example which fails? The code you showed on the…

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.

Now, I could fix it using Lazarusresources.

2009/2/1 Felipe Monteiro de Carvalho :

Show quoted text 12 lines
Can you post a very simple, but complete, example which fails? The code you showed on the first e-mail was too short to check if your code is wrong or if it's a bug in TIcon. -- Felipe Monteiro de Carvalho _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus
Timeo hominem unius libri Cogito ergo sum - Carpe diem []s Guionardo Furlan http://guionardo.blogspot.com

Reply by email

Vincent Snijders
to Guionardo Furlan
Guionardo Furlan wrote 63 lines
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

Reply by email

Guionardo Furlan
to Vincent Snijders

Don't worked. The icon is loaded by the application.

begin
  Application.Title := uTipos.ProgTitulo;
   Application.Initialize;
  Tray.Cria;
   Application.Run;
end.

2009/2/1 Vincent Snijders :

Show quoted text 74 lines
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 _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus
Timeo hominem unius libri Cogito ergo sum - Carpe diem []s Guionardo Furlan http://guionardo.blogspot.com

Reply by email

Paul Ishenin
to Guionardo Furlan
Guionardo Furlan wrote 10 lines
Don't worked. The icon is loaded by the application. begin Application.Title := uTipos.ProgTitulo; Application.Initialize; Tray.Cria; Application.Run; end.

It is all with 0.9.27 I suppose?

Best regards,
Paul Ishenin.

Reply by email

Guionardo Furlan
to Paul Ishenin

0.9.26, the last stable available.
I'll install the 0.9.27+fpc2.2.3 to try.

2009/2/2 Paul Ishenin :

Show quoted text 20 lines
Guionardo Furlan wrote: > Don't worked. The icon is loaded by the application. > > > begin > Application.Title := uTipos.ProgTitulo; > Application.Initialize; > Tray.Cria; > Application.Run; > end. > It is all with 0.9.27 I suppose? Best regards, Paul Ishenin. _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus
Timeo hominem unius libri Cogito ergo sum - Carpe diem []s Guionardo Furlan http://guionardo.blogspot.com

Reply by email