Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Incompatible types: Array and PAnsiChar

Status
Not open for further replies.

riggdd

Technical User
Aug 6, 2009
1
AU
I am trying to compile some example code, usb_cdc shown below, from sixca.com

After installing the TComPort component, required, and compiling I get an error message stating: Incompatible types: 'Array' and 'PAnsiChar'

The error points to line 45 in RED below: ComPort1.Read(InBuffer,2);

Can someone please explain or help with a solution?

Thanks
Don



unit main;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, CPort, ComCtrls;

type
TForm1 = class(TForm)
ComPort1: TComPort;
Edit1: TEdit;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
Label1: TLabel;
ProgressBar1: TProgressBar;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
procedure ComPort1RxChar(Sender: TObject; Count: Integer);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure CheckBox1Click(Sender: TObject);
procedure CheckBox2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
Out_Buffer:char;

implementation

{$R *.dfm}

procedure TForm1.ComPort1RxChar(Sender: TObject; Count: Integer);
var InBuffer:array[0..1] of byte;
ADC_Hi,ADC_lo:byte;
ADCRes:word;
volt:double;
begin
ComPort1.Read(InBuffer,2);
ADC_Hi:=InBuffer[0];
ADC_Lo:=InBuffer[1];
ADCRes:=(ADC_Hi shl 8) or ADC_Lo;
Volt:=(5*ADCRes)/$3FF;
edit1.Text:=FloatToStrF(Volt,ffFixed,3,2);
Progressbar1.Position:=round((100*ADCRes)/$3FF);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Comport1.Open;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Comport1.Close;
end;

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
if CheckBox1.Checked then
ComPort1.WriteStr('1')
else
ComPort1.WriteStr('2');
end;

procedure TForm1.CheckBox2Click(Sender: TObject);
begin
if CheckBox2.Checked then
ComPort1.WriteStr('3')
else
ComPort1.WriteStr('4');
end;

end.
 
After installing the TComPort component, required, and compiling I get an error message stating: Incompatible types: 'Array' and 'PAnsiChar'

The method is expecting one type of parm (PAnsiChar) and you are giving it another (Array).

Code:
InBuffer:array[0..1] of byte;

ComPort1.Read(InBuffer,2);

PAnsiChar is a pointer to a string comprised of ANSI characters. I don't know how this method works, so I can't say for certain how to fix it, but the first thing I would try is to pass the pointer address of InBuffer[0] to the method and then insure there is always a null character ($00) at the end of Inbuffer.

Measurement is not management.
 
if you want to do serial communication, I strongly suggest you take a look at turbopower's tpapro. Some years ago this was payware but they went broke and the dev's decided to opensource the project. Here's the link:

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Second daddy's suggestion. I was actually a paying customer for Turbo Power Apro "some years ago". Great stuff. Source code is included so you can really learn from it!

Roo
Delphi Rules!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top