<?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[Auf Parent der CheckBox zugreifen]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich möchte auf das Parent(Panel) eines Objects ,hier CheckBox, zugreifen und<br />
dessen Caption lesen.<br />
Wie stell ich so was an?</p>
<p>(((TCheckBox*)AlarmCheck-&gt;Items[Cb+(Index*5)])-&gt;Parent-&gt;? == &quot;Reserved&quot;)</p>
<p>((TCheckBox*)AlarmCheck-&gt;Items[Cb+(Index*5)])-&gt;(TPanel*)Parent-&gt;Caption == &quot;Reserved&quot;)<br />
geht ebenfalls nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/162033/auf-parent-der-checkbox-zugreifen</link><generator>RSS for Node</generator><lastBuildDate>Tue, 11 Aug 2026 17:33:58 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/162033.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 13 Oct 2006 20:17:30 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Auf Parent der CheckBox zugreifen on Fri, 13 Oct 2006 20:21:52 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich möchte auf das Parent(Panel) eines Objects ,hier CheckBox, zugreifen und<br />
dessen Caption lesen.<br />
Wie stell ich so was an?</p>
<p>(((TCheckBox*)AlarmCheck-&gt;Items[Cb+(Index*5)])-&gt;Parent-&gt;? == &quot;Reserved&quot;)</p>
<p>((TCheckBox*)AlarmCheck-&gt;Items[Cb+(Index*5)])-&gt;(TPanel*)Parent-&gt;Caption == &quot;Reserved&quot;)<br />
geht ebenfalls nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1154349</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1154349</guid><dc:creator><![CDATA[hermes]]></dc:creator><pubDate>Fri, 13 Oct 2006 20:21:52 GMT</pubDate></item><item><title><![CDATA[Reply to Auf Parent der CheckBox zugreifen on Fri, 13 Oct 2006 21:52:43 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>da ist immer erstmal günstiger, Schritt für Schritt durchzugehen (soweit ich den Sinn verstanden habe).<br />
Und vor allem C++ Casts zu verwenden</p>
<pre><code class="language-cpp">TCheckBox* checkbox = static_cast&lt;TCheckBox*&gt;(AlarmCheck-&gt;Items[Cb+(Index*5)]); // was ist AlarmCheck? Was gibt Items zurück? cast vielleicht unnötig
TPanel* panel = static_cast&lt;TPanel*&gt;(checkbox-&gt;Parent);
panel-&gt;Caption = &quot;Reserved&quot;;
</code></pre>
<p>Zusammensetzen kannst du es nun selber, aber ich denke das es zu unübersichtlich wird.<br />
Übrigens ist == kein Operator zum Lesen eines Wertes.</p>
<p>bis bald<br />
akari</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1154397</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1154397</guid><dc:creator><![CDATA[akari]]></dc:creator><pubDate>Fri, 13 Oct 2006 21:52:43 GMT</pubDate></item><item><title><![CDATA[Reply to Auf Parent der CheckBox zugreifen on Sun, 15 Oct 2006 11:33:17 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>ich glaube, ich habe das ganze etwas aus dem Zusammenhang geriessen.</p>
<p>Ich erzeuge mir dynamisch eine GroupBox und in der Box Panels auf denen<br />
immer 5 CheckBoxen instanziert werden.</p>
<p>Dieses passiert in der Funktion<br />
DrawAlarmList(AnsiString BoxName, unsigned char Mask,const char * List)<br />
hier ist BoxName der Name der GroupBox.<br />
List beinhaltete die Captions der einzelnen Panels.<br />
Mask gibt an welche der 5 CheckBoxenauf dem Panel Enabled sein sollen.<br />
Die CheckBoxen sollen ebenfalls nicht enabled sein wenn das Caption des<br />
Panels auf dem sie sich befinden &quot;Reserved&quot; ist.Bei der Abfrage gibt es eine<br />
Fehler Meldung.</p>
<pre><code class="language-cpp">if( !((1&lt;&lt;Cb)&amp;Mask)
            || ( ((TCheckBox*)AlarmCheck-&gt;Items[Cb+(Index*5)])-&gt;(TPanel*)Parent-&gt;Caption == &quot;Reserved&quot;) )
            {
                ((TCheckBox*)AlarmCheck-&gt;Items[Cb+(Index*5)])-&gt;Enabled          = false;
            }
</code></pre>
<p>Das ganze sieht dann so aus.</p>
<pre><code class="language-cpp">//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
void __fastcall TRelayData::FormCreate(TObject *Sender)
{
	const char SupplyAlarmList[] =
     {
		&quot;AC MAINS L1 FAIL            &quot;&quot;\0&quot;
		&quot;AC MAINS L2 FAIL            &quot;&quot;\0&quot;
		&quot;AC MAINS L3 FAIL            &quot;&quot;\0&quot;
		&quot;DC OVERVOLTAGE              &quot;&quot;\0&quot;
		&quot;DC UNDERVOLTAGE             &quot;&quot;\0&quot;
		&quot;POWER LIMIT                 &quot;&quot;\0&quot;
		&quot;MODULE OVERTEMP             &quot;&quot;\0&quot;
		&quot;MODUL1 FAIL                 &quot;&quot;\0&quot;
		&quot;MODUL2 FAIL                 &quot;&quot;\0&quot;
		&quot;MODUL3 FAIL                 &quot;&quot;\0&quot;
		&quot;MODUL4 FAIL                 &quot;&quot;\0&quot;
		&quot;ALARM1                      &quot;&quot;\0&quot;
		&quot;ALARM2                      &quot;&quot;\0&quot;
		&quot;ALARM3                      &quot;&quot;\0&quot;
		&quot;ALARM4                      &quot;&quot;\0&quot;
		&quot;ALARM5                      &quot;&quot;\0&quot;
		&quot;ALARM6                      &quot;&quot;\0&quot;
		&quot;ALARM7                      &quot;&quot;\0&quot;
		&quot;ALARM8                      &quot;&quot;\0&quot;&quot;\0&quot;
     };
	const char UltraCapList[] =
     {
		&quot;OVERTEMP	                   &quot;&quot;\0&quot;
		&quot;SYMMETRIE ERROR             &quot;&quot;\0&quot;
		&quot;Reserved                    &quot;&quot;\0&quot;&quot;\0&quot;
     };
	const char InverterList[] =
     {
		&quot;Reserved                    &quot;&quot;\0&quot;
		&quot;Reserved                    &quot;&quot;\0&quot;
		&quot;Reserved                    &quot;&quot;\0&quot;
		&quot;Reserved                    &quot;&quot;\0&quot;
    		&quot;Reserved               	    &quot;&quot;\0&quot;&quot;\0&quot;
     };
	const char Hallo[] =
     {
		&quot;bbbbbbbbbb                  &quot;&quot;\0&quot;
		&quot;aaaaaaa                     &quot;&quot;\0&quot;
    		&quot;RESERVE                	    &quot;&quot;\0&quot;&quot;\0&quot;
     };
     DrawAlarmList(&quot;Supply&quot;,0x13,SupplyAlarmList);
     DrawAlarmList(&quot;EnergieBlock&quot;,0x13,UltraCapList);
     DrawAlarmList(&quot;Reserve&quot;,0x13,InverterList);
	((TPanel*)Alarme-&gt;Items[0])-&gt;Color = clYellow;
}
//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
void TRelayData::DrawAlarmList(AnsiString BoxName, unsigned char Mask,const char * List)
{
	#define BOX_WIDTH 		740
     #define PANEL_TOP 		20
     #define PANEL_LEFT 		10
     #define PANEL_HEIGHT 	20
     #define PANEL_WIDTH      700
     #define CHECK_BOX_LEFT   500
     #define CHECK_BOX_STEP   30
     #define ENABLE 0x1f
	static int LastTopPos = 21;
     static int LastIndex  = 0;
     //Bei der ersten AlarmBox &quot;AlarmPanel sowie CheckBox&quot; - Listen instanzieren
     if(LastIndex == 0)
     {
		Alarme 		     = new TList;
		AlarmCheck 		= new TList;
    		Alarme-&gt;Count 		= 500;
	    	AlarmCheck-&gt;Count 	= 500;
	}
	ListLenght 		= 0;
     while(List[ListLenght*29] != 0)ListLenght++;;
     //Neu Box erzeugen
	AlarmBox 			= new TGroupBox((TComponent*)this);
    	AlarmBox-&gt;Parent	= Gesamt;
    	AlarmBox-&gt;Caption 	= BoxName;
    	AlarmBox-&gt;Width 	= BOX_WIDTH;
     AlarmBox-&gt;Height 	= ((ListLenght+1)*PANEL_HEIGHT)+10;
     AlarmBox-&gt;Left 	= 10;
     AlarmBox-&gt;Top 		= LastTopPos;
     LastTopPos	    	+= AlarmBox-&gt;Height+1;
     AlarmBox-&gt;Visible 	= true;
     //--------------------------------------------
	TextIndex = 0;
     for(int Index = LastIndex; Index &lt; (ListLenght+LastIndex); Index++)
     {
     	//Panels erzeugen
     	Alarme-&gt;Items[Index] 					= new TPanel((TComponent*)this);
     	((TPanel*)Alarme-&gt;Items[Index])-&gt;Parent 	= AlarmBox;
     	((TPanel*)Alarme-&gt;Items[Index])-&gt;Alignment 	= taLeftJustify;
     	((TPanel*)Alarme-&gt;Items[Index])-&gt;Height  	= PANEL_HEIGHT;
     	((TPanel*)Alarme-&gt;Items[Index])-&gt;Width   	= PANEL_WIDTH;
     	((TPanel*)Alarme-&gt;Items[Index])-&gt;Top     	= PANEL_TOP+(TextIndex*20);
     	((TPanel*)Alarme-&gt;Items[Index])-&gt;Left	  	= PANEL_LEFT;
     	((TPanel*)Alarme-&gt;Items[Index])-&gt;Caption 	= AnsiString().sprintf(&quot; %3d&quot;,Index)+&quot;  &quot;+ (List+(TextIndex*29));   //
          ((TPanel*)Alarme-&gt;Items[Index])-&gt;OnMouseMove = MouseOnPanel;
          ((TPanel*)Alarme-&gt;Items[Index])-&gt;DoubleBuffered = true;
     	((TPanel*)Alarme-&gt;Items[Index])-&gt;Visible 	= true;
          //CheckBoxen erzeugen
          for(int Cb = 0; Cb &lt;= 4; Cb++)
          {
          	AlarmCheck-&gt;Items[Cb+(Index*5)] = new TCheckBox((TComponent*)this);
		   	((TCheckBox*)AlarmCheck-&gt;Items[Cb+(Index*5)])-&gt;OnClick 			= CheckBoxClick;
		   	((TCheckBox*)AlarmCheck-&gt;Items[Cb+(Index*5)])-&gt;OnMouseMove		  	= MouseOnPanel;
 	     	((TCheckBox*)AlarmCheck-&gt;Items[Cb+(Index*5)])-&gt;Parent 				= ((TPanel*)Alarme-&gt;Items[Index]);
		 	((TCheckBox*)AlarmCheck-&gt;Items[Cb+(Index*5)])-&gt;Top				= 1;
               ((TCheckBox*)AlarmCheck-&gt;Items[Cb+(Index*5)])-&gt;Left   				= CHECK_BOX_LEFT+(Cb*CHECK_BOX_STEP);
			((TCheckBox*)AlarmCheck-&gt;Items[Cb+(Index*5)])-&gt;Width 				= 15;
//Zeiger auf Ram Array sowie die Maske
			((TCheckBox*)AlarmCheck-&gt;Items[Cb+(Index*5)])-&gt;Tag          		= (Index&lt;&lt;16)|1&lt;&lt;Cb;
			if( !((1&lt;&lt;Cb)&amp;Mask)
			|| ( ((TCheckBox*)AlarmCheck-&gt;Items[Cb+(Index*5)])-&gt;(TPanel*)Parent-&gt;Caption == &quot;Reserved&quot;) )
			{
				((TCheckBox*)AlarmCheck-&gt;Items[Cb+(Index*5)])-&gt;Enabled      	= false;
			}
			((TCheckBox*)AlarmCheck-&gt;Items[Cb+(Index*5)])-&gt;DoubleBuffered		= true;
			((TCheckBox*)AlarmCheck-&gt;Items[Cb+(Index*5)])-&gt;Visible				= true;
          }
          TextIndex++;
	}
	LastIndex += ListLenght;
     AllAlerts	= LastIndex;
}
</code></pre>
<p>Das ganze etwas vereinfacht.</p>
<pre><code class="language-cpp">void __fastcall TForm1::FormCreate(TObject *Sender)
{
	TPanel *Panel  = new TPanel((TComponent*)this);
	Panel-&gt;Parent  = this;
	Panel-&gt;Caption = &quot;Reserved&quot;;
	TCheckBox *CheckBox = new TCheckBox((TComponent*)this);
	CheckBox-&gt;Parent	= Panel;
     if(CheckBox-&gt;(TPanel*)Parent-&gt;Caption == &quot;Reserved&quot;)
	    	CheckBox-&gt;Enabled = true;
}
</code></pre>
<p>Hier kommt eine Fehlermeldung &quot;Elemente Bezeichner erwartet&quot;.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1155030</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1155030</guid><dc:creator><![CDATA[hermes]]></dc:creator><pubDate>Sun, 15 Oct 2006 11:33:17 GMT</pubDate></item><item><title><![CDATA[Reply to Auf Parent der CheckBox zugreifen on Mon, 16 Oct 2006 11:23:46 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>Du hast scheinbar das Prinzip des Castens noch nicht richtig verstanden.<br />
Mit</p>
<pre><code class="language-cpp">(TComponent*)TestKomponente
</code></pre>
<p>wandelst du einen den die Variable TestKomponente in eine Variable vom Typ Zeiger auf TComponent um. Das geschieht hier ohne Typprüfung (da C-Style Cast).<br />
1. Verwende C++-Style Casts (static_cast, dynamic_cast) statt deinen C-Style<br />
<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-39493.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-t-is-39493.html</a><br />
<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-39463.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-t-is-39463.html</a><br />
2. Caste nur wenn es nötig ist.</p>
<pre><code class="language-cpp">TPanel *Panel  = new TPanel((TComponent*)this);
</code></pre>
<p>Warum castest du hier this in TComponent?<br />
3. Wenn du die zu castende Variable mehrfach benötigst erzeuge dir eine temporäre Variable und verwende dann diese<br />
Bsp. statt</p>
<pre><code class="language-cpp">((TPanel*)Alarme-&gt;Items[Index])-&gt;Parent     = AlarmBox;
((TPanel*)Alarme-&gt;Items[Index])-&gt;Alignment     = taLeftJustify;
((TPanel*)Alarme-&gt;Items[Index])-&gt;Height      = PANEL_HEIGHT;
((TPanel*)Alarme-&gt;Items[Index])-&gt;Width       = PANEL_WIDTH;
((TPanel*)Alarme-&gt;Items[Index])-&gt;Top         = PANEL_TOP+(TextIndex*20);
((TPanel*)Alarme-&gt;Items[Index])-&gt;Left          = PANEL_LEFT;
</code></pre>
<p>lieber</p>
<pre><code class="language-cpp">TPanel* panel = dynamic_cast&lt;TPanel*&gt;(Alarme-&gt;Items[Index]);
if( panel )
{
   panel-&gt;Parent     = AlarmBox;
   panel-&gt;Alignment     = taLeftJustify;
   panel-&gt;Height      = PANEL_HEIGHT;
   panel-&gt;Width       = PANEL_WIDTH;
   panel-&gt;Top         = PANEL_TOP+(TextIndex*20);
   panel-&gt;Left          = PANEL_LEFT;
// usw.
</code></pre>
<p>4. Was soll das hier</p>
<pre><code class="language-cpp">if(CheckBox-&gt;(TPanel*)Parent-&gt;Caption == &quot;Reserved&quot;)
     CheckBox-&gt;Enabled = true;
</code></pre>
<p>Das Cast ist hier falsch positioniert</p>
<pre><code class="language-cpp">TPanel* panel = dynamic_cast&lt;TPanel*&gt;(CheckBox-&gt;Parent);
if(panel &amp;&amp; panel-&gt;Caption == &quot;Reserved&quot;)
         CheckBox-&gt;Enabled = true;
</code></pre>
<p>oder hier besser gleich</p>
<pre><code class="language-cpp">if(Panel-&gt;Caption == &quot;Reserved&quot;)
     CheckBox-&gt;Enabled = true;
</code></pre>
<p>Belies dich bitt auch ein wenig bezüglich Polymorphie<br />
<a href="http://www.tutorialpage.de/Cpp2/index.php?ziel=http://www.tutorialpage.de/Cpp2/chap5.php" rel="nofollow">http://www.tutorialpage.de/Cpp2/index.php?ziel=http://www.tutorialpage.de/Cpp2/chap5.php</a><br />
<a href="http://www.volkard.de/vcppkold/polymorphie.html" rel="nofollow">http://www.volkard.de/vcppkold/polymorphie.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1155625</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1155625</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Mon, 16 Oct 2006 11:23:46 GMT</pubDate></item><item><title><![CDATA[Reply to Auf Parent der CheckBox zugreifen on Fri, 20 Oct 2006 00:10:07 GMT]]></title><description><![CDATA[<p>Danke für die Hilfe, werde mich näher damit beschäftigen.</p>
<blockquote>
<p>Du hast scheinbar das Prinzip des Castens noch nicht richtig verstanden.</p>
</blockquote>
<p>Ich denke schon</p>
<p>unsigned char Buffer[2];<br />
unsigned short Test = (unsigned short)((Buffer[1]&lt;&lt;8)&amp;0xff00) | (unsigned short)(Buffer[0] &amp; 0xff);</p>
<p>Ich Caste hier für diese Operation Buffer auf unsigned short.</p>
<blockquote>
<p>TPanel *Panel = new TPanel((TComponent*)this);<br />
Warum castest du hier this in TComponent?</p>
</blockquote>
<p>Du hast recht, ich habe das ganze gerade probiert<br />
TPanel *Panel = new TPanel(this);<br />
irgendwie ist der Cast da reingewandert, weil die Fehlermeldung<br />
Mehrdeutigkeit zwischen ...... kam, kann das ganze aber nicht mehr nachvollziehen<br />
da der Fehler nun nicht mehr auftritt.<br />
Irgenwie habe ich bei dem Object 3 Konstruktoren zur Auswahl unter anderem<br />
einen mit dem Übergabeparameter TComponent *Owner, deswegen habe ich gecastet und der Fehler kam nicht mehr.</p>
<p>Zum dynamic_cast, hier caste ich den Pointer Sender dynamisch ist Sender nicht<br />
vom Datentyp TPanel wird ein NULL Pointer zurückgegeben.</p>
<pre><code class="language-cpp">void _fastcall TRelayData::MouseOnPanel(TObject *Sender, TShiftState Shift,
      int X, int Y)
{
	TPanel *Panel = dynamic_cast&lt;TPanel*&gt;(Sender);
     if(!Panel)
     {
         //Wenn nicht Panel dann war der Auslöser ein Object das das 
         //Panel als Parent hat. 
         Panel = dynamic_cast&lt;TPanel*&gt;(((TControl*)Sender)-&gt;Parent);
     }
</code></pre>
<p>Wie gesagt, ich kann mir immer noch nicht erklären wie Oben der Fehler<br />
Mehrdeutigkeit zwischen ...... kam.</p>
<blockquote>
<p>Das Cast ist hier falsch positioniert</p>
<pre><code class="language-cpp">TPanel* panel = dynamic_cast&lt;TPanel*&gt;(CheckBox-&gt;Parent);
if(panel &amp;&amp; panel-&gt;Caption == &quot;Reserved&quot;)
         CheckBox-&gt;Enabled = true;	

TPanel* panel = dynamic_cast&lt;TPanel*&gt;(CheckBox-&gt;Parent);
if(panel &amp;&amp; panel-&gt;Caption == &quot;Reserved&quot;)
CheckBox-&gt;Enabled = true;	

TPanel* panel = dynamic_cast&lt;TPanel*&gt;(CheckBox-&gt;Parent);
if(panel &amp;&amp; panel-&gt;Caption == &quot;Reserved&quot;)
         CheckBox-&gt;Enabled = true;	

oder hier besser gleich

if(Panel-&gt;Caption == &quot;Reserved&quot;)
     CheckBox-&gt;Enabled = true;	

if(Panel-&gt;Caption == &quot;Reserved&quot;)
CheckBox-&gt;Enabled = true;	

if(Panel-&gt;Caption == &quot;Reserved&quot;)
     CheckBox-&gt;Enabled = true;
</code></pre>
</blockquote>
<p>Ok sieht gut aus. Meine Idee war CheckBox-&gt;Parent, hier ist Parent ja ein Objectzeiger auf das Parent(Panel) von CheckBox, über diesen Zeiger kann ich dann<br />
doch gecastet auf den Datentypen TPanel* auf dessen Caption zugreifen oder.<br />
Ist das nicht analog zu Panel-&gt;Caption?</p>
<blockquote>
<p>3. Wenn du die zu castende Variable mehrfach benötigst erzeuge dir eine temporäre Variable und verwende dann diese<br />
Bsp. statt</p>
<pre><code class="language-cpp">((TPanel*)Alarme-&gt;Items[Index])-&gt;Parent     = AlarmBox;
((TPanel*)Alarme-&gt;Items[Index])-&gt;Alignment     = taLeftJustify;
((TPanel*)Alarme-&gt;Items[Index])-&gt;Height      = PANEL_HEIGHT;
((TPanel*)Alarme-&gt;Items[Index])-&gt;Width       = PANEL_WIDTH;
((TPanel*)Alarme-&gt;Items[Index])-&gt;Top         = PANEL_TOP+(TextIndex*20);
((TPanel*)Alarme-&gt;Items[Index])-&gt;Left          = PANEL_LEFT; 	

lieber

	TPanel* panel = dynamic_cast&lt;TPanel*&gt;(Alarme-&gt;Items[Index]);
if( panel )
{
   panel-&gt;Parent     = AlarmBox;
   panel-&gt;Alignment     = taLeftJustify;
   panel-&gt;Height      = PANEL_HEIGHT;
   panel-&gt;Width       = PANEL_WIDTH;
   panel-&gt;Top         = PANEL_TOP+(TextIndex*20);
   panel-&gt;Left          = PANEL_LEFT;
// usw.
</code></pre>
</blockquote>
<p>Finde ich auch besser so und vor allem sicherer durch den dynamic_cast, obwohl<br />
sich in der Liste ausschließlich Pointer vom Datentyp TPanel* befinden.</p>
<blockquote>
<p>Belies dich bitt auch ein wenig bezüglich Polymorphie</p>
</blockquote>
<p>Oh je das Wort hört sich schon kompliziert an, werde mal sehen.</p>
<p>Ach das ist die Sache mit der virtuellen Funktion, diese Funktion kann<br />
in einer von der BasisKlasse abgeleiteten Klasse überschrieben werden.<br />
Passiert dies nicht wird die Funktion der BasisKlasse ausgeführt.</p>
<p>Was hat das mit den Sachen weiter Oben zu tun?</p>
<p>An die C++ Style Casts muss ich mich gewönnen, da ich sehr viel C<br />
Programmiere ist man schnell dabei diese C Style Casts auch unter C++<br />
zu verwenden. Werde mich diesbezüglich etwas am &quot;Riemen reissen&quot; und<br />
C++ style Casts verwenden.</p>
<p>Danke für die Lehreiche Hilfe.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1155959</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1155959</guid><dc:creator><![CDATA[hermes]]></dc:creator><pubDate>Fri, 20 Oct 2006 00:10:07 GMT</pubDate></item><item><title><![CDATA[Reply to Auf Parent der CheckBox zugreifen on Tue, 17 Oct 2006 09:23:33 GMT]]></title><description><![CDATA[<p>Wenn du dir sicher bist, dass du den Typ des Objektes in Sender genau kennst, kannst du auch statt dynamic_cast einen static_cast verwenden und die Prüfung auf 0 weglassen. Falls es aber nicht stimmt, bekommst du interessante Fehlermeldungen. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1156122</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1156122</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Tue, 17 Oct 2006 09:23:33 GMT</pubDate></item><item><title><![CDATA[Reply to Auf Parent der CheckBox zugreifen on Fri, 20 Oct 2006 01:05:39 GMT]]></title><description><![CDATA[<p>Braunstein schrieb:</p>
<blockquote>
<p>Wenn du dir sicher bist, dass du den Typ des Objektes in Sender genau kennst, kannst du auch statt dynamic_cast einen static_cast verwenden und die Prüfung auf 0 weglassen. Falls es aber nicht stimmt, bekommst du interessante Fehlermeldungen. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
</blockquote>
<p>Ich denke mal es kommt im schlimmsten Fall eine Speicherzugriffsverletzung.</p>
<p>Ich würde das ganze etwas anders Formulieren, in deinem Kommentar sieht es so aus<br />
als ob bei beiden Cast Arten im Fehler Fall ein NULL Pointer zurückgegeben<br />
wird &quot;kannst du auch statt dynamic_cast einen static_cast verwenden und die Prüfung auf 0 weglassen.&quot;<br />
Natürlich kommt im beim static_cast im Fehlerfall kein NULL Pointer zurück.</p>
<blockquote>
<p>. Wenn du die zu castende Variable mehrfach benötigst erzeuge dir eine temporäre Variable und verwende dann diese<br />
Bsp. statt</p>
<pre><code class="language-cpp">((TPanel*)Alarme-&gt;Items[Index])-&gt;Parent     = AlarmBox;
((TPanel*)Alarme-&gt;Items[Index])-&gt;Alignment     = taLeftJustify;
((TPanel*)Alarme-&gt;Items[Index])-&gt;Height      = PANEL_HEIGHT;
((TPanel*)Alarme-&gt;Items[Index])-&gt;Width       = PANEL_WIDTH;
((TPanel*)Alarme-&gt;Items[Index])-&gt;Top         = PANEL_TOP+(TextIndex*20);
((TPanel*)Alarme-&gt;Items[Index])-&gt;Left          = PANEL_LEFT;    

lieber

    TPanel* panel = dynamic_cast&lt;TPanel*&gt;(Alarme-&gt;Items[Index]);
if( panel )
{
   panel-&gt;Parent     = AlarmBox;
   panel-&gt;Alignment     = taLeftJustify;
   panel-&gt;Height      = PANEL_HEIGHT;
   panel-&gt;Width       = PANEL_WIDTH;
   panel-&gt;Top         = PANEL_TOP+(TextIndex*20);
   panel-&gt;Left          = PANEL_LEFT;
// usw.
</code></pre>
</blockquote>
<p>Warum denn.</p>
<pre><code class="language-cpp">Alarme-&gt;Items[Index] 					= new TPanel(this);
	    	((TPanel*)Alarme-&gt;Items[Index])-&gt;Parent 	= AlarmBox;
     	((TPanel*)Alarme-&gt;Items[Index])-&gt;Alignment 	= taLeftJustify;
     	((TPanel*)Alarme-&gt;Items[Index])-&gt;Height  	= PANEL_HEIGHT;
     	((TPanel*)Alarme-&gt;Items[Index])-&gt;Width   	= PANEL_WIDTH;
     	((TPanel*)Alarme-&gt;Items[Index])-&gt;Top     	= PANEL_TOP+(TextIndex*PANEL_HEIGHT);
     	((TPanel*)Alarme-&gt;Items[Index])-&gt;Left	  	= PANEL_LEFT;
     	((TPanel*)Alarme-&gt;Items[Index])-&gt;Caption 	= AnsiString().sprintf(&quot; %3d&quot;,Index)+&quot;  &quot;+ (List+(TextIndex*29));   //
          ((TPanel*)Alarme-&gt;Items[Index])-&gt;OnMouseMove = MouseOnPanel;
          ((TPanel*)Alarme-&gt;Items[Index])-&gt;DoubleBuffered = true;
     	((TPanel*)Alarme-&gt;Items[Index])-&gt;Visible 	= true;
</code></pre>
<p>Hier Instanziere ich mir ein Panel Object und schreibe es gleich in das<br />
List Object, nun greife ich mit einem C Style Cast auf den in der Liste<br />
instanzierten Pointer des Panels zu. Ist doch OK so.</p>
<pre><code class="language-cpp">((TPanel*)Alarme-&gt;Items[Index])-&gt;Parent     = AlarmBox;
</code></pre>
<p>Warum sollte ich hier nicht einen C Style Cast nehmen, ist doch kein Unterschied<br />
zum static_cast in beiden Fällen wird der Pointer Typ nicht überprüft.</p>
<p>Zu meinem anfänglichem Problem, das habe ich nun so gelöst.</p>
<pre><code class="language-cpp">if( NULL != (TmpPanel = dynamic_cast&lt;TPanel*&gt;(((TCheckBox*)AlarmCheck-&gt;Items[Cb+(Index*5)])-&gt;Parent)) )
               	PanelCaption = TmpPanel-&gt;Caption.SubString(7,8);
			if( !((1&lt;&lt;Cb)&amp;Mask) || (PanelCaption == &quot;Reserved&quot;) )
			{
				((TCheckBox*)AlarmCheck-&gt;Items[Cb+(Index*5)])-&gt;Enabled      	= false;
			}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1156193</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1156193</guid><dc:creator><![CDATA[hermes]]></dc:creator><pubDate>Fri, 20 Oct 2006 01:05:39 GMT</pubDate></item></channel></rss>