Autor Beitrag
delphisual
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 89

WIN 2000
D5 Prof
BeitragVerfasst: Fr 30.01.04 23:35 
Hallo zusammen,

wie kann man für ein Objekt der von Klasse TObject abgeleitet wurde ein Ereignis schreiben? :?:
z.B.: onClick-Ereignis.

Mit freundlichen Grüßen
delphisual

_________________
(Wer ein Problem definiert, hat es schon halb gelöst.)
derDoc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 623

Win Vista Prof
D2007 Prof
BeitragVerfasst: Sa 31.01.04 10:02 
Du musst in der Typdeklaration ein published einfügen. Dann benötigst du folgende Zeilen:
ausblenden Delphi-Quelltext
1:
property OnCustomBtnsClick : TButtonClickEvent read GetOnBtnClick write SetOnBtnClick;					

und unter private musst du dann noch das hier schreiben
ausblenden Delphi-Quelltext
1:
2:
function GetOnBtnClick() : TButtonClickEvent;
procedure SetOnBtnClick(const Value : TButtonClickEvent);


Ich hoffe, dass es kein TButtonClickEvent gibt, denn das musst du dann noch definieren.

Das machst du dann so
ausblenden Delphi-Quelltext
1:
TButtonClickEvent = procedure (Sender : TObject; ButtonIndex : Integer) of object;					


Das hier war nur ein Beispiel, damit du weißt, was du machen musst. Ich gehe nicht davon aus, dass es bei dir mit meinen Auszügen funktioniert.

Wenn du die normalen Ereignisse benutzen willst kannst du auch einfach unter published property OnClick; einfügen.

_________________
MfG derDoc
There are only 10 types of people: those who understand binary and those who don't.
delphisual Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 89

WIN 2000
D5 Prof
BeitragVerfasst: So 01.02.04 19:30 
danke derDoc,
ist ein hartes Stück Brot ich versuche mich da durchzubeißen.

Wenn jemand etwas dazu beitragen möchte würde ich mich freuen.
Am besten wäre ein kleines funktionales Beispiel anhand einer abgeleiteter Klasse von TObject.

gruß an Alle
delphisual

_________________
(Wer ein Problem definiert, hat es schon halb gelöst.)
Alexander F
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 149

Win XP, Win 2000
D6 PE, D7 Prof, D8 Prof
BeitragVerfasst: So 01.02.04 21:07 
Hallo,
ich kann dir zwar nicht direkt helfen, aber da du eine Professional-Version, kannst du in die Sourcen der Komponente (ab)kucken ;-)
Einfach mal in den Source-Ordner im Delphi-Verzeichnis schauen.
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Mo 02.02.04 13:02 
Du könntest dir mal meine OOP-Ausarbeitung anschaun ob dir die vielleicht ein bisschen weiterhilft: www.x-spy.net/personal bzw falls die Domain bei dir nicht funktioniert probier die Subdomain motzi.fs-tools.de/personal

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
delphisual Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 89

WIN 2000
D5 Prof
BeitragVerfasst: Mo 02.02.04 23:00 
Vielen Dank an Alle,
ich hoffe dass mein Ergebnis das widerspiegelt was Ihr versucht habt mir zu erklären.
Die auf dem Punkt gebrachte Ausarbeitung von Motzi hat mir den entscheidenden Anstoß gegeben den Code zu vollenden.
Hier die Gesamtcode die zumindest schon mal funktional ist:

Unit des Objektes:
ausblenden 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:
unit myObject; 

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

type
  // selbst deklariertes Ereignis
  TEreignisstruktur=procedure(Sender:TObject) of object;

  TMyObject=class
   private
     fEreignis: TEreignisstruktur;
     procedure DoEreignis;
   public
     property  OnEreignis:TEreignisstruktur read fEreignis write fEreignis;
end// TMyObject

implementation

procedure TMyObject.DoEreignis;
begin
  if Assigned(fEreignis) then fEreignis(Self);
end;


Haupt-Unit:
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:
unit Unit1;

interface

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

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

var
  TestObject: TmyObject;
  Form1: TForm1;


implementation

{$R *.DFM}



procedure TForm1.tuwas(Sender: TObject);
begin
ShowMessage('Na endlich!');
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
TestObject:=TmyObject.Create;
with TestObject do
  begin
    OnEreignis:=tuwas;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
TestObject.OnEreignis(self);
end;

end.


Wenn jemand einen Fehler sehen sollte hoffe ich dass der mir mitgeteilt wird.
Mit freundlichen Grüßen
delphisual

Moderiert von user profile iconUGrohne: Code- durch Delphi-Tags ersetzt

_________________
(Wer ein Problem definiert, hat es schon halb gelöst.)
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Di 03.02.04 13:37 
Abgesehen von einer für mich etwas ungewohnten Vergabe von Variablen-/Klassennamen und Code-Formatierung... stimmt alles! 8)

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!