Autor Beitrag
Kay E.
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 118



BeitragVerfasst: Do 18.11.10 18:02 
Hallo!

Ich bin gerade dabei, mir einen Typ zu bauen, der im Prinzip ein rechteckiges Bild (60x60 px) darstellt und der noch eine Ereignisbehandlung bekommt, so dass zum Beispiel bei Klick Bild a und bei Rechtsklick Bild b angezeigt wird. Bis jetzt ist der Grundaufbau ohne Ereignis implementiert. Nur: Das Standartbild wird nicht angezeigt. Kann mir bitte jemand zeigen, wo der Fehler liegt?

Hier der Code:
ausblenden volle Höhe Delphi-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:
49:
50:
51:
52:
53:
54:
unit Wiesenfeld;

interface

uses
  SysUtils, Math, Controls, ExtCtrls, Graphics, Classes, jpeg;

type
  TFieldState =(fsEmpty, fsCrystal, fsBottle);

  TWiesenfeld=class(TImage)
  private
    FFieldState:TFieldState;
    function GetState: TFieldState;
    procedure SetState(FieldState:TFieldState);
    procedure SetPicture(Fieldstate:TFieldstate);
  public
    property Fieldstate: TFieldState read GetState write SetState;
    Constructor Create(Owner:TComponent); override;
  end;


implementation

Constructor TWiesenfeld.Create(Owner:TComponent);
begin
  inherited Create(Owner);
  Width:=60;
  Height:=60;
  SetState(fsEmpty);
end;

function TWiesenfeld.GetState: TFieldState;
begin
  result:=FFieldstate;
end;

procedure TWiesenfeld.SetState(FieldState: TFieldState);
begin
  FFieldstate:=Fieldstate;
  SetPicture(FieldState);
  Invalidate;
end;

procedure TWiesenfeld.SetPicture(Fieldstate: TFieldState);
begin
  case FieldState of
    fsEmpty: Picture.LoadFromFile('fsEmpty.jpg');
    fsCrystal: Picture.LoadFromFile('fsCrystal.jpg');
    fsBottle: Picture.LoadFromFile('fsBottle.jpg');
  end;
end;

end.


Danke schonmal für eure Mühen!


Moderiert von user profile iconMartok: Topic aus Delphi Language (Object-Pascal) / CLX verschoben am Do 18.11.2010 um 17:57
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: Do 18.11.10 18:26 
eventuell die relativen Pfadangaben?

probier mal
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TWiesenfeld.SetPicture(Fieldstate: TFieldState);
var path: String;
begin
  path := ExtractFileDir(Application.Filename);
  case FieldState of
    fsEmpty: Picture.LoadFromFile(path + 'fsEmpty.jpg');
    fsCrystal: Picture.LoadFromFile(path + 'fsCrystal.jpg');
    fsBottle: Picture.LoadFromFile(path + 'fsBottle.jpg');
  end;
end;


lg elundril

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.
Kay E. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 118



BeitragVerfasst: Do 18.11.10 18:53 
Hallo elundril,

Nein, das funktioniert auch nicht. Erstens funktioniert ExtractFileDir(Application.Filename) nicht, er bringt mir ne Fehlermeldung undeclared identifier "Application". Und auch wenn ich die uses Units anpasse, dann bekomm ich trotzdem die Meldung, dass es Filename nicht gibt.

Ich hab aber einfach mal einen absoluten Pfad für das Bild angegeben, was aber am Ergebnis nichts geändert hat.

Ich bin also immer noch für jede Idee offen!
Dude566
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1592
Erhaltene Danke: 79

W8, W7 (Chrome, FF, IE)
Delphi XE2 Pro, Eclipse Juno, VS2012
BeitragVerfasst: Do 18.11.10 19:24 
ExtractFilePath(ParamStr(0)) bezeichnet den Ordner in dem deine Anwendung liegt.

_________________
Es gibt 10 Gruppen von Menschen: diejenigen, die das Binärsystem verstehen, und die anderen.
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: Do 18.11.10 19:31 
Ich würde Dir raten satt TImage TGraphicControl zu verwenden und die Bilddaten entweder aus einer zuweisbaren Imagelist zu ziehen oder LoadFromResource zu verwenden.

_________________
Das Problem liegt üblicherweise zwischen den Ohren H₂♂
DRY DRY KISS
Kay E. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 118



BeitragVerfasst: Fr 19.11.10 12:56 
Hab das Problem noch mit euren beiden Vorschlägen angegangen und muss gestehen: Es hat nichts mit der Komponente zu tun, sondern mit der Erzeugung derselbigen. Ich hab vergessen, der Komponente einen Parent zuzuweisen. Nachdem ich das gemacht hab, hats funktioniert - mit jeder dieser Vesionen ;)

Danke an alle!