<?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[Zugriff auf Elemente aus einer Funktion heraus]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe vor 1 Tag mit C++ und GUIs angefangen und wollte mal einen kleinen Taschenrechner programmieren.</p>
<p>Hier der Code:</p>
<pre><code class="language-cpp">//---------------------------------------------------------------------------

#include &lt;vcl.h&gt;
#pragma hdrstop

#include &quot;Unit1.h&quot;
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource &quot;*.dfm&quot;
TCalc *Calc;
//---------------------------------------------------------------------------
__fastcall TCalc::TCalc(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

int zahl1 = 0, zahl2 = 0, ergebnis = 0;
bool zahl1_set = false, zahl2_set = false;

void rechne(void)
{
   if(zahl1_set)
    {
      zahl2 = StrToInt(Edit1-&gt;Text);
      zahl2_set = true;
      ergebnis = zahl1+zahl2;
      Panel1-&gt;Caption = IntToStr(zahl1)+&quot; + &quot;+IntToStr(zahl2)+&quot; = &quot;+IntToStr(ergebnis);
    }
    else
    {
     zahl1 = StrToInt(Edit1-&gt;Text);
     zahl1_set = true;
     Panel1-&gt;Caption = IntToStr(zahl1)+&quot; + ? =&quot;;
    }
}

void display_Number(int nr)
{
 Panel1-&gt;Text = &quot;test&quot;;
}
//---------------------------------------------------------------------------

void __fastcall TCalc::Button1Click(TObject *Sender)
{
 display_Number(1);
}
//---------------------------------------------------------------------------

void __fastcall TCalc::Button2Click(TObject *Sender)
{
 display_Number(2);
}
//---------------------------------------------------------------------------

void __fastcall TCalc::Button3Click(TObject *Sender)
{
 display_Number(3);
}
//---------------------------------------------------------------------------

void __fastcall TCalc::Button4Click(TObject *Sender)
{
 display_Number(4);
}
//---------------------------------------------------------------------------

void __fastcall TCalc::Button5Click(TObject *Sender)
{
 display_Number(5);
}
//---------------------------------------------------------------------------

void __fastcall TCalc::Button6Click(TObject *Sender)
{
 display_Number(6);
}
//---------------------------------------------------------------------------
void __fastcall TCalc::Button7Click(TObject *Sender)
{
 display_Number(7);
}
//---------------------------------------------------------------------------

void __fastcall TCalc::Button8Click(TObject *Sender)
{
 display_Number(8);
}
//---------------------------------------------------------------------------

void __fastcall TCalc::Button9Click(TObject *Sender)
{
 display_Number(9);
}
//---------------------------------------------------------------------------

void __fastcall TCalc::Button10Click(TObject *Sender)
{
 display_Number(0);
}
//---------------------------------------------------------------------------
</code></pre>
<p>Das Problem ist nun, dass der Compiler mir meldet, dass das Element Edit1 nicht vorhanden sei. (genau wie alle anderen elemente)<br />
Allerdings hat es noch funktioniert, als ich das Zeug noch nicht in seperaten Funktionen hatte.</p>
<p>Meine Frage ist jetzt: Wie greife ich auf die Elemente zu?</p>
<p>fat32</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/206873/zugriff-auf-elemente-aus-einer-funktion-heraus</link><generator>RSS for Node</generator><lastBuildDate>Thu, 20 Aug 2026 01:42:54 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/206873.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 29 Feb 2008 22:27:25 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Zugriff auf Elemente aus einer Funktion heraus on Fri, 29 Feb 2008 22:27:25 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe vor 1 Tag mit C++ und GUIs angefangen und wollte mal einen kleinen Taschenrechner programmieren.</p>
<p>Hier der Code:</p>
<pre><code class="language-cpp">//---------------------------------------------------------------------------

#include &lt;vcl.h&gt;
#pragma hdrstop

#include &quot;Unit1.h&quot;
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource &quot;*.dfm&quot;
TCalc *Calc;
//---------------------------------------------------------------------------
__fastcall TCalc::TCalc(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

int zahl1 = 0, zahl2 = 0, ergebnis = 0;
bool zahl1_set = false, zahl2_set = false;

void rechne(void)
{
   if(zahl1_set)
    {
      zahl2 = StrToInt(Edit1-&gt;Text);
      zahl2_set = true;
      ergebnis = zahl1+zahl2;
      Panel1-&gt;Caption = IntToStr(zahl1)+&quot; + &quot;+IntToStr(zahl2)+&quot; = &quot;+IntToStr(ergebnis);
    }
    else
    {
     zahl1 = StrToInt(Edit1-&gt;Text);
     zahl1_set = true;
     Panel1-&gt;Caption = IntToStr(zahl1)+&quot; + ? =&quot;;
    }
}

void display_Number(int nr)
{
 Panel1-&gt;Text = &quot;test&quot;;
}
//---------------------------------------------------------------------------

void __fastcall TCalc::Button1Click(TObject *Sender)
{
 display_Number(1);
}
//---------------------------------------------------------------------------

void __fastcall TCalc::Button2Click(TObject *Sender)
{
 display_Number(2);
}
//---------------------------------------------------------------------------

void __fastcall TCalc::Button3Click(TObject *Sender)
{
 display_Number(3);
}
//---------------------------------------------------------------------------

void __fastcall TCalc::Button4Click(TObject *Sender)
{
 display_Number(4);
}
//---------------------------------------------------------------------------

void __fastcall TCalc::Button5Click(TObject *Sender)
{
 display_Number(5);
}
//---------------------------------------------------------------------------

void __fastcall TCalc::Button6Click(TObject *Sender)
{
 display_Number(6);
}
//---------------------------------------------------------------------------
void __fastcall TCalc::Button7Click(TObject *Sender)
{
 display_Number(7);
}
//---------------------------------------------------------------------------

void __fastcall TCalc::Button8Click(TObject *Sender)
{
 display_Number(8);
}
//---------------------------------------------------------------------------

void __fastcall TCalc::Button9Click(TObject *Sender)
{
 display_Number(9);
}
//---------------------------------------------------------------------------

void __fastcall TCalc::Button10Click(TObject *Sender)
{
 display_Number(0);
}
//---------------------------------------------------------------------------
</code></pre>
<p>Das Problem ist nun, dass der Compiler mir meldet, dass das Element Edit1 nicht vorhanden sei. (genau wie alle anderen elemente)<br />
Allerdings hat es noch funktioniert, als ich das Zeug noch nicht in seperaten Funktionen hatte.</p>
<p>Meine Frage ist jetzt: Wie greife ich auf die Elemente zu?</p>
<p>fat32</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1465841</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1465841</guid><dc:creator><![CDATA[fat32]]></dc:creator><pubDate>Fri, 29 Feb 2008 22:27:25 GMT</pubDate></item><item><title><![CDATA[Reply to Zugriff auf Elemente aus einer Funktion heraus on Fri, 29 Feb 2008 22:38:14 GMT]]></title><description><![CDATA[<p>Entweder du schreibst davor jeweils ein</p>
<pre><code class="language-cpp">Calc-&gt;
</code></pre>
<p>oder machst die Funktionen gleich zu Memberfunktionen(Methoden) deiner Form indem du sie in der Header bekanntmachst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1465845</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1465845</guid><dc:creator><![CDATA[dsw]]></dc:creator><pubDate>Fri, 29 Feb 2008 22:38:14 GMT</pubDate></item><item><title><![CDATA[Reply to Zugriff auf Elemente aus einer Funktion heraus on Fri, 29 Feb 2008 22:42:16 GMT]]></title><description><![CDATA[<p>Vielen Dank!</p>
<p>das mit Calc-&gt; hat geklappt.<br />
Ich google mal nach den erwähnten Memberfunktionen...</p>
<p>fat32</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1465848</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1465848</guid><dc:creator><![CDATA[fat32]]></dc:creator><pubDate>Fri, 29 Feb 2008 22:42:16 GMT</pubDate></item><item><title><![CDATA[Reply to Zugriff auf Elemente aus einer Funktion heraus on Sat, 01 Mar 2008 13:55:08 GMT]]></title><description><![CDATA[<p>Lies doch mal in der FAQ<br />
<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-39242.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-t-is-39242.html</a><br />
oder<br />
<a href="http://tutorial.schornboeck.net/oop2.htm" rel="nofollow">http://tutorial.schornboeck.net/oop2.htm</a><br />
<a href="http://www.ica1.uni-stuttgart.de/Courses_and_Lectures/C++/script/node17.html" rel="nofollow">http://www.ica1.uni-stuttgart.de/Courses_and_Lectures/C++/script/node17.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1466041</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1466041</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Sat, 01 Mar 2008 13:55:08 GMT</pubDate></item></channel></rss>