Solved

Copying a binary buffer to a TIdBytes object

Posted on 2013-01-28
3
1,317 Views
Last Modified: 2013-02-03
I am using Indy10 with C++ builder XE2 and I want to send a packet of binary data using a UDPServer control. I have a plain buffer of data to send in an array of unsigned chars.
Can someone explain how to move data from a plain character array to a TIdBytes object

The code is as follows :

unsigned char buff[566];
TIdBytes ABuffer;

SetupBuffer(buff) // data is prepared for sending (566 bytes)

// .....  some code needed to move the buffer into the TIdBytes buffer ??

// now send the data using UDP to a remote host listening on port 10036

IdUDPServer1->SendBuffer(remotehost,10036,ABuffer);

Thanks,

Roger
0
Comment
Question by:alcindor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 38827408
That could be

unsigned char buff[566];
TIdBytes ABuffer;

ABuffer.Length = 256;

for (int i = 0; i < 256; ++i)
  ABuffer[i] = buff[i];

Open in new window


But IMHO it might be easier to pass ABuffer to 'SetupBuffer()' instead.
0
 
LVL 2

Accepted Solution

by:
alcindor earned 0 total points
ID: 38830557
I have found the answer:

ABuffer.set_length(sizeof(buff));
ABuffer =  RawToBytes(buff, sizeof(buff));
0
 
LVL 2

Author Closing Comment

by:alcindor
ID: 38848251
I found the solution myself
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question