<?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[TStringList als Rückgabewert einer Funktion.]]></title><description><![CDATA[<p>Hallo zusammen,<br />
ich mache gerade meine ersten Schritte mit BCB.<br />
Ich habe vorhin versucht eine TStringList als Rückgabewert einer Funktion zu geben. Leider ergab es eine Fehlermeldung.<br />
Sorry das ich so dumm frage. Aber ich habe noch kaum Ahnung.<br />
Was habe ich falsch gemacht?</p>
<p>Hier die Funktion:</p>
<pre><code class="language-cpp">TStringList TForm1::LoginInfo(void)
{
TStringList* config = new TStringList;

.
.
.

config-&gt;Add(user);
config-&gt;Add(pass);

return (config);
}
</code></pre>
<p>Hier der Funktionsaufruf:</p>
<pre><code class="language-cpp">TStringList* login = new TStringList;
login = LoginInfo();
</code></pre>
<p>Hier die Fehlermeldung:</p>
<pre><code class="language-cpp">[C++ Error] Unit1.cpp(331): E2034 Cannot convert 'TStringList' to 'TStringList *'
[C++ Warning] Unit1.cpp(348): W8004 'login' is assigned a value that is never used
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/174470/tstringlist-als-rückgabewert-einer-funktion</link><generator>RSS for Node</generator><lastBuildDate>Fri, 14 Aug 2026 18:16:41 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/174470.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 27 Feb 2007 17:05:28 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to TStringList als Rückgabewert einer Funktion. on Tue, 27 Feb 2007 17:05:28 GMT]]></title><description><![CDATA[<p>Hallo zusammen,<br />
ich mache gerade meine ersten Schritte mit BCB.<br />
Ich habe vorhin versucht eine TStringList als Rückgabewert einer Funktion zu geben. Leider ergab es eine Fehlermeldung.<br />
Sorry das ich so dumm frage. Aber ich habe noch kaum Ahnung.<br />
Was habe ich falsch gemacht?</p>
<p>Hier die Funktion:</p>
<pre><code class="language-cpp">TStringList TForm1::LoginInfo(void)
{
TStringList* config = new TStringList;

.
.
.

config-&gt;Add(user);
config-&gt;Add(pass);

return (config);
}
</code></pre>
<p>Hier der Funktionsaufruf:</p>
<pre><code class="language-cpp">TStringList* login = new TStringList;
login = LoginInfo();
</code></pre>
<p>Hier die Fehlermeldung:</p>
<pre><code class="language-cpp">[C++ Error] Unit1.cpp(331): E2034 Cannot convert 'TStringList' to 'TStringList *'
[C++ Warning] Unit1.cpp(348): W8004 'login' is assigned a value that is never used
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1236302</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1236302</guid><dc:creator><![CDATA[RainerBeckler]]></dc:creator><pubDate>Tue, 27 Feb 2007 17:05:28 GMT</pubDate></item><item><title><![CDATA[Reply to TStringList als Rückgabewert einer Funktion. on Tue, 27 Feb 2007 17:32:36 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>der Compiler sagt Dir eigentlich ganz gut, was falsch ist.</p>
<pre><code>[C++ Error] Unit1.cpp(331): E2034 Cannot convert 'TStringList' to 'TStringList *'
</code></pre>
<p>Von welchem Typ ist login und welchen Typ gibt Dir LoginInfo() zurück?</p>
<p>Gruß</p>
<p>Alexander</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1236311</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1236311</guid><dc:creator><![CDATA[Alexander Kempf]]></dc:creator><pubDate>Tue, 27 Feb 2007 17:32:36 GMT</pubDate></item><item><title><![CDATA[Reply to TStringList als Rückgabewert einer Funktion. on Tue, 27 Feb 2007 17:36:27 GMT]]></title><description><![CDATA[<p>Hallo</p>
<pre><code class="language-cpp">TStringList* TForm1::LoginInfo() // Pointer zurückgeben, kein Parameter
{
TStringList* config = new TStringList;
...
config-&gt;Add(user);
config-&gt;Add(pass);
return config; // return ist keine Funktion, extra Klammern hier sind C-Style
}

TStringList* login = LoginInfo(); // Speicherreservierung übernimmt die Funktion
... // benutzen
delete login;
</code></pre>
<p>Allerdings halte ich das diese Variante für sauberer, denn hier ist erstens die Speicherverwaltung an einem Platz und zweitens könnte man theoretisch beliebige TStrings-Objekte übergeben</p>
<pre><code class="language-cpp">void TForm1::LoginInfo(TStrings* config) 
{
config-&gt;Clear();
...
config-&gt;Add(user);
config-&gt;Add(pass);
}

TStringList* login = new TStringList();
LoginInfo(login); 
delete login;
</code></pre>
<p>bis bald<br />
akari</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1236320</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1236320</guid><dc:creator><![CDATA[akari]]></dc:creator><pubDate>Tue, 27 Feb 2007 17:36:27 GMT</pubDate></item><item><title><![CDATA[Reply to TStringList als Rückgabewert einer Funktion. on Tue, 27 Feb 2007 17:57:03 GMT]]></title><description><![CDATA[<p>Danke für die Hilfe!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1236334</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1236334</guid><dc:creator><![CDATA[RainerBeckler]]></dc:creator><pubDate>Tue, 27 Feb 2007 17:57:03 GMT</pubDate></item><item><title><![CDATA[Reply to TStringList als Rückgabewert einer Funktion. on Wed, 28 Feb 2007 12:44:25 GMT]]></title><description><![CDATA[<p>In die Funktion sollte vielleicht noch ein Null-Test für config eingebaut werden. Weiter wäre hier noch die Verwendung von auto_ptr oder boost::shared_ptr möglich, um auch noch das delete einzusparen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1236768</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1236768</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Wed, 28 Feb 2007 12:44:25 GMT</pubDate></item></channel></rss>