468,727 Members | 1,611 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,727 developers. It's quick & easy.

Cannot convert 'AnsiString' to 'const char *'

codexparse
I am writing a browser program in C++ Builder 6 that loads a web page using the following code:

Expand|Select|Wrap|Line Numbers
  1. void __fastcall TForm1::ToolButton1Click(TObject *Sender)
  2. {
  3.      wchar_t buff[100];
  4.      MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,
  5.      "http://www.thescripts.com", -1, buff, sizeof(buff));
  6.      CppWebBrowser1->Navigate(buff, 0, 0, 0, 0);
  7. }
To include the address bar implementation, I need a temporary string derived from an edit box. This is the code I have tried but receive the error that I cannot convert an AnsiString to const char * and require a type conversion:

Expand|Select|Wrap|Line Numbers
  1. void __fastcall TForm1::ToolButton1Click(TObject *Sender)
  2. {
  3.      const char *tempstring = Edit1->Text;
  4.      wchar_t buff[100];
  5.      MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,
  6.      tempstring, -1, buff, sizeof(buff));
  7.      CppWebBrowser1->Navigate(buff, 0, 0, 0, 0);
  8. }
I've tried to decipher how the TStringConverter VCL class works but I have been unsuccesful determining how it works either:

TStringConverter::AnsiToWide

Converts a null-terminated ANSI string to a wide (Unicode) string.
static LPWSTR AnsiToWide(LPCSTR src);

WideToAnsi calls MultiByteToWideChar(), using the ANSI code page, to convert the ANSI string specified by src to a null-terminated string of Unicode characters. The source string may be from a multibyte character set.

Thanks in advance for suggestions anyone might have as to how I can resolve this programming obstacle.
Nov 4 '07 #1
1 13306
Banfa
9,057 Expert Mod 8TB
instead of

Expand|Select|Wrap|Line Numbers
  1. const char *tempstring = Edit1->Text;
  2.  
try

Expand|Select|Wrap|Line Numbers
  1. const char *tempstring = Edit1->Text.c_str();
  2.  
Nov 5 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Mendon?a | last post: by
5 posts views Thread by Brad Moore | last post: by
2 posts views Thread by nassim.bouayad.agha | last post: by
1 post views Thread by CARIGAR | last post: by
9 posts views Thread by bryonone | last post: by
reply views Thread by zhoujie | last post: by
xarzu
1 post views Thread by xarzu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.