Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
331 views
in Technique[技术] by (71.8m points)

c++ - Indy10中是否有一个称为ReadBuffer的indy9函数?(Is there an indy9 function called ReadBuffer in Indy10?)

This code is written by Borland Cpp Builder6 in Indy9.

(该代码由Indy9中的Borland Cpp Builder6编写。)

void __fastcall TfrmMain::ServerConnect(TIdPeerThread *AThread)
{
     BKUK_PACKET Pkt;
----------(中略)---------------------------------------

AThread->Connection->ReadBuffer((BYTE *)&Pkt,sizeof(BKUK_PACKET));

----------(中略)---------------------------------------
}

The function named ReadBuffer is not found in Indy10.

(在Indy10中找不到名为ReadBuffer的函数。)

Is there an equivalent function?

(有等效功能吗?)

BKUK_PACKET is a structure of about 1200 bytes.

(BKUK_PACKET是大约1200个字节的结构。)

typedef struct _BKUK_PACKET_
{
    BYTE head[4];
    WORD PayLoad;
    WORD Length;
    BYTE Data[1200];
    WORD Ver;
    BYTE tail[2];
}BKUK_PACKET;

I found ReadBytes when I was looking at the instruction manual for Indy10.

(我在查看Indy10的使用手册时发现了ReadBytes。)

Context->Connection->IOHandler->ReadBytes((BYTE *)&Pkt,sizeof(BKUK_PACKET))

When I tried to program as above, I got the following error:

(当我尝试如上所述编程时,出现以下错误:)

[bcc32c error] Main.cpp(530): non-const lvalue reference to type 'Idglobal::TIdBytes' (aka 'DynamicArray') cannot bind to a temporary of type 'BYTE *' (aka 'unsigned char *') IdIOHandler.hpp(235): passing argument to parameter 'VBuffer' here

([bcc32c错误] Main.cpp(530):对类型'Idglobal :: TIdBytes'(又名'DynamicArray')的非常量左值引用无法绑定到类型为'BYTE *'(又名'unsigned char *')的临时IdIOHandler .hpp(235):在此处将参数传递给参数“ VBuffer”)

Please tell me how to fix it.

(请告诉我如何解决。)

Thanks

(谢谢)

  ask by nordsynth translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The signature of ReadBytes() is

(ReadBytes()的签名是)

virtual void __fastcall ReadBytes(Idglobal::TIdBytes &VBuffer, 
                                  int AByteCount,
                                  bool AAppend = true);

TIdBytes is a type that represents a platform-agnostic representation for string data type and its dynamic nature makes ReadBytes() not a good choice for what you are trying to achieve.

(TIdBytes是一种表示与字符串数据类型无关的平台表示形式的类型,它的动态性质使ReadBytes()并不是您要实现的目标的不错选择。)

You could however use TIdIOHandler 's

(但是,您可以使用TIdIOHandler的)

System::Byte __fastcall ReadByte();

and create your own function to populate objects:

(并创建自己的函数来填充对象:)

template<typename T>
void __fastcall Populate(T& obj, TIdIOHandler* ioh) {
    System::Byte* p = (System::Byte*) &obj;
    for(unsigned count=0; count<sizeof(T); ++count, ++p)
        *p = ioh->ReadByte();
}

and use it like this:

(并像这样使用它:)

BKUK_PACKET Pkt;
Populate(Pkt, Context->Connection->IOHandler);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...