Autor Beitrag
Stoffel1984
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 219

Win NT, Win 2000
D6 Prof
BeitragVerfasst: So 18.09.05 15:40 
Hallo,
kann mir bitte jemand sagen, wie ich
ausblenden Delphi-Quelltext
1:
2:
3:
4:
var
  Sec: string;
begin
  Sec := (Sender as TTimer).Name;

ohne Fehlermeldung abarbeiten kann?
worm
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 135


D6 Prof
BeitragVerfasst: So 18.09.05 15:55 
Was für ein Fehler erscheint denn? Laut Profil hast Du Delphi 6 Pro, und dort ist type TComponentName = type String und Dein Beispiel funktioniert einwandfrei.

_________________
In the beginning, the universe was created. This has made a lot of people very angry, and is generally considered to have been a bad move.
Stoffel1984 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 219

Win NT, Win 2000
D6 Prof
BeitragVerfasst: So 18.09.05 17:16 
Ich bekomme beim Ausführen des Programms eine Exception vom Typ Invalid Class Typecast.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: So 18.09.05 17:28 
Mach mal MessageDlg(TComponent(Sender).Name + ': ' + TComponent(Sender).ClassName, mtInformation, [mbOK], 0); und sag dann, ob dort der richtige Typ raus kommt. Ich glaub's mal nicht.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Stoffel1984 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 219

Win NT, Win 2000
D6 Prof
BeitragVerfasst: So 18.09.05 17:36 
Ach klar ich bekomme ich Form..

Wie schaffe ich es nochmal, die aufrufende Komponente heraus zu bekommen?
worm
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 135


D6 Prof
BeitragVerfasst: So 18.09.05 17:47 
Erstmal eine Erklärung des Problems oben:
Wenn Du Sender as TTimer benutzt, wird vorher eine Typüberprüfung vorgenommen und es gibt eine Exception, wenn Sender nicht vom Typ TTimer oder einem Erben von TTimer ist - obwohl Du das Name-property auch mit z.B. einem TButton nutzen kannst (alles was von TComponent abstammt). Mit Sender as TComponent sollte Dein Beispiel klappen.
(Nicht empfohlen, aber möglich, wäre auch eine Umgehung der Typüberprüfung mit TComponent(Sender). Das solltest Du aber nur einsetzen, wenn es auf Geschwindigkeit ankommt und Du 100%ig sicher sein kannst, kein Objekt einer inkompatiblen Klasse vor Dir zu haben.)

Zu Deiner Frage: Sender liefert Dir doch die aufrufende Komponente? Oder was meintest Du?

_________________
In the beginning, the universe was created. This has made a lot of people very angry, and is generally considered to have been a bad move.
Stoffel1984 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 219

Win NT, Win 2000
D6 Prof
BeitragVerfasst: So 18.09.05 18:00 
Das Problem ist, ich habe einen Timer zur Laufzeit erstellt und dieser bekommt zur Laufzeit einen Eventhandler zugewiesen. frmMain.OnTimer.

Wenn ketzt OnTimer ausgeführt wird erhalte ich frmMain als Sender, hätte aber gerne den Timer