Sign in to follow this  
Ebola0001

DrawText won't cooperate.

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
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
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
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this