1

Topic: Cannot convert ' AnsiString ' to ' string'

6th. Help to rectify errors...

//---------------------------------------------------------------------------
#include <vcl.h>
#include <iostream>
#include <string>
using namespace std;
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package (smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__ fastcall TForm1:: TForm1 (TComponent* Owner)
: TForm (Owner)
{
}
//---------------------------------------------------------------------------
string Morf (string S1, bool T)
{
int LS;
int KB;
int B;
int W;
string S2;
LS = S1.size ();
KB = LS * LS;
if (! T)
{
for (int I = 0; I <LS; I ++)
{
B = S1 [i];
if (B> 32)
{
W = B + KB;
if (W> 255)
W = W - 223;
B = W;
}; //If
S2 + = static_cast <char> (B);
KB = (KB + (I * 2)) AND 127;
}
}
else
{
for (int I = 0; I <LS; I ++)
{
B = S1 [i];
if (B> 32)
{
W = B - KB;
if (W <33)
W = W + 223;
B = W;
}
S2 + = static_cast <char> (B);
KB = (KB + (I * 2)) AND 127;
}
}
return S2;
}
void __ fastcall TForm1:: Button1Click (TObject *Sender)
{
Edit2-> Text = Morf (Edit1-> Text, false);
}
//---------------------------------------------------------------------------
void __ fastcall TForm1:: Button2Click (TObject *Sender)
{
Edit4-> Text = Morf (Edit3-> Text, true);
}
//---------------------------------------------------------------------------

[A C ++ Error] Unit1.cpp (71): E2034 Cannot convert ' AnsiString ' to ' string'
[A C ++ Error] Unit1.cpp (71): E2342 Type mismatch in parameter ' S1 ' (wanted ' string ', got ' AnsiString ')
[A C ++ Error] Unit1.cpp (71): E2034 Cannot convert ' string ' to ' AnsiString'
[A C ++ Error] Unit1.cpp (77): E2034 Cannot convert ' string ' to ' AnsiString'

2

Re: Cannot convert ' AnsiString ' to ' string'

kamero wrote:

Help to rectify errors...

Ctrl-R, "string", "AnsiString", Enter, A.

3

Re: Cannot convert ' AnsiString ' to ' string'

Dimitry Sibiryakov;
The error to the address beats out... In a file dstring.h

char& __ fastcall operator [] (const int idx)
{
ThrowIfOutOfRange (idx);//Should Range-checking be optional to avoid overhead??
Unique ();//Ensure we're not ref-counted
return Data [idx-1];
}

4

Re: Cannot convert ' AnsiString ' to ' string'

View-> Debug Windows-> Call Stack.

5

Re: Cannot convert ' AnsiString ' to ' string'

Dimitry Sibiryakov;
75C4B727 C:\Windows\syswow64\KERNELBASE.dll
40005B68 C:\Windows\SysWOW64\rtl60.bpl
775C6A8B ntdll.dll
77590143 ntdll.dll
0040277A System:: AnsiString:: ThrowIfOutOfRange
00401DA7 System:: AnsiString:: operator [] (this =:0018F280, idx=0)
00401BE9 Morf (S1 = {"111"}, T=false)
00401E2B TForm1:: Button1Click (this =:009E5674, Sender =:009E73B8)
4010798A C:\Windows\SysWOW64\vcl60.bpl
4010A9A8 C:\Windows\SysWOW64\vcl60.bpl
4010AAE0 C:\Windows\SysWOW64\vcl60.bpl
4010A9A8 C:\Windows\SysWOW64\vcl60.bpl
4010A623 C:\Windows\SysWOW64\vcl60.bpl
40037EEA C:\Windows\SysWOW64\rtl60.bpl
759862FA C:\Windows\syswow64\user32.dll
75986D3A C:\Windows\syswow64\user32.dll
75990D27 C:\Windows\syswow64\user32.dll
75990D4D C:\Windows\syswow64\user32.dll
7227A7C2 C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.7601.17514_none_ec83dffa859149af\comctl32.dll
7227A9D0 C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.7601.17514_none_ec83dffa859149af\comctl32.dll
7227A985 C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.7601.17514_none_ec83dffa859149af\comctl32.dll
72291BD0 C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.7601.17514_none_ec83dffa859149af\comctl32.dll
7227A9D0 C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.7601.17514_none_ec83dffa859149af\comctl32.dll
7227A8C3 C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.7601.17514_none_ec83dffa859149af\comctl32.dll
759862FA C:\Windows\syswow64\user32.dll
75986D3A C:\Windows\syswow64\user32.dll
7598965E C:\Windows\syswow64\user32.dll
759896C5 C:\Windows\syswow64\user32.dll
759C5FBB C:\Windows\syswow64\user32.dll
759C60FC C:\Windows\syswow64\user32.dll
759B312E C:\Windows\syswow64\user32.dll
759AAA3F C:\Windows\syswow64\user32.dll
759862FA C:\Windows\syswow64\user32.dll
75986D3A C:\Windows\syswow64\user32.dll
75990D27 C:\Windows\syswow64\user32.dll
7599794A C:\Windows\syswow64\user32.dll
4010AA8C C:\Windows\SysWOW64\vcl60.bpl
4010A9A8 C:\Windows\SysWOW64\vcl60.bpl
40037EEA C:\Windows\SysWOW64\rtl60.bpl
759862FA C:\Windows\syswow64\user32.dll
75986D3A C:\Windows\syswow64\user32.dll
759877C4 C:\Windows\syswow64\user32.dll
75987BCA C:\Windows\syswow64\user32.dll
400F5834 C:\Windows\SysWOW64\vcl60.bpl
004017AB WinMain (=:00400000, =NULL, =:00454450, =9)
3267E52F C:\Windows\SysWOW64\CC3260MT.DLL

6

Re: Cannot convert ' AnsiString ' to ' string'

kamero;
2nd, a line this error which jumps out in a pop-up window. Here in this file that that not so.

7

Re: Cannot convert ' AnsiString ' to ' string'

kamero wrote:

00401BE9 Morf (S1 = {"111"}, T=false)

Here now click on this line and look at what code line you carries out. Look that in
It it is wrong.

8

Re: Cannot convert ' AnsiString ' to ' string'

Dimitry Sibiryakov;

B = S1 [i];

Here on this deduces...