Re: Interfacing with Comm32 Component



Jamie wrote:
There lye a problem. You may have non null data at the end of the buffer
and that may just lead into problems where it just keeps on reading along past the actual point of valid data.
This is what I would do to insure this won't happen.
Allocate the space for the buffer to what ever, and when setting up the
initial size of the buffer to the comm32 functions, report it as 1 less in size. This way it'll never fill up to the max point and not give you any room to trim the end.

Are you in change of allocating the buffer? Or does the library allocate and fill its own buffer, and then pass it to you once it's filled?

It's important for Andy to realize that if he's going to try the technique below, it's _required_ that he be in charge of allocating the buffer. The technique I showed in my other post will work in all cases, and although it looks like it's allocating an extra string variable, it's really not; passing a PChar to TStrings.Append would force conversion to a string anyway.

In the receive event, simply set the last byte just after the reported
received data count to 0.
APcharPointer := Pchar(Dword(BufferPointer)+BufferLength);

APCharPointer^ := #0; // this will insure you have the buffer terminated correctly.
I guess if you didn't want to use a another pointer for the end you
could do this.
Pchar(Dword(BufferPointer)+BufferLength)^ := #0;

If you want to avoid the arithmetic, the type cast to an unrelated type, and the pointer-dereference, you could write it like this instead:

PChar(BufferPointer)[BufferLength] := #0;

memo1.lines.append(Pchar(bufferPointer));

I don't know what kind of app you're doing how ever, considering it to
be a memo in use, you may want to think about deleting some old lines
when it starts to get filled up..



--
Rob
.



Relevant Pages

  • Changing output buffer size in dsp plugin
    ... I have created a plugin which is able both to increase and decrease the ... length of the buffer. ... therefore I need to find a way to realloc this output stream so it matches ... deallocating and allocating in the AllocateStreamingResources ...
    (microsoft.public.windowsmedia.sdk)
  • Re: Buffer or Realloc?
    ... better to allocate memory and realloc it for the size of the what is ... between deciding to use a fixed size buffer or allocating memory ...
    (comp.lang.c)
  • Re: [PATCHSET] printk: implement printk_header() and merging printk, take #3
    ... result TF isn't available and thus res printout is ... require allocating yest another temp buf and separating out res printing ... needed to allocate the buffer elsewhere than stack. ...
    (Linux-Kernel)
  • Re: String data input and storage
    ... As you can probably tell I dont have much coding practice, but I am trying to get there. ... saving some by not allocating memory that you will not be using. ... stdin kernel buffer into your process's buffer, ...
    (comp.lang.c)
  • Re: detecting characters on RS232-Interface
    ... at one time what I did was establish a receive buffer. ... If it wasn't the header char, ... > Sometimes this device also sends valid data. ... > Can I do this in realtime because the device does not support flow ...
    (microsoft.public.vb.general.discussion)