求助:C++ Builder 6错误:[Linker Error] Unresolved external '__fastcall TForm1::GetPYString(System::AnsiString)' referenced from E

时间:2021-01-08 04:51:54
错误:[Linker Error] Unresolved external '__fastcall TForm1::GetPYString(System::AnsiString)' referenced from E:\PROGRAM FILES\BORLAND\CBUILDER6\PROJECTS\UNIT1.OBJ
源代码:CPP文件:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
bool __fastcall In(int LowPosition,int HighPosition,int Value)
{
        return ((Value<=HighPosition) && (Value>=LowPosition));
}
//----------------------------------------------------------------------------
char __fastcall GetPYFirstChar(AnsiString HZ)
{
        WORD High=WORD(HZ[1]) << 8;
        WORD Low=BYTE(HZ[2]);
        int n=High+Low;
        if(In(0xB0A1,0xB0C4,n))
                return 'A';
        if(In(0xB0C5,0xB2C0,n))
                return 'B';
        if(In(0xB2C1,0xB4ED,n))
                return 'C';
        if(In(0xB4EE,0xB6E9,n))
                return 'D';
        if(In(0xB6EA,0xB7A1,n))
                return 'E';
        if(In(0xB7A2,0xB8C0,n))
                return 'F';
        if(In(0xB8C1,0xB9FD,n))
                return 'G';
        if(In(0xB9FE,0xBBF6,n))
                return 'H';
        if(In(0xBBF7,0xBFA5,n))
                return 'J';
        if(In(0xBFA6,0xC0AB,n))
                return 'K';
        if(In(0xC0AC,0xC2E7,n))
                return 'L';
        if(In(0xC2E8,0xC2E7,n))
                return 'M';
        if(In(0xC4C3,0xC5B5,n))
                return 'N';
        if(In(0xC5B6,0xC5BD,n))
                return 'O';
        if(In(0xC5BE,0xC6D9,n))
                return 'P';
        if(In(0xC6DA,0xC8BA,n))
                return 'Q';
        if(In(0xC8BB,0xC8F5,n))
                return 'R';
        if(In(0xC8F6,0xCBF0,n))
                return 'S';
        if(In(0xCBFA,0xCDD9,n))
                return 'T';
        if(In(0xCDDA,0xCEF3,n))
                return 'W';
        if(In(0xCEF4,0xD188,n))
                return 'X';
        if(In(0xD1B9,0xD4D0,n))
                return 'Y';
        if(In(0xD4D1,0xD7F9,n))
                return 'Z';
        return char(0);
}
//----------------------------------------------------------------------------
AnsiString __fastcall GetPYStirng(AnsiString InputHZString)
{
        AnsiString TempString,ReturnString;
        AnsiString Str=InputHZString.Trim();
        for(int i=1;i<Str.Length();i++)
        {
                if(isprint(Str[i]))
                {
                        ReturnString=ReturnString + Str[i];
                }
                else
                {
                        TempString+=Str[i];
                        if(TempString.Length()==2)
                        {
                                ReturnString=ReturnString +GetPYFirstChar(TempString);
                                TempString = " ";
                        }
                }
        }
        return ReturnString;
}
//-----------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
        if(this->Edit1->Text.Length()<1)
                return;
        this->Edit2->Text=GetPYString(this->Edit1->Text);
}
//---------------------------------------------------------------------------
************************
//Header文件:
//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
        TGroupBox *GroupBox1;
        TLabel *Label1;
        TEdit *Edit1;
        TLabel *Label2;
        TEdit *Edit2;
        TButton *Button1;
        TButton *Button2;
        void __fastcall Button1Click(TObject *Sender);
private: // User declarations
        __fastcall In(int LowPosition,int HighPosition,int Value);
        __fastcall GetPYFirstChar(AnsiString HZ);
        __fastcall GetPYString(AnsiString InputHZString);
public: // User declarations
        __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

4 个解决方案

#1


LONG

#2


把你的GetPYFirstChar函数和GetPYStirng函数定义成TForm1类的成员,如下所示:

char __fastcall TForm1::GetPYFirstChar(AnsiString HZ)
{
    //...
}
char __fastcall TForm1::GetPYStirng(AnsiString HZ)
{
    //...
}

#3


同意楼上,并补充:
怎么头文件中
__fastcall GetPYFirstChar(AnsiString HZ);
__fastcall GetPYString(AnsiString InputHZString);
没有返回类型?

#4


你想得到汉字的首拼音,此函数不知对大多数汉字无法得到,特别是拼音输入时后部分的汉字,即比较偏僻的,希望能有改进的方法.

#1


LONG

#2


把你的GetPYFirstChar函数和GetPYStirng函数定义成TForm1类的成员,如下所示:

char __fastcall TForm1::GetPYFirstChar(AnsiString HZ)
{
    //...
}
char __fastcall TForm1::GetPYStirng(AnsiString HZ)
{
    //...
}

#3


同意楼上,并补充:
怎么头文件中
__fastcall GetPYFirstChar(AnsiString HZ);
__fastcall GetPYString(AnsiString InputHZString);
没有返回类型?

#4


你想得到汉字的首拼音,此函数不知对大多数汉字无法得到,特别是拼音输入时后部分的汉字,即比较偏僻的,希望能有改进的方法.