Jump to content
  • Advertisement
Sign in to follow this  
Ebola0001

DrawText won't cooperate.

This topic is 4349 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
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 this post


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

Share this post


Link to post
Share on other sites
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 this post


Link to post
Share on other sites
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 this post


Link to post
Share on other sites
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 this post


Link to post
Share on other sites
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 this post


Link to post
Share on other sites
Quote:
Original post by EasilyConfused
AnsiString, 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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!