Autor Beitrag
Sivar
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 40



BeitragVerfasst: Do 23.01.03 21:16 
Hallo,

ich habe in meiner Komponente ein Icon als property definiert, so dass ich schon während der Programmentwicklung ein Icon zuweisen kann.
Problem: Sobald ich das Programm starte hat er das Icon vergessen.

Ich möchte das eigentlich so wie bei einem TImage haben, da kann man auch schon im Objektinspektor ein Bild laden welches dann auch noch zur Laufzeit zur Verfügung steht.

Hat jemand eine Idee was dabei beachtet werden muss bzw. wie man das realisieren kann?

Dank und Gruß

Sivar
Sivar Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 40



BeitragVerfasst: Fr 24.01.03 14:04 
Hat wirklich keiner eine Idee? Oder zumindest wo ich evtl. Info's darüber finden kann?

Ich habe schon versucht das im Delphi Source Code nach zu schauen, aber ich find da nichts spezielles.
opfer.der.genauigkeit
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 754
Erhaltene Danke: 1



BeitragVerfasst: Fr 24.01.03 14:18 
Versuchs mal bei FormCreate zu erstellen.

Von welechem Typ ist eigentlich deine Eigenschaft?

_________________
Stellen Sie sich bitte Zirkusmusik vor.
Sivar Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 40



BeitragVerfasst: Fr 24.01.03 14:59 
Hey, es gitbt doch noch Hoffnung für mich :)

Hm, FormCreate macht wenig Sinn bei einer Komponente?!
Die Eigentschaft ist vom Typ TIcon.
smiegel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 992
Erhaltene Danke: 1

WIN 7
D7 Prof., C#, RAD XE Prof.
BeitragVerfasst: Fr 24.01.03 15:02 
Hallo Sivar,

wie sieht Deine Objektdeklaration bzgl. des Icon aus?

_________________
Gruß Smiegel
Ich weiß, daß ich nichts weiß, aber ich weiß mehr als die, die nicht wissen, daß sie nichts wissen. (Sokrates)
opfer.der.genauigkeit
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 754
Erhaltene Danke: 1



BeitragVerfasst: Fr 24.01.03 15:57 
Wieso sollte das keinen Sinn machen bei FormCreate?
Klar umständlich, die Prop. der Komponente beim Erzeugen des Formulars zu setzen. Aber möglich. :)

Vielleicht hast ja beim Ableiten d. Kompo was falsch gemacht.
inherited od. sowas vergeßn...
Schau die Kompo noch mal genau an.

_________________
Stellen Sie sich bitte Zirkusmusik vor.
Sivar Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 40



BeitragVerfasst: Fr 24.01.03 16:09 
@Smiegel:
ausblenden volle Höhe Quelltext
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:
type
  TNotifyMouseEvent = procedure(Sender : TObject; X, Y : Longint) of object;

  TNotifyIcon = class(TNotifyComponent) // TComponent mit Message behandlung
    constructor Create(AOwner : TComponent); override;
    destructor Destroy; override;
  private
    { Private-Deklarationen }
    fNotifyIconData : TNotifyIconData;
    fIcon : TIcon;
    fHint : String;
    fVisible : Boolean;
    fPopupMenu : TPopupMenu;

    fOnLButtonDown : TNotifyMouseEvent;
    fOnRButtonDown : TNotifyMouseEvent;
    fOnMButtonDown : TNotifyMouseEvent;
    fOnLButtonUp   : TNotifyMouseEvent;
    fOnRButtonUp   : TNotifyMouseEvent;
    fOnMButtonUp   : TNotifyMouseEvent;
    fOnLButtonDblClk : TNotifyMouseEvent;
    fOnRButtonDblClk : TNotifyMouseEvent;
    fOnMButtonDblClk : TNotifyMouseEvent;
    procedure NotifyIconMessage(var AMessage : TMessage); message WM_NotifyIconMessage;
    procedure SetIcon(AIcon : TIcon);
    procedure SetVisible(AVisible : Boolean);
    procedure SetHint(AHint : String);
  protected
    { Protected-Deklarationen }
  public
    { Public-Deklarationen }
  published
    { Published-Deklarationen }
    property Icon : TIcon read fIcon write SetIcon;
    property Visible : Boolean read fVisible write SetVisible;
    property Hint : String read fHint write SetHint;
    property PopupMenu : TPopupMenu read fPopupMenu write fPopupMenu;

    property OnLButtonDown : TNotifyMouseEvent read fOnLButtonDown write fOnLButtonDown;
    property OnRButtonDown : TNotifyMouseEvent read fOnRButtonDown write fOnRButtonDown;
    property OnMButtonDown : TNotifyMouseEvent read fOnMButtonDown write fOnMButtonDown;
    property OnLButtonUp   : TNotifyMouseEvent read fOnLButtonUp write fOnLButtonUp;
    property OnRButtonUp   : TNotifyMouseEvent read fOnRButtonUp write fOnRButtonUp;
    property OnMButtonUp   : TNotifyMouseEvent read fOnMButtonUp write fOnMButtonUp;
    property OnLButtonDblClk : TNotifyMouseEvent read fOnLButtonDblClk write fOnLButtonDblClk;
    property OnRButtonDblClk : TNotifyMouseEvent read fOnRButtonDblClk write fOnRButtonDblClk;
    property OnMButtonDblClk : TNotifyMouseEvent read fOnMButtonDblClk write fOnMButtonDblClk;
  end;


