Re: Interfacing with Comm32 Component



Rudy Velthuis wrote:
Andy Massey wrote:
The procedure in my user program is:
procedure TForm1.Comm321ReceiveData(Buffer: Pointer; BufferLength:
Word);

I can't figure out how to get the characters in the Buffer (type of
Pointer) into a string that I can use in a memo control.

Try:

Memo1.Lines.Append(PChar(Buffer));

Better yet:

var
s: AnsiString;
begin
SetString(s, Buffer, BufferLength);
Memo1.Lines.Add(s);
end;

The presence of a BufferLength parameter suggests that there won't necessarily be a null character marking the end of the buffer. There might even be null characters in the middle of the buffer.

--
Rob
.



Relevant Pages

  • Re: Delphi Quiz: SetLength( WideString, 10 );
    ... >> I call a function and the function returns a buffer of bytes. ... Let's assume it's a 16 bit unicode string. ... characters to a wide character encoding scheme such as Unicode. ...
    (alt.comp.lang.borland-delphi)
  • Re: Why crash ?
    ... Yes, but naively, I would assume that the optimal buffer size ... depended on a certain number of characters, ... small string optimization is that the std::string object has a certain ... If you allocate dynamic storage, the string object has to store ...
    (microsoft.public.vc.language)
  • Re: Why crash ?
    ... Yes, but naively, I would assume that the optimal buffer size ... depended on a certain number of characters, ... small string optimization is that the std::string object has a certain ... If you allocate dynamic storage, the string object has to store ...
    (microsoft.public.vc.language)
  • Re: max size for printf() format conversion?
    ... For example, %i should never convert to a string that is longer than the number of digits in INT_MAX, right? ... This limit goes up to 4095 characters. ... lower bound for or at least give an impression of sensible buffer sizes. ... If the format string contains "%s", of course, the result is limited only by the possible length of a string. ...
    (comp.lang.c)
  • Re: Search a binary file for a string... again! (its to slow)
    ... >>Im writing a program to search for a string in a binary file. ... > Most of the time the first character in the buffer won't match the first ... characters, then taking 3 steps back, and reading ...
    (comp.lang.c)