Re: Interfacing with Comm32 Component



Andy Massey wrote:

Hello all,

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


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.
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";

.



Relevant Pages

  • Interfacing with Comm32 Component
    ... WinXP and have installed Delphi 2.0 in Win95 compatibility mode. ... My user program interfaces to the component using a Comm32 component event ... Buffer won't automatically cast into a string. ...
    (alt.comp.lang.borland-delphi)
  • Re: GetComputerName
    ... The use of a String as a buffer simplifies things substantially ... Delphi allows us to send it to APIs as a PChar ... Some APIs perform differently between versions of Windows ... Reporting the result of GetLastError is a pretty generic task ...
    (alt.comp.lang.borland-delphi)
  • Re: [OT] Re: Overflows in HMAC from LibTomCrypt
    ... is it somehow coincidence that MS are always having buffer ... > If Kylix has dynamic arrays, then it won't have buffer overflows, ... I'm on the Delphi side of this Delphi/Kylix beast :-), ...
    (sci.crypt)
  • Re: Text file question
    ... last non-blank one, using Delphi Readln. ... cluster of the file, or two clusters if the last is nearly empty, to ... if the temporary file is rapidly deleted it never will be written. ... An elegant way would be to Blockread into a buffer and open the buffer ...
    (alt.comp.lang.borland-delphi)
  • Re: How to drive an USB device in LABVIEW using call DLL node!Thanks...
    ... VAR parameters in Pascal (and Delphi is still Pascal in its syntax) ... Also the second parameter is a buffer. ...
    (comp.lang.labview)