File: port11.htm

package info (click to toggle)
wxwin2-doc 2.01-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 6,540 kB
  • ctags: 5,968
  • sloc: cpp: 15,157; makefile: 434; sh: 6
file content (38 lines) | stat: -rw-r--r-- 1,653 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<HTML>
<head><title>Strings</title></head>

<BODY BGCOLOR=#FFFFFF>
<A NAME="topic3"></A><CENTER>
<A HREF="port.htm"><img align=center src="contents.gif" BORDER=0 ALT="Contents"></A> <A HREF="port10.htm#topic2"><img align=center src="up.gif" BORDER=0 ALT="Up"></A> <A HREF="port10.htm#topic2"><img align=center src="back.gif" BORDER=0 ALT="Previous"></A> <A HREF="port12.htm#topic4"><img align=center src="forward.gif" BORDER=0 ALT="Next"></A> </CENTER><HR>

<H2>Strings</H2>
<P>
wxString has replaced char* in the majority of cases. For passing strings into functions,
this should not normally require you to change your code if the syntax is otherwise the
same. This is because C++ will automatically convert a char* or const char* to a wxString by virtue
of appropriate wxString constructors.<P>
However, when a wxString is returned from a function in wxWindows 2.0 where a char* was
returned in wxWindows 1.xx, your application will need to be changed. Usually you can
simplify your application's allocation and deallocation of memory for the returned string,
and simply assign the result to a wxString object. For example, replace this:<P>
<FONT SIZE=2><PRE>

  char* s = wxFunctionThatReturnsString();
  s = copystring(s); // Take a copy in case it's temporary
  .... // Do something with it
  delete[] s;
</PRE>

</FONT><P>
with this:<P>
<FONT SIZE=2><PRE>

  wxString s = wxFunctionThatReturnsString();
  .... // Do something with it
</PRE>

</FONT><P>
To indicate an empty return value or a problem, a function may return either the
empty string ("") or a null string. You can check for a null string with wxString::IsNull().<P>

</BODY></HTML>