# DrawText won't cooperate.

## Recommended Posts

Ebola0001    138
hey guys These are my wits [start end] I'm somewhere over here-----^ Im attempting to use DrawText, ive gotten it to display static text that I code into the call. but it refuses to accept anything external (fps, messages, whatever) I was following the drunken hyena tutorial and it has gotten me this far, however when i try to have it use anything else it says [C++ Error] File1.cpp(265): E2034 Cannot convert 'AnsiString' to 'const char *' in the Documentation, it specifically DOES support AnsiString "[in] Pointer to a string to draw. This parameter supports ANSI and Unicode text strings" what am i doing wrong?
   RECT font_rect;

SetRect(&font_rect,200,rock_scale*1000+200,300,rock_scale*1000+300);

g_font->DrawText(NULL,        //pSprite
screen_text,  //pString
-1,          //Count
&font_rect,  //pRect
DT_LEFT|DT_NOCLIP,//Format,
0xFFFFFFFF); //Color

d3ddev->EndScene();

d3ddev->Present(NULL, NULL, NULL, NULL);

return;
}



##### Share on other sites
ToohrVyk    1595
Quote:
 in the Documentation, it specifically DOES support AnsiString"[in] Pointer to a string to draw. This parameter supports ANSI and Unicode text strings"

ANSI and Unicode are encodings for strings, not C++ types. An ANSI string can be stored both as a char* and as an AnsiString. Which of the two does your function use? The compiler seems to agree on char*.

##### Share on other sites
Ebola0001    138
It starts life as:
String screen_text = "hi";

which is rejected with the error i listed in the previous post

It accepts

char* screen_text = "hi";
and
const char* screen_text = "hi";

but then i get an error of

[C++ Error] File1.cpp(237): E2060 Illegal use of floating point

when I try to copy the data into the string

##### Share on other sites
ToohrVyk    1595
Check the documentation of your String object for a conversion to const char*. One of its methods should provide this.

##### Share on other sites
Ebola0001    138
I have tried sever things to convert my string over and i keep running into

[C++ Error] File1.cpp(259): E2034 Cannot convert 'AnsiString' to 'char *'

any thoughts on direction to head in ?

##### Share on other sites
ToohrVyk    1595
Use the c_str() of the AnsiString class (which is not a standard C++ class, as far as I can tell, so I can only make guesses about what it does), copy the resulting const char* into an appropriately-sized char* buffer, then pass the buffer to the function. Use the buffer value, and then delete it.

##### Share on other sites
Ebola0001    138
well that was annoyingly undocumented :)

thanks the solution for those that are interested was adding the ".c_str()"
after the string name

   g_font->DrawText(NULL,        //pSprite                    screen_text.c_str(),  //pString                    -1,          //Count                    &font_rect,  //pRect                    DT_LEFT|DT_NOCLIP,//Format,                    0xFFFFFFFF); //Color

##### Share on other sites
ToohrVyk    1595
As a side note, the std::string class is better documented than that [wink] and it's standard, too.

##### Share on other sites
Aardvajk    13207
AnsiString, typedefed to String (with a capital) is Borland's string class used with the VCL so I assume the OP is using Builder.

c_str() is listed under AnsiString->Methods in the help along with all its other methods if you are looking for any other ways to use it.

std::string is indeed probably superior but all the VCL and other Borland library stuff uses String so if I am correct and you are using Builder, it is well worth learning to use their String as well.

##### Share on other sites
ToohrVyk    1595
Quote:
 Original post by EasilyConfusedAnsiString, typedefed to String (with a capital) is Borland's string class used with the VCL so I assume the OP is using Builder.

That's what I feared, too. The class does have some nifty possibilities, and good interaction with the rest of Borland functionality, but it sucks when dealing with the SC++L.

##### Share on other sites
Aardvajk    13207
I quite agree but I would guess that, when using Builder, it is more efficient to work with String and use c_str() to communicate with the standard library than to use std::string and create a new String object every time you intereact with the VCL.