@odg:
Ich meine das Verhalten was die z.B. die TImage Komponente z.B. hat.
Da kannst du zur Entwicklungszeit ein Image laden welches zur Laufzeit zur Verfügung steht
smiegel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 992
Erhaltene Danke: 1

WIN 7
D7 Prof., C#, RAD XE Prof.
BeitragVerfasst: Fr 24.01.03 16:25 
Hallo,

leider bringt mir der Code nicht viel. Wie sieht Create und SetIcon aus?

_________________
Gruß Smiegel
Ich weiß, daß ich nichts weiß, aber ich weiß mehr als die, die nicht wissen, daß sie nichts wissen. (Sokrates)
Sivar Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 40



BeitragVerfasst: Fr 24.01.03 16:29 
ausblenden volle Höhe Quelltext
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:
constructor TNotifyIcon.Create(AOwner : TComponent);
begin
  inherited Create(AOwner);

  if not Assigned(fIcon) then
  begin
    fIcon := TIcon.Create;
    fIcon.Assign(Application.Icon);
  end;

  fVisible := False;
  fHint := '';

  with fNotifyIconData do
  begin
    cbsize           := sizeof(TNotifyIconData);
    uID              := 0;
    uFlags           := NIF_ICON or NIF_MESSAGE or NIF_TIP;
    uCallbackMessage := WM_NotifyIconMessage;
    szTip            := '';
    Wnd              := Handle;
    hIcon            := fIcon.Handle;
  end;
end;

procedure TNotifyIcon.SetIcon(AIcon : TIcon);
var
  NewIcon : TIcon;
begin
  NewIcon := nil;
  if AIcon <> nil then
  begin
    NewIcon := TIcon.Create;
    NewIcon.Assign(AIcon);
  end;
  try
    fIcon.Free;
    FIcon := NewIcon;
    fNotifyIconData.hIcon := fIcon.Handle;
    if fVisible then Shell_NotifyIcon(NIM_MODIFY, @fNotifyIconData)
  except
    NewIcon.Free;
    raise;
  end;
end;


Das SetIcon habe ich mir aus der Source von TImage abgeschaut.
So, jetzt werd ich erstmal nach Hause fahren....FEIERABEND....werde zu Hause wieder reinschauen.

- bis später -
smiegel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 992
Erhaltene Danke: 1

WIN 7
D7 Prof., C#, RAD XE Prof.
BeitragVerfasst: Fr 24.01.03 16:51 
Hallo,

das Problem liegt daran:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
  ...
  fIcon.Free; 
  FIcon := NewIcon; //--> hier wird nur der Zeiger aber kein Inhalt zugewiesen
  ...
except 
    NewIcon.Free; // --> Referenz auf fIcon wird gelöscht
  ...


Mal eine andere Frage: muss das so kompliziert sein? Reciht nicht folgendes?
ausblenden Quelltext
1:
2:
3:
4:
5:
procedure TNotifyIcon.SetIcon(AIcon : TIcon); 
begin
  fIcon.Assign(aIcon);
  if fVisible then Shell_NotifyIcon(NIM_MODIFY, @fNotifyIconData);
end;

_________________
Gruß Smiegel
Ich weiß, daß ich nichts weiß, aber ich weiß mehr als die, die nicht wissen, daß sie nichts wissen. (Sokrates)
Sivar Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 40



BeitragVerfasst: Fr 24.01.03 17:41 
Tja, das hatte ich auch zuerst so, aber dann habe ich mir mal den TImage Code angeschaut, und die haben das da so gemacht....Ist quasi "Adaptierter Borldand-Code", hihi. (Ich dachte damit würde es gehen).

Hast aber recht, das einfache geht natürlich auch.

Führt aber beides zum selben Ergebnis: Zur Laufzeit ist's Icon nich mehr da.
smiegel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 992
Erhaltene Danke: 1

WIN 7
D7 Prof., C#, RAD XE Prof.
BeitragVerfasst: Fr 24.01.03 18:26 
Hallo Sivar,

was mir noch aufgefallen ist, in der Create bei der Initialisierung von fNotifyIconData würde ich bei Wnd einmal Application.Handle eintragen.

_________________
Gruß Smiegel
Ich weiß, daß ich nichts weiß, aber ich weiß mehr als die, die nicht wissen, daß sie nichts wissen. (Sokrates)
Sivar Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 40



BeitragVerfasst: Fr 24.01.03 19:17 
Wegen dem Handle:

Ich habe die TNotifyComponent genommen, die hat ihr eigenes Handle. Deshalb habe ich das dort eingetragen. Läuft auch super soweit. Wenn du möchstest kann ich dir die kompo gerne mal komplett geben. Was nur nicht geht ist halt das dumme Icon aus der IDE das ich drinn haben will.
smiegel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 992
Erhaltene Danke: 1

WIN 7
D7 Prof., C#, RAD XE Prof.
BeitragVerfasst: Sa 25.01.03 16:53 
Hallo Sivar,

Zitat:

Wenn du möchstest kann ich dir die kompo gerne mal komplett geben


kannst Du machen.

_________________
Gruß Smiegel
Ich weiß, daß ich nichts weiß, aber ich weiß mehr als die, die nicht wissen, daß sie nichts wissen. (Sokrates)