<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Timer-&amp;gt;OnTimer - Event abfangen]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich habe folgenden Code:</p>
<pre><code>void __fastcall TForm1::Button1Click(TObject *Sender)
{
   TTimer *timer = new TTimer(this);

   timer-&gt;Interval = 6000;
   timer-&gt;Enabled  = true;

}
</code></pre>
<p>Wie kann ich jetzt das OnTimer-Ereignis abfangen??</p>
<p>Meine Frage ist nur wie ich das im Quellcode definieren muss??</p>
<p>So ungefähr??:</p>
<pre><code>void timer::OnTimer()
{

}
</code></pre>
<p>DANKE</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/153475/timer-gt-ontimer-event-abfangen</link><generator>RSS for Node</generator><lastBuildDate>Mon, 10 Aug 2026 11:43:46 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/153475.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 17 Jul 2006 13:37:53 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Timer-&amp;gt;OnTimer - Event abfangen on Mon, 17 Jul 2006 13:37:53 GMT]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich habe folgenden Code:</p>
<pre><code>void __fastcall TForm1::Button1Click(TObject *Sender)
{
   TTimer *timer = new TTimer(this);

   timer-&gt;Interval = 6000;
   timer-&gt;Enabled  = true;

}
</code></pre>
<p>Wie kann ich jetzt das OnTimer-Ereignis abfangen??</p>
<p>Meine Frage ist nur wie ich das im Quellcode definieren muss??</p>
<p>So ungefähr??:</p>
<pre><code>void timer::OnTimer()
{

}
</code></pre>
<p>DANKE</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1099194</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1099194</guid><dc:creator><![CDATA[skluge]]></dc:creator><pubDate>Mon, 17 Jul 2006 13:37:53 GMT</pubDate></item><item><title><![CDATA[Reply to Timer-&amp;gt;OnTimer - Event abfangen on Mon, 17 Jul 2006 13:55:57 GMT]]></title><description><![CDATA[<p>wieso nimmst nicht die nichtvisuelle komponente, platzierst sie, und schaust dir den generierten code mal an?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1099210</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1099210</guid><dc:creator><![CDATA[ser1al]]></dc:creator><pubDate>Mon, 17 Jul 2006 13:55:57 GMT</pubDate></item><item><title><![CDATA[Reply to Timer-&amp;gt;OnTimer - Event abfangen on Mon, 17 Jul 2006 13:58:19 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">void __fastcall TForm1::Button1Click(TObject *Sender)
{
   TTimer *timer = new TTimer(this);

   timer-&gt;Interval = 6000;
   timer-&gt;Enabled  = true;
   timer-&gt;OnTimer  = OnTimer;
} 

void __fastcall TForm1::OnTimer(TObject *Sender)  // mußt du dann auch in form1.h deklarieren
{
   // hier dein Timer Code
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1099211</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1099211</guid><dc:creator><![CDATA[~Th]]></dc:creator><pubDate>Mon, 17 Jul 2006 13:58:19 GMT</pubDate></item><item><title><![CDATA[Reply to Timer-&amp;gt;OnTimer - Event abfangen on Tue, 18 Jul 2006 08:50:28 GMT]]></title><description><![CDATA[<blockquote>
<p>void __fastcall TForm1::Button1Click(TObject *Sender)<br />
{<br />
TTimer *timer = new TTimer(this);</p>
<p>timer-&gt;Interval = 6000;<br />
timer-&gt;Enabled = true;<br />
timer-&gt;OnTimer = OnTimer;<br />
}</p>
</blockquote>
<p>So wird das nicht funktionieren, da nach verlassen des Scopes von Button1Click dein Timer nicht mehr existiert.<br />
Wenn schon dann so:</p>
<p>Unit1.h</p>
<pre><code class="language-cpp">//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include &lt;Classes.hpp&gt;
#include &lt;Controls.hpp&gt;
#include &lt;StdCtrls.hpp&gt;
#include &lt;Forms.hpp&gt;
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:	// Von der IDE verwaltete Komponenten
   TButton *Button1;
   TEdit *Edit1;
   void __fastcall FormCreate(TObject *Sender);
   void __fastcall Button1Click(TObject *Sender);
   void __fastcall FormClose(TObject *Sender, TCloseAction &amp;Action);
private:	// Anwender-Deklarationen
   TTimer *timer;
   void __fastcall OnTimer(TObject *Sender);
public:		// Anwender-Deklarationen
   __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
</code></pre>
<p>Unit1.cpp</p>
<pre><code class="language-cpp">void __fastcall TForm1::FormCreate(TObject *Sender)
{
   timer=NULL;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
   delete timer;
   timer=new TTimer(this);
   timer-&gt;Interval = 6000;
   timer-&gt;OnTimer = OnTimer;
   timer-&gt;Enabled = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::OnTimer(TObject *Sender)
{
   //Mach was
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1099603</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1099603</guid><dc:creator><![CDATA[teatimer]]></dc:creator><pubDate>Tue, 18 Jul 2006 08:50:28 GMT</pubDate></item><item><title><![CDATA[Reply to Timer-&amp;gt;OnTimer - Event abfangen on Tue, 18 Jul 2006 12:51:22 GMT]]></title><description><![CDATA[<p>Natürlich existiert der Timer auch weiterhin (nur gibt es keinen Zeiger darauf, um den Timer zu löschen).<br />
Aber @Teatime, dein Code ist so natürlich richtig, wenn man nur einen Timer haben will, aber vielleicht möchte man ja mehrere Timer mit dem Buttno erstellen, dann müßte man nur noch die Timer in einen vector stellen bzw. bei Schließen des Forms werden die Timer dann ja automatisch entfernt (da die Form mit &quot;this&quot; als Owner angegeben wurde).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1099791</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1099791</guid><dc:creator><![CDATA[Th]]></dc:creator><pubDate>Tue, 18 Jul 2006 12:51:22 GMT</pubDate></item><item><title><![CDATA[Reply to Timer-&amp;gt;OnTimer - Event abfangen on Tue, 18 Jul 2006 13:01:58 GMT]]></title><description><![CDATA[<p>rofl</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1099799</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1099799</guid><dc:creator><![CDATA[ser1al]]></dc:creator><pubDate>Tue, 18 Jul 2006 13:01:58 GMT</pubDate></item><item><title><![CDATA[Reply to Timer-&amp;gt;OnTimer - Event abfangen on Mon, 28 Aug 2006 06:28:29 GMT]]></title><description><![CDATA[<p>Hallo zusammen,<br />
ich habe das gleiche Problem wie &quot;skluge&quot;, allerdings erstelle ich den Timer in der Funtion einer Klasse und er wird auch nur dort benötigt!</p>
<p>wie kann ich also das OnTimer event abfangen??</p>
<p>Vielen Dank</p>
<p>mfg hans</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1125858</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1125858</guid><dc:creator><![CDATA[hansB.two]]></dc:creator><pubDate>Mon, 28 Aug 2006 06:28:29 GMT</pubDate></item><item><title><![CDATA[Reply to Timer-&amp;gt;OnTimer - Event abfangen on Mon, 28 Aug 2006 07:24:07 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>genauso wie du es bei einer Form machen würdest. Also brauchst du eine Funktion mit dem Prototyp</p>
<pre><code class="language-cpp">void __fastcall MyClass::OnTimer(TObject *Sender)
</code></pre>
<p>die du als Methode an den Timerevent übergeben kannst.</p>
<p>bis bald<br />
akari</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1125875</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1125875</guid><dc:creator><![CDATA[akari]]></dc:creator><pubDate>Mon, 28 Aug 2006 07:24:07 GMT</pubDate></item><item><title><![CDATA[Reply to Timer-&amp;gt;OnTimer - Event abfangen on Mon, 28 Aug 2006 08:06:55 GMT]]></title><description><![CDATA[<p>Dnake sehr. Ich habs mit allen hier gegebenen Informatiunen hingekriegt!</p>
<p>mfg hans</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1125895</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1125895</guid><dc:creator><![CDATA[hansB.two]]></dc:creator><pubDate>Mon, 28 Aug 2006 08:06:55 GMT</pubDate></item></channel></rss>