Autor Beitrag
comes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40



BeitragVerfasst: Mi 10.12.03 17:51 
Hallo!

Ich habe da mein ein kleines Problem!
Ich habe eine neue klasse erstellt und habe in dieser Klasse eine procedure die ich nun auf einen andere umleiten will, leider geht das nicht so wie ich mir das vorgestellt habe. Kann mir da mal bitte jemand weiterhelfen?

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:
type
// meine neue Klasse
  TPlanet = class
    public
      Bild : TImage;
      Bezeichnung : String;
      AnzahlEinwohner : Integer;
      maxEineohner : Integer;
      Besitzer : String;
      Volk : TVolk;
      Rohstoffe : TRohstoffe;
      StationierteSchiffe : TStationierteSchiffe;
      Gebaeude : TGebaeude;
      neutral : boolean;
      procedure onclick(Sender:TObject);

  end;

var
  planet : Tplanet;

procedure TPlanet.onclick(Sender:TObject);
begin
  showmessage('test');
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
 planet.Bild := TImage.Create(self);
 planet.Bild.Parent := self;
 planet.Bild.Picture.LoadFromFile('c:\test.bmp');
 planet.Bild.SetBounds(10,10,20,20);
 planet.Bild.Show;
 planet.bild.onclick := TPlanet.onclick; // <-- das hier geht leider nicht so, wie ich das gern hätte
end;


danke schonmal für eure hilfe


mfg, comes

Moderiert von user profile iconPeter Lustig: Code- durch Delphi-Tags ersetzt
Gandalfus
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 129



BeitragVerfasst: Mi 10.12.03 18:48 
comes hat folgendes geschrieben:

Ich habe eine neue klasse erstellt und habe in dieser Klasse eine procedure

procedure = Methode kann etwas verwirren wen man nicht die richtigen Namen benutzt.

Zu dem Problem:
In object sind noch keine Ereignisse implementiert
du muss von einer Klasse mit Mouse Events erben:

z.B.: TPlanet = class(TGraphicControl);

Da kann man auch noch die paint Methode überschreiben.

mfg

_________________
Wennn man feststellt, dass es drei Moeglichkeiten gibt, die einen Vorgang schiefgehen lassen koennen und man diese ausschaltet, entstehen automatisch drei neue Moeglichkeiten.
Nightmare_82
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 260



BeitragVerfasst: Mi 10.12.03 18:53 
und du mußt planet.onClick nehmen statt TPlanet.onClick.
Du mußt ja das Ereignis einem Objekt und nicht einer Klasse zuweisen.
comes Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40



BeitragVerfasst: Mi 10.12.03 22:36 
Titel: warum?
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:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Image1: TImage;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

type
  TRohstoffe = record
    Uran : boolean;
    cryptonid : boolean;
  end;

type
  TStationierteSchiffe = record
    FrachterKlein : Integer;
    FrachterGross : Integer;
    Kriegsschiffklein : Integer;
    Kriegsschiffgross : Integer;
  end;

type
  TVolk = record
    Krieger : boolean;
    Handelsvolk : boolean;
    Mischvolk : boolean;
  end;

type
  TGebaeude = record
    Kraftwerk : boolean;
    Werft : boolean;
    Schutzschild : boolean;
    Waffensysteme : boolean;
    Forschungsstation : boolean;
    Depot : boolean;
  end;

type
  TPlanet = class(TGraphicControl)
    public
      Bild : TImage;
      Bezeichnung : String;
      AnzahlEinwohner : Integer;
      maxEineohner : Integer;
      Besitzer : String;
      Volk : TVolk;
      Rohstoffe : TRohstoffe;
      StationierteSchiffe : TStationierteSchiffe;
      Gebaeude : TGebaeude;
      neutral : boolean;
 //     procedure onclick(Sender:TObject);

  end;

var
  Form1: TForm1;
  planet : Tplanet;

implementation

{$R *.dfm}

{procedure TPlanet.onclick(Sender:TObject);
begin
  showmessage('test');
end;}


procedure TForm1.Button1Click(Sender: TObject);
begin
 planet.Bild := TImage.Create(Form1); //<-- <--warum bricht der CODE jetzt hier ab? 
 planet.Bild.Parent := self;
 planet.Bild.Picture.LoadFromFile('c:\test.bmp');
 planet.Bild.SetBounds(10,10,20,20);
 planet.Bild.Show;
// planet.bild.onclick := Planet.onclick;
end;

end.

warum bricht das prog hier ab?
kann mir ma plz jemand ein bsp coden, was ich hier verwenden kann?

Moderiert von user profile iconTino: Code- durch Delphi-Tags ersetzt.