我有一个用c ++ builder 6编写的简单项目。它是关于加密RSA算法的。 想要转换为c ++ builder 2010,但它会出错
e.g。主项目源代码
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "UTForm.h"
#include "UTRSA.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
randomize();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TRSA a(Edit4->Text.ToInt());
char* tmp = a.KeyModul;
Edit1->Text = AnsiString(tmp);
tmp = a.OpenKey;
Edit2->Text = AnsiString(tmp);
tmp = a.SecretKey;
Edit3->Text = AnsiString(tmp);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
TNumber n(Edit1->Text.c_str());
TNumber e(Edit2->Text.c_str());
TNumber d(Edit3->Text.c_str());
THexString text;
text.AsCharString = Edit5->Text;
if (Edit3->Text != "")
{
TRSA a(n,e,d,Edit4->Text.ToInt());
a.PlainText = text;
Edit6->Text = a.CryptedText.AsHexString;
}
else
{
TRSA a(n,e,Edit4->Text.ToInt());
a.PlainText = text;
Edit6->Text = a.CryptedText.AsHexString;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
TNumber n(Edit1->Text.c_str());
TNumber e(Edit2->Text.c_str());
TNumber d(Edit3->Text.c_str());
THexString text;
text.AsHexString = Edit6->Text;
if (Edit3->Text != "")
{
TRSA a(n,e,d,Edit4->Text.ToInt());
a.CryptedText = text;
Edit8->Text = a.PlainText.AsCharString;
}
else
{
TRSA a(n,e,Edit4->Text.ToInt());
a.CryptedText = text;
Edit8->Text = a.PlainText.AsCharString;
}
}
//---------------------------------------------------------------------------
错误是:
Build
Checking project dependencies...
Compiling RSA.cbproj (Debug configuration)
[BCC32 Warning] UTHexString.cpp(92): W8012 Comparing signed and unsigned values
[BCC32 Warning] UTHexString.cpp(92): W8012 Comparing signed and unsigned values
[BCC32 Warning] UTForm.cpp(29): W8057 Parameter 'Sender' is never used
[BCC32 Error] UTForm.cpp(33): E2285 Could not find a match for 'TNumber::TNumber(wchar_t *)'
[BCC32 Error] UTForm.cpp(34): E2285 Could not find a match for 'TNumber::TNumber(wchar_t *)'
[BCC32 Error] UTForm.cpp(35): E2285 Could not find a match for 'TNumber::TNumber(wchar_t *)'
[BCC32 Warning] UTForm.cpp(52): W8057 Parameter 'Sender' is never used
[BCC32 Error] UTForm.cpp(57): E2285 Could not find a match for 'TNumber::TNumber(wchar_t *)'
[BCC32 Error] UTForm.cpp(58): E2285 Could not find a match for 'TNumber::TNumber(wchar_t *)'
[BCC32 Error] UTForm.cpp(59): E2285 Could not find a match for 'TNumber::TNumber(wchar_t *)'
[BCC32 Warning] UTForm.cpp(76): W8057 Parameter 'Sender' is never used
Failed
Elapsed time: 00:00:01.5
Project Import
Upgrading project "D:\SOFTS\DELPHI and C++ Builder 2009\Cryptography\RSA\RSA\RSA.bpr"
Reading "D:\SOFTS\DELPHI and C++ Builder 2009\Cryptography\RSA\RSA\RSA.bpr"
Upgraded to "D:\SOFTS\DELPHI and C++ Builder 2009\Cryptography\RSA\RSA\RSA.cbproj"
我认为C ++ Builder 2010具有默认的unicode支持,这就是为什么或者我错了? 当我查看TNumber构造函数时,它具有以下内容:
//---------------------------------------------------------------------------
#ifndef UTNumberH
#define UTNumberH
//---------------------------------------------------------------------------
#include <assert.h>
#include <iostream.h>
#include <iomanip.h>
#include <string.h>
#include <ctype.h>
#include <limits.h>
#include <math.h>
class TNumber
{
private:
TNumber multdigit(int) const;
TNumber mult10(int) const;
char *vlstr;
int vlen;
int vlsign;
public:
TNumber(const char* = NULL);
TNumber(int);
TNumber(const TNumber &);
~TNumber();
operator int() const;
operator long() const;
operator double() const;
operator char*() const;
const TNumber& operator=(const TNumber&);
TNumber operator - () const;
TNumber operator ++ ();
TNumber operator ++ (int);
TNumber operator -- ();
TNumber operator -- (int);
TNumber operator += (const TNumber &);
TNumber operator -= (const TNumber &);
TNumber operator *= (const TNumber &);
TNumber operator /= (const TNumber &);
TNumber operator %= (const TNumber &);
friend TNumber operator + (const TNumber &, const TNumber &);
friend TNumber operator - (const TNumber &, const TNumber &);
friend TNumber operator * (const TNumber &, const TNumber &);
friend TNumber operator / (const TNumber &, const TNumber &);
friend TNumber operator % (const TNumber &, const TNumber &);
friend int operator == (const TNumber &, const TNumber &);
friend int operator != (const TNumber &, const TNumber &);
friend int operator < (const TNumber &, const TNumber &);
friend int operator <= (const TNumber &, const TNumber &);
friend int operator > (const TNumber &, const TNumber &);
friend int operator >= (const TNumber &, const TNumber &);
char* strrev(char *s) const;
friend TNumber abs(const TNumber &);
friend TNumber sqrt(const TNumber &);
friend TNumber pow(const TNumber &, const TNumber &);
friend double div(const TNumber &, const TNumber &);
friend ostream & operator << (ostream &, const TNumber &);
friend istream & operator >> (istream &, TNumber &);
friend TNumber rnd(const TNumber& from, const TNumber& to);
};
const TNumber zero = TNumber("0");
const TNumber one = TNumber("1");
const TNumber two = TNumber("2");
TNumber eae(TNumber u, TNumber v);
#endif
我哪里错了?
另外找到附加的c ++ builder 6项目!
答案 0 :(得分:2)
你是对的。 UnicodeString
是2010年默认情况下大多数字符串的含义。由于Text
属性很可能是其中之一,因此最安全的编译方法是使用以下内容进行转换:
TNumber n( AnsiString( Edit1->Text ).c_str() );
<强>更新强>
根据评论,我会澄清答案。答案是假设代码仍然只是期望ANSi数据。否则,正如David M.指出的那样,更好的解决方案是将基础TNumber类更改为处理UnicodeString(即wchar_t)。
答案 1 :(得分:0)
“从不使用参数'发件人'”。