Autor Beitrag
catweasel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 487
Erhaltene Danke: 1

Win 7 64bit
Delphi 7 Second Sedition V7.2
BeitragVerfasst: Mo 04.09.06 12:34 
Hi,

hmmm da laesst einen das Delphi- Forum nicht mal die Frage im Topic ausschreiben...:
Hier nochmal ohne Steno.. :

Eventhadler zur Objektinstanz einer dynamisch registrierten Klasse hinzufuegen.

Also mein Problem ist folgendes:

Ich moechte yu einem TEdit (oder auch TButton, oder TLabel, etc...) einen Eventhandler zuweisen,
genauer gesagt den OnMouseDown handler.

Wenn ich ein solches Control "normal" erstelle, egal ob zur Destgntime oder runtime, dann klappt es.

z.b.:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
var
mycontrol : TEdit;
begin
mycontrol := TEdit.create(self)<
mycontrol.parent := self;
mycontrol.onmousedown : ownfunction;
end;


.. wobei dann ownfunction der Eventhandler Code ist....

Aaaaaber wenn ich die Klasse erst zur Laufzeit bestimme und den TControl typ, bzw. dessen Referenz benutze, dann geht garnix... :(
Ich probier das so.....:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
type TMyControls = class of TControl;

......

var
newclass : TMyControls;
begin
registerclasses([TEdit,TLabel,TButton]);

newclass := TControl(getclass('TButton')).create(self);
newclass.parent := self;
//  hier will ich nun dem neuen Objekt den Eventhandler verpassen...)

end;


Ich verstehe das nicht. Newclass ist doch vom Typ TMycontrols was wiederum vom Typ TCOntrol ist.
Und TControl hat doch einen OnMousedown handler..... :?

Selbst ein Cast von newclass via :

TControl(newclass).onmousedown... geht nicht... warum ?

was mache ich falsch. :shock:


(Bin gerade dabei sowas wie ne kleine Mini-IDE zu schreiben..... Gibts da irgendwo gute Tutorials zur Delphi Streaming engine......? )

Cheers :-)
Catweasel

_________________
Pommes werden schneller fertig wenn man sie vor dem Frittieren einige Minuten in siedendes Fett legt.
catweasel Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 487
Erhaltene Danke: 1

Win 7 64bit
Delphi 7 Second Sedition V7.2
BeitragVerfasst: Di 05.09.06 12:18 
Hmmm hab selbst noch ein bischen rumprobiert und bin zu folgendem Ergebnis gekommen:

Scheinbar ist der Eventhandler deshalb nicht zugaenglich weil er als protected in TControl definiert ist und erst in Descendants wie TButton, TLabel, etc published wird.....

Andererseits.... Was ich da mit meinem TMyControls typ bezwecke ist doch eigentlich nichts andres als ein "normaler" Klassen-hack...
Warum nur geht das nicht???

Gibts denn hier niemand der sich mit sowas auskennt ?
(Zu Luckie und TUFKAPL schiel .... )

Catweawel

_________________
Pommes werden schneller fertig wenn man sie vor dem Frittieren einige Minuten in siedendes Fett legt.
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Di 05.09.06 15:44 
*angesprochen fühl*

Mach doch einfach in deiner Hack-Klasse ein
ausblenden Delphi-Quelltext
1:
2:
3:
4:
...
published
  property OnMouseDown;
....


EDIT: Mal davon abgesehen, dass ein Class-Hack anders aussieht, dann braucst du das andere auch nicht mehr:
ausblenden Delphi-Quelltext
1:
2:
Type
  TMyControl=class(TControl);


Also ohne das 'of'.

Martok

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."