<?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[Unterkomponten bei Komponentenerstellung]]></title><description><![CDATA[<p>Hi,</p>
<p>ich hab folgendes Problem bei der Erstellung einer Komponente, welche von TCustomPanel abgeleitet ist (dient als Container) und auf der ein TEdit und ein TLabel plaziert werdensollen. Klappt so weit ganz gut, beide Objekte sind sichtbar und funktionsfähig. Ich kann auch Default-Werte im Konstruktor zuweisen, allerdings nur dort. Sobald ich in anderen Set/Get Methoden auf diese Pointer zugreifen will sind diese =Null. Über Components[iIndex] komm ich wiederrum dran.<br />
Hier der Code:</p>
<pre><code>class PACKAGE TLookupEdit : public TCustomPanel
{
private:

   TEdit *oEdit;
   TLabel *oLabel;

   int FFieldSize;
   String FText;
   void __fastcall SetFieldSize(int value);
   int __fastcall GetFieldSize();
   void __fastcall SetText(String value);
   String __fastcall GetText();
   ...
</code></pre>
<pre><code>__fastcall TLookupEdit::TLookupEdit(TComponent* Owner)
   : TCustomPanel(Owner)
{
   TEdit* oEdit = new TEdit((TComponent*)this);
   oEdit -&gt;SetSubComponent(true);
   oEdit-&gt;Parent = this;
   oEdit-&gt;Visible = true;
   oEdit-&gt;MaxLength = 2;
   oEdit-&gt;Left = 0;
   oEdit-&gt;Top = 0;
   oEdit-&gt;Width = 24;
   this-&gt;Height = oEdit-&gt;Height;

   TLabel* oLabel = new TLabel(this);
   oLabel-&gt;SetSubComponent(true);
   oLabel-&gt;Parent = this;
   oLabel-&gt;Visible = true;
   oLabel-&gt;AutoSize = true;
   oLabel-&gt;Caption = &quot;&quot;;
   oLabel-&gt;Left = oEdit-&gt;Width + 4;
   oLabel-&gt;Top = 2;
   oLabel-&gt;Width = 30;
}

void __fastcall TLookupEdit::SetFieldSize(int value)
{
   if (value!=FFieldSize)
   {
      FFieldSize = value;
      if (oEdit)
      {
         oEdit-&gt;Width = 12 * value; //Funktioniert nicht, da oEdit=Null
         oEdit-&gt;MaxLength = value;
      }
   }
}
int __fastcall TLookupEdit::GetFieldSize()
{
   return FFieldSize;
}
//---------------------------------------------------------------------------

void __fastcall TLookupEdit::SetText(String value)
{
   //this-&gt;oEdit-&gt;Text = value;
   ((TEdit*)this-&gt;Components[0])-&gt;Text = value;//Funktioniert
   FText = value;

}
String __fastcall TLookupEdit::GetText()
{
   return FText;
}
</code></pre>
<p>Das Ändern der Werte im Property-Editor geht auch, hat im ersten Fall nur keine Auswirkung.<br />
Also weiß jemand wann, wo und warum diese Objekte, bzw. Pointer auf Null gesetzt werden?</p>
<p>Schon mal Danke <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/topic/97754/unterkomponten-bei-komponentenerstellung</link><generator>RSS for Node</generator><lastBuildDate>Sun, 12 Jul 2026 02:38:07 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/97754.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 13 Jan 2005 15:29:51 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Unterkomponten bei Komponentenerstellung on Thu, 13 Jan 2005 15:29:51 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>ich hab folgendes Problem bei der Erstellung einer Komponente, welche von TCustomPanel abgeleitet ist (dient als Container) und auf der ein TEdit und ein TLabel plaziert werdensollen. Klappt so weit ganz gut, beide Objekte sind sichtbar und funktionsfähig. Ich kann auch Default-Werte im Konstruktor zuweisen, allerdings nur dort. Sobald ich in anderen Set/Get Methoden auf diese Pointer zugreifen will sind diese =Null. Über Components[iIndex] komm ich wiederrum dran.<br />
Hier der Code:</p>
<pre><code>class PACKAGE TLookupEdit : public TCustomPanel
{
private:

   TEdit *oEdit;
   TLabel *oLabel;

   int FFieldSize;
   String FText;
   void __fastcall SetFieldSize(int value);
   int __fastcall GetFieldSize();
   void __fastcall SetText(String value);
   String __fastcall GetText();
   ...
</code></pre>
<pre><code>__fastcall TLookupEdit::TLookupEdit(TComponent* Owner)
   : TCustomPanel(Owner)
{
   TEdit* oEdit = new TEdit((TComponent*)this);
   oEdit -&gt;SetSubComponent(true);
   oEdit-&gt;Parent = this;
   oEdit-&gt;Visible = true;
   oEdit-&gt;MaxLength = 2;
   oEdit-&gt;Left = 0;
   oEdit-&gt;Top = 0;
   oEdit-&gt;Width = 24;
   this-&gt;Height = oEdit-&gt;Height;

   TLabel* oLabel = new TLabel(this);
   oLabel-&gt;SetSubComponent(true);
   oLabel-&gt;Parent = this;
   oLabel-&gt;Visible = true;
   oLabel-&gt;AutoSize = true;
   oLabel-&gt;Caption = &quot;&quot;;
   oLabel-&gt;Left = oEdit-&gt;Width + 4;
   oLabel-&gt;Top = 2;
   oLabel-&gt;Width = 30;
}

void __fastcall TLookupEdit::SetFieldSize(int value)
{
   if (value!=FFieldSize)
   {
      FFieldSize = value;
      if (oEdit)
      {
         oEdit-&gt;Width = 12 * value; //Funktioniert nicht, da oEdit=Null
         oEdit-&gt;MaxLength = value;
      }
   }
}
int __fastcall TLookupEdit::GetFieldSize()
{
   return FFieldSize;
}
//---------------------------------------------------------------------------

void __fastcall TLookupEdit::SetText(String value)
{
   //this-&gt;oEdit-&gt;Text = value;
   ((TEdit*)this-&gt;Components[0])-&gt;Text = value;//Funktioniert
   FText = value;

}
String __fastcall TLookupEdit::GetText()
{
   return FText;
}
</code></pre>
<p>Das Ändern der Werte im Property-Editor geht auch, hat im ersten Fall nur keine Auswirkung.<br />
Also weiß jemand wann, wo und warum diese Objekte, bzw. Pointer auf Null gesetzt werden?</p>
<p>Schon mal Danke <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/695250</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/695250</guid><dc:creator><![CDATA[Howie]]></dc:creator><pubDate>Thu, 13 Jan 2005 15:29:51 GMT</pubDate></item><item><title><![CDATA[Reply to Unterkomponten bei Komponentenerstellung on Thu, 13 Jan 2005 16:53:55 GMT]]></title><description><![CDATA[<p>Du erzeugst im Konstruktor mit &quot;TEdit *oEdit = new ...&quot; eine neue Variable oEdit, die nur im Konstruktor gültig ist. Laß einfach den Typ TEdit vor *oEdit weg, damit die Variable aus der Komponente verwendet wird.</p>
<p>Rob'</p>
]]></description><link>https://www.c-plusplus.net/forum/post/695355</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/695355</guid><dc:creator><![CDATA[Rob&#x27;]]></dc:creator><pubDate>Thu, 13 Jan 2005 16:53:55 GMT</pubDate></item><item><title><![CDATA[Reply to Unterkomponten bei Komponentenerstellung on Fri, 14 Jan 2005 07:20:10 GMT]]></title><description><![CDATA[<p>Ah, ich Doof.</p>
<p>Vielen Dank Rob, funktioniert nun.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/695817</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/695817</guid><dc:creator><![CDATA[Howie]]></dc:creator><pubDate>Fri, 14 Jan 2005 07:20:10 GMT</pubDate></item></channel></rss>