|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| ||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Incompatible types: Array and PAnsiChar
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 at Line 45: Incompatible types: 'Array' and 'PAnsiChar' The error points to this line 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. |
|
#2
|
|||
|
|||
|
Can't say for sure, but you may try two things that won't kill you and might help:
maybe: Code:
ComPort1.Read(InBuffer^,2); or maybe: Code:
var InBuffer:array[0..1] of CHAR; or a combination of both Can't give any guarantee any of this will work, but won't hurt to try. |
|
#3
|
|||
|
|||
|
Try
Code:
ComPort1.Read(InBuffer[0],2); Clive |
|
#4
|
|||
|
|||
|
Sorry guys but none of those ideas worked...
|
|
#5
|
|||
|
|||
|
Damn it works with streams so what's with this com port thing ... hm ... Maybe there is a method like ReadChar there? You could use it two times to read a character in the worst case. You could probably define the buffer as PChar and Read(p^, 2) or is it Read(p, 2) ... but i'm not sure how you would get the bytes out of that damn pchar after that.
|
|
#6
|
|||
|
|||
|
Did you try?
Code:
var InBuffer:array[0..1] of AnsiChar; ComPort1.Read(InBuffer[0],2); or maybe Code:
var InBuffer:array[0..1] of AnsiChar; ComPort1.Read(pAnsiChar(InBuffer[0]),2); |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Delphi Programming > Incompatible types: Array and PAnsiChar |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|