Delphi Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreDelphi Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 6th, 2009, 08:20 AM
riggd riggd is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2009
Posts: 2 riggd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 30 m 49 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old August 6th, 2009, 09:56 AM
murklys murklys is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2008
Posts: 381 murklys User rank is Sergeant (500 - 2000 Reputation Level)murklys User rank is Sergeant (500 - 2000 Reputation Level)murklys User rank is Sergeant (500 - 2000 Reputation Level)murklys User rank is Sergeant (500 - 2000 Reputation Level)murklys User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 19 h 50 m 7 sec
Reputation Power: 21
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.

Reply With Quote
  #3  
Old August 6th, 2009, 01:18 PM
clivew clivew is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 1,261 clivew User rank is Captain (20000 - 30000 Reputation Level)clivew User rank is Captain (20000 - 30000 Reputation Level)clivew User rank is Captain (20000 - 30000 Reputation Level)clivew User rank is Captain (20000 - 30000 Reputation Level)clivew User rank is Captain (20000 - 30000 Reputation Level)clivew User rank is Captain (20000 - 30000 Reputation Level)clivew User rank is Captain (20000 - 30000 Reputation Level)clivew User rank is Captain (20000 - 30000 Reputation Level)clivew User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 6 Days 22 h 2 m 47 sec
Reputation Power: 273
Try
Code:
ComPort1.Read(InBuffer[0],2);


Clive

Reply With Quote
  #4  
Old August 7th, 2009, 06:35 AM
riggd riggd is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2009
Posts: 2 riggd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 30 m 49 sec
Reputation Power: 0
Sorry guys but none of those ideas worked...

Reply With Quote
  #5  
Old August 7th, 2009, 09:39 AM
murklys murklys is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2008
Posts: 381 murklys User rank is Sergeant (500 - 2000 Reputation Level)murklys User rank is Sergeant (500 - 2000 Reputation Level)murklys User rank is Sergeant (500 - 2000 Reputation Level)murklys User rank is Sergeant (500 - 2000 Reputation Level)murklys User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 19 h 50 m 7 sec
Reputation Power: 21
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.

Reply With Quote
  #6  
Old August 7th, 2009, 12:30 PM
clivew clivew is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 1,261 clivew User rank is Captain (20000 - 30000 Reputation Level)clivew User rank is Captain (20000 - 30000 Reputation Level)clivew User rank is Captain (20000 - 30000 Reputation Level)clivew User rank is Captain (20000 - 30000 Reputation Level)clivew User rank is Captain (20000 - 30000 Reputation Level)clivew User rank is Captain (20000 - 30000 Reputation Level)clivew User rank is Captain (20000 - 30000 Reputation Level)clivew User rank is Captain (20000 - 30000 Reputation Level)clivew User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 6 Days 22 h 2 m 47 sec
Reputation Power: 273
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);

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > Incompatible types: Array and PAnsiChar


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek