<?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[Forms - Variablenübergabe an andere Form ohne Timer etc.]]></title><description><![CDATA[<p>Da ich auf das Thema in der FAQ Variablenübergabe an andere Form nicht Antworten konnte schreib ich jetzt das hier rein:</p>
<p>Also es geht um eine Variablenübergabe an andere Form aber <strong>ohne einen Timer etc.</strong></p>
<p>Zuerst hier der Code der Form die die Variable erhalten soll:</p>
<pre><code class="language-cpp">//------Unit1.cpp------------------------------------------------------------
#include &lt;vcl.h&gt;
#pragma hdrstop

#include &quot;Unit1.h&quot;
#include &quot;Unit2.h&quot;
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource &quot;*.dfm&quot;
TForm1 *Form1;

String Variable = &quot;&quot;;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SetVariable1(void)
{
        if (Label1-&gt;Caption != &quot;&quot;) {
        Variable = Label1-&gt;Caption;
        }
}
//---------------------------------------------------------------------------
</code></pre>
<p>In der Unit1.h muss unter published das eingetragen werden:</p>
<pre><code class="language-cpp">void __fastcall SetVariable1(void);
</code></pre>
<p>Nun brauchen wir folgenden Code in der Form von der die Variable übergeben werden soll.</p>
<pre><code class="language-cpp">//------Unit2.cpp------------------------------------------------------------
#include &lt;vcl.h&gt;
#pragma hdrstop

#include &quot;Unit1.h&quot;
#include &quot;Unit2.h&quot;
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource &quot;*.dfm&quot;
TForm2 *Form2;
String Variable = &quot;Das was übergeben werden soll&quot;;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm2::FormCreate(TObject *Sender)
{
        Form1-&gt;Label1-&gt;Caption = Variable;
        Form1-&gt;SetVariable1();
}
//---------------------------------------------------------------------------
</code></pre>
<p><strong>Erläuterung:</strong></p>
<p>Nachdem die Variable in das Label der Form1 geschrieben wurde wird in Form1 die Funktion ausgeführt und somit der code:</p>
<pre><code class="language-cpp">if (Label1-&gt;Caption != &quot;&quot;) {
        Variable = Label1-&gt;Caption;
    }
</code></pre>
<p>ausgeführt, der den Text aus der Label als Variable speichert.</p>
<p>Mfg. BNS</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/174469/forms-variablenübergabe-an-andere-form-ohne-timer-etc</link><generator>RSS for Node</generator><lastBuildDate>Fri, 14 Aug 2026 18:16:42 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/174469.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 27 Feb 2007 17:05:10 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Forms - Variablenübergabe an andere Form ohne Timer etc. on Tue, 27 Feb 2007 17:53:47 GMT]]></title><description><![CDATA[<p>Da ich auf das Thema in der FAQ Variablenübergabe an andere Form nicht Antworten konnte schreib ich jetzt das hier rein:</p>
<p>Also es geht um eine Variablenübergabe an andere Form aber <strong>ohne einen Timer etc.</strong></p>
<p>Zuerst hier der Code der Form die die Variable erhalten soll:</p>
<pre><code class="language-cpp">//------Unit1.cpp------------------------------------------------------------
#include &lt;vcl.h&gt;
#pragma hdrstop

#include &quot;Unit1.h&quot;
#include &quot;Unit2.h&quot;
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource &quot;*.dfm&quot;
TForm1 *Form1;

String Variable = &quot;&quot;;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SetVariable1(void)
{
        if (Label1-&gt;Caption != &quot;&quot;) {
        Variable = Label1-&gt;Caption;
        }
}
//---------------------------------------------------------------------------
</code></pre>
<p>In der Unit1.h muss unter published das eingetragen werden:</p>
<pre><code class="language-cpp">void __fastcall SetVariable1(void);
</code></pre>
<p>Nun brauchen wir folgenden Code in der Form von der die Variable übergeben werden soll.</p>
<pre><code class="language-cpp">//------Unit2.cpp------------------------------------------------------------
#include &lt;vcl.h&gt;
#pragma hdrstop

#include &quot;Unit1.h&quot;
#include &quot;Unit2.h&quot;
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource &quot;*.dfm&quot;
TForm2 *Form2;
String Variable = &quot;Das was übergeben werden soll&quot;;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm2::FormCreate(TObject *Sender)
{
        Form1-&gt;Label1-&gt;Caption = Variable;
        Form1-&gt;SetVariable1();
}
//---------------------------------------------------------------------------
</code></pre>
<p><strong>Erläuterung:</strong></p>
<p>Nachdem die Variable in das Label der Form1 geschrieben wurde wird in Form1 die Funktion ausgeführt und somit der code:</p>
<pre><code class="language-cpp">if (Label1-&gt;Caption != &quot;&quot;) {
        Variable = Label1-&gt;Caption;
    }
</code></pre>
<p>ausgeführt, der den Text aus der Label als Variable speichert.</p>
<p>Mfg. BNS</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1236301</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1236301</guid><dc:creator><![CDATA[BNightSpeeder]]></dc:creator><pubDate>Tue, 27 Feb 2007 17:53:47 GMT</pubDate></item><item><title><![CDATA[Reply to Forms - Variablenübergabe an andere Form ohne Timer etc. on Tue, 27 Feb 2007 17:30:43 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>Ist das etwa ein ernsthafter Vorschlag? Tut mir leid aber das ist wirklich nicht brauchbar.<br />
- globale Variablen, besser sind Membervariablen, in dem Fall von TForm2<br />
- Zweckentfremdung eines Labels, besser eine Getter-Methode des Forms<br />
- Verwendung des OnCreate-Events, besser ist der Konstruktor des Forms<br />
- Aufruf von Update() und Close wo da Form noch gar nicht angezeigt wird. Wird gar nicht gebraucht</p>
<p>Allgemein : Schau dir erstmal die Grundlagen von OOP in C++ an.</p>
<p>bis bald<br />
akari</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1236308</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1236308</guid><dc:creator><![CDATA[akari]]></dc:creator><pubDate>Tue, 27 Feb 2007 17:30:43 GMT</pubDate></item><item><title><![CDATA[Reply to Forms - Variablenübergabe an andere Form ohne Timer etc. on Tue, 27 Feb 2007 17:49:42 GMT]]></title><description><![CDATA[<p>Hab ein paar Sachen daran verbessert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1236331</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1236331</guid><dc:creator><![CDATA[BNightSpeeder]]></dc:creator><pubDate>Tue, 27 Feb 2007 17:49:42 GMT</pubDate></item><item><title><![CDATA[Reply to Forms - Variablenübergabe an andere Form ohne Timer etc. on Tue, 27 Feb 2007 18:37:41 GMT]]></title><description><![CDATA[<p>bitte nich haun, abba ich versteh denn sinn dieses eintrags nich <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /> .<br />
was ist eine variablenübergabe ohne timer?? ich habe noch nie eine variable mit timer übergeben?<br />
soll das eine einfache variablenübergabe von form zu form sein? und wenn ja, wieso wurde hier keine public variable deklariert?</p>
<p>grüße litooo</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1236368</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1236368</guid><dc:creator><![CDATA[Lito]]></dc:creator><pubDate>Tue, 27 Feb 2007 18:37:41 GMT</pubDate></item><item><title><![CDATA[Reply to Forms - Variablenübergabe an andere Form ohne Timer etc. on Tue, 27 Feb 2007 19:09:37 GMT]]></title><description><![CDATA[<p>Hallo</p>
<blockquote>
<p>was ist eine variablenübergabe ohne timer?? ich habe noch nie eine variable mit timer übergeben?</p>
</blockquote>
<p>BNightSpeeder bezieht sich auf diesen <a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-39242.html" rel="nofollow">FAQ-Eintrag</a>, wo unter anderem ein Timer verwendet wird. Der ist aber nur zur Demonstration, kein Teil des Prinzips.<br />
Selbstverständlich braucht man keinen Timer nur zur Variablenübergabe.</p>
<blockquote>
<p>wieso wurde hier keine public variable deklariert?</p>
</blockquote>
<p>weil <a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-39302.html" rel="nofollow">das</a> noch schimmer wäre... Stichwort Datenkapselung.<br />
Richtig wäre eine private Membervariable des Forms inklusive Gettermethode, bzw. eine entsprechende <a href="http://bcb-tutorial.c-plusplus.net/komponentenentwicklung/komponenten2.html" rel="nofollow">VCL-Property</a>.</p>
<p>bis bald<br />
akari</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1236386</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1236386</guid><dc:creator><![CDATA[akari]]></dc:creator><pubDate>Tue, 27 Feb 2007 19:09:37 GMT</pubDate></item></channel></rss>