Re: Interfacing with Comm32 Component
- From: Jamie <jamie_ka1lpa_not_valid_after_ka1lpa_@xxxxxxxxxxx>
- Date: Fri, 18 Jan 2008 18:46:16 -0500
Andy Massey wrote:
Hello all,There lye a problem. You may have non null data at the end of the buffer
I am trying to use a Comm32 Component authored by David Wann in 1996 (http://www.programmersheaven.com/download/14247/download.aspx). I am using WinXP and have installed Delphi 2.0 in Win95 compatibility mode. I have installed the component in the Delphi component library and am now trying to interface to it.
My user program interfaces to the component using a Comm32 component event named "OnReceiveData".
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.
Roughly what I want to do is: Memo1.Lines.Append (Buffer); , but Buffer won't automatically cast into a string.
I haven't programmed in Delphi for 10 years, and I wasn't very good then. I've done my best to describe my question above, but I am unsure about the terms that I've used. If something doesn't make sense, I've probably used the wrong term to describe it.
Can somebody tell me how to get my Comm data from the Buffer variable to a string variable?
Thanks,
Andy Massey
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.
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;
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..
--
http://webpages.charter.net/jamie_5"
.
- Follow-Ups:
- Re: Interfacing with Comm32 Component
- From: Rob Kennedy
- Re: Interfacing with Comm32 Component
- References:
- Interfacing with Comm32 Component
- From: Andy Massey
- Interfacing with Comm32 Component
- Prev by Date: TImagelist problems
- Next by Date: Re: Interfacing with Comm32 Component
- Previous by thread: Re: Interfacing with Comm32 Component
- Next by thread: Re: Interfacing with Comm32 Component
- Index(es):
Relevant Pages
|