473,325 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

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 14899
Banfa
9,065 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

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

Similar topics

2
by: Mendon?a | last post by:
I cant seem to find on borland help files anything about AnsiString to char conversion. Just the opposite. Can u help me?
5
by: Brad Moore | last post by:
Hey all, I'm getting the following compiler error from my code. I was wondering if anyone could help me understand the concept behind it (I actually did try and compile this degenerate...
2
by: Abhijit Bhadra | last post by:
Hi , I was trying to build my project in VC with latest Service Packs but got this error . C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE\atlconv.h(125) : error C2440: 'return' :...
6
by: John Smith | last post by:
What's wrong with the use of atoi in the following code? Why do I get the error message: 'atoi' : cannot convert parameter 1 from 'char' to 'const char *' char cBuffer; void...
3
by: Alfonso Morra | last post by:
Hi, I'm using a third party library which has a function that expects an arg of type const char*. I have a char* which is assigned a value at run time - how can I pass it to my function? ...
3
by: kaizen | last post by:
Hi, i wrote the code in C and compiled in VC++ compiler. at that time it has thrown the below mentioned error. error C2664: 'strcpy' : cannot convert parameter 2 from 'char' to 'const char *'...
3
by: bg_ie | last post by:
Hi, I am using a API I downloaded from the internet programmed in C. I need the function below which works with this api in my c++ file - void StoreNoteCallback(void *context, int arglen,...
2
by: nassim.bouayad.agha | last post by:
Hello, here is a code snippet showning my problem : template<typename _K> class TClass1 { public: void Process(const _K& arg) const {
5
by: slizorn | last post by:
well the error i get is the title above: error C2664: 'searchTree' : cannot convert parameter 2 from 'const char *' to 'char' error is form this line searchTree(treeObj->root ,data1.c_str());...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.