<?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[Zugriffsverletzung bei Komponentenentwicklung]]></title><description><![CDATA[<p>Hallo!</p>
<p>Ich möchte eine Komponenten entwickeln, die, wenn ich sie aktiviere, alle Komponenten auf einem Formular in einem neuen Stil zeichnet. Doch wenn ich im Entwicklungsmodus die Komponente aktiviere (ich habe hierfür eine neue Eigenschaft eingetragen), kommt es zu einer Zugriffsverletzung in einem Modul. Kann mir vielleicht jemand bei dem Problem behilflich sein?</p>
<p>Hier ist der Code:</p>
<pre><code class="language-cpp">void __fastcall TKomponente::SetActive(bool Value)
{
 if (!(Value == FActive))
 {
  FActive = Value;
  if (FActive)
   InitItems(FForm, true, true);
  else
   InitItems(FForm,false,true);
  }
}
//----------------------------------------------------------------------------

void __fastcall TKomponente::InitItems(TScrollingWinControl* wForm, bool Enable, bool Update)
{
 int i;
 TComponent *Comp;

 for (i=0; i&lt;=wForm-&gt;ComponentCount-1; i++) //der Fehler tritt hier auf
 {
  Comp = wForm-&gt;Components[i];
 }
}
</code></pre>
<p>Der Header sieht wie folgt aus:</p>
<pre><code class="language-cpp">/---------------------------------------------------------------------------

#ifndef KomponenteH
#define KomponenteH
//---------------------------------------------------------------------------
#include &lt;SysUtils.hpp&gt;
#include &lt;Controls.hpp&gt;
#include &lt;Classes.hpp&gt;
#include &lt;Forms.hpp&gt;
//---------------------------------------------------------------------------
class PACKAGE TKomponente : public TComponent
{
private:
        bool FActive;
        TScrollingWinControl *FForm;
        TFont *FFont;
        void __fastcall SetActive(bool Value);
        void __fastcall SetForm(TScrollingWinControl *Value);
        void __fastcall InitItems(TScrollingWinControl* wForm, bool Enable, bool Update);

protected:
        virtual void __fastcall Loaded();

public:
        __fastcall TKomponente(TComponent* Owner);
        virtual __fastcall ~TKomponente();
        __property TScrollingWinControl *Form = {read = FForm, write = SetForm};

__published:
        __property bool Active = {read = FActive, write = SetActive};
        __property TFont *Font = {read = FFont, write = FFont};
};
</code></pre>
<p>Danke!</p>
<p>Gruß<br />
Thomas</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/93801/zugriffsverletzung-bei-komponentenentwicklung</link><generator>RSS for Node</generator><lastBuildDate>Thu, 09 Jul 2026 13:32:58 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/93801.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 02 Dec 2004 18:36:42 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Zugriffsverletzung bei Komponentenentwicklung on Thu, 02 Dec 2004 18:36:42 GMT]]></title><description><![CDATA[<p>Hallo!</p>
<p>Ich möchte eine Komponenten entwickeln, die, wenn ich sie aktiviere, alle Komponenten auf einem Formular in einem neuen Stil zeichnet. Doch wenn ich im Entwicklungsmodus die Komponente aktiviere (ich habe hierfür eine neue Eigenschaft eingetragen), kommt es zu einer Zugriffsverletzung in einem Modul. Kann mir vielleicht jemand bei dem Problem behilflich sein?</p>
<p>Hier ist der Code:</p>
<pre><code class="language-cpp">void __fastcall TKomponente::SetActive(bool Value)
{
 if (!(Value == FActive))
 {
  FActive = Value;
  if (FActive)
   InitItems(FForm, true, true);
  else
   InitItems(FForm,false,true);
  }
}
//----------------------------------------------------------------------------

void __fastcall TKomponente::InitItems(TScrollingWinControl* wForm, bool Enable, bool Update)
{
 int i;
 TComponent *Comp;

 for (i=0; i&lt;=wForm-&gt;ComponentCount-1; i++) //der Fehler tritt hier auf
 {
  Comp = wForm-&gt;Components[i];
 }
}
</code></pre>
<p>Der Header sieht wie folgt aus:</p>
<pre><code class="language-cpp">/---------------------------------------------------------------------------

#ifndef KomponenteH
#define KomponenteH
//---------------------------------------------------------------------------
#include &lt;SysUtils.hpp&gt;
#include &lt;Controls.hpp&gt;
#include &lt;Classes.hpp&gt;
#include &lt;Forms.hpp&gt;
//---------------------------------------------------------------------------
class PACKAGE TKomponente : public TComponent
{
private:
        bool FActive;
        TScrollingWinControl *FForm;
        TFont *FFont;
        void __fastcall SetActive(bool Value);
        void __fastcall SetForm(TScrollingWinControl *Value);
        void __fastcall InitItems(TScrollingWinControl* wForm, bool Enable, bool Update);

protected:
        virtual void __fastcall Loaded();

public:
        __fastcall TKomponente(TComponent* Owner);
        virtual __fastcall ~TKomponente();
        __property TScrollingWinControl *Form = {read = FForm, write = SetForm};

__published:
        __property bool Active = {read = FActive, write = SetActive};
        __property TFont *Font = {read = FFont, write = FFont};
};
</code></pre>
<p>Danke!</p>
<p>Gruß<br />
Thomas</p>
]]></description><link>https://www.c-plusplus.net/forum/post/664714</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/664714</guid><dc:creator><![CDATA[Tom1966]]></dc:creator><pubDate>Thu, 02 Dec 2004 18:36:42 GMT</pubDate></item><item><title><![CDATA[Reply to Zugriffsverletzung bei Komponentenentwicklung on Thu, 02 Dec 2004 18:50:39 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>Dazu müsste man schon sehen wie deine Komponente eingesetzt wird. Ein Zugriffsverletzung an dieser Stelle wird wohl durch einen ungültigen Pointer (wForm) verursacht.<br />
Ist vor dem Aufruf von SetActive auch FForm schon gesetzt (d.h. SetForm aufgerufen)?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/664724</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/664724</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Thu, 02 Dec 2004 18:50:39 GMT</pubDate></item><item><title><![CDATA[Reply to Zugriffsverletzung bei Komponentenentwicklung on Thu, 02 Dec 2004 19:34:12 GMT]]></title><description><![CDATA[<p>Hallo!</p>
<p>Ja! SetForm ist auch schon gesetzt. Hier ist der Code dazu:</p>
<pre><code class="language-cpp">void __fastcall TKomponente::SetForm(TScrollingWinControl *Value)
{
 bool Hold;

 if (Value != FForm)
 {
    Hold = Active;
    Active = false;
    FForm = Value;
    if (Hold)
       Active = true;
 }
}
</code></pre>
<p>Alles funktioniert, d.h. ich kann Active ändern, solange ich die Zeilen in InitItems deaktiviere.</p>
<p>Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/664754</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/664754</guid><dc:creator><![CDATA[Tom1966]]></dc:creator><pubDate>Thu, 02 Dec 2004 19:34:12 GMT</pubDate></item><item><title><![CDATA[Reply to Zugriffsverletzung bei Komponentenentwicklung on Thu, 02 Dec 2004 23:18:59 GMT]]></title><description><![CDATA[<p>Ich kann nicht sehen, dass Du irgendwo überprüfst, ob FForm auch eine gültige Instanz ist.<br />
Also irgendwas in der Art:</p>
<pre><code class="language-cpp">void __fastcall TKomponente::InitItems(TScrollingWinControl* wForm, bool Enable, bool Update)
{
 int i;
 TComponent *Comp;

 if (wForm)
   for (i=0; i&lt;=wForm-&gt;ComponentCount-1; i++) //der Fehler tritt hier auf
   {
    Comp = wForm-&gt;Components[i];
   }
}
</code></pre>
<p>Weshalb übergibst Du eigentlich der privaten Methode InitItems die Referenz auf FForm und verwendest nicht direkt Form?</p>
<p>Was mir noch zu dem Thema einfällt, ist, dass Du die Eigenschaft ComponentState (glaube die heißt so) abprüfen kannst. Daraus kann<br />
man sehen, ob die Komponente bereits vollständig geladen ist. Hilfreich könnte in dem Zusammenhang u.U. auch ein Überschreiben<br />
der Loaded()-Methode sein.</p>
<p>Gruß,</p>
<p>Alexander</p>
]]></description><link>https://www.c-plusplus.net/forum/post/664852</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/664852</guid><dc:creator><![CDATA[Alexander Kempf]]></dc:creator><pubDate>Thu, 02 Dec 2004 23:18:59 GMT</pubDate></item></channel></rss>