Re: Interfacing with Comm32 Component
- From: Rob Kennedy <me3@xxxxxxxxxxx>
- Date: Fri, 18 Jan 2008 18:39:02 -0600
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
.
- References:
- Interfacing with Comm32 Component
- From: Andy Massey
- Re: Interfacing with Comm32 Component
- From: Jamie
- Interfacing with Comm32 Component
- Prev by Date: Re: Interfacing with Comm32 Component
- Next by Date: Re: Delphi 5 server app as a dll without forms
- Previous by thread: Re: Interfacing with Comm32 Component
- Next by thread: Length of Tenumeration has got to be fixed/implemented
- Index(es):
Relevant Pages
|