Re: [Lazarus] Got Pointer, expected Open Array Of Char

2013-01-13 Thread leledumbo
 I think making src also a var parameter...

Or const since it's meant to be read only



--
View this message in context: 
http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-Got-Pointer-expected-Open-Array-Of-Char-tp4028513p4028521.html
Sent from the Free Pascal - Lazarus mailing list archive at Nabble.com.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Got Pointer, expected Open Array Of Char

2013-01-13 Thread Dave Coventry
On 13 January 2013 14:56, leledumbo leledumbo_c...@yahoo.co.id wrote:
 Or const since it's meant to be read only

Hmmm.

Doesn't help. Still getting the same error.

I've tried passing the src parameter as a Pointer and then casting it
as an array of Char.

procedure Copybytes(var dst: Pointer; src: Pointer; len: integer);
var
  i: integer;
  data_in,data_out: Array of Char;
begin
  data_in:=@src;
  data_out:=@dst;
  for i:=0 to len-1 do
  begin
data_out[i]:=data_in[i];
  end;
end;

Calling the procedure: Copybytes(@dst[dloc],@src[sloc],16);

I get the error

Error: Can't assign values to an address

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Got Pointer, expected Open Array Of Char

2013-01-13 Thread Howard Page-Clark

On 13/1/13 1:58, Dave Coventry wrote:

On 13 January 2013 14:56, leledumbo leledumbo_c...@yahoo.co.id wrote:

Or const since it's meant to be read only


Hmmm.

Doesn't help. Still getting the same error.

I've tried passing the src parameter as a Pointer and then casting it
as an array of Char.

procedure Copybytes(var dst: Pointer; src: Pointer; len: integer);
var
   i: integer;
   data_in,data_out: Array of Char;
begin
   data_in:=@src;
   data_out:=@dst;
   for i:=0 to len-1 do
   begin
 data_out[i]:=data_in[i];
   end;
end;

Calling the procedure: Copybytes(@dst[dloc],@src[sloc],16);

I get the error

Error: Can't assign values to an address


One source of confusion arises because your parameter declaration array 
of char in procedure Copybytes(var dst: array of Char ...

means something different from your variable declaration

var
 data_in, data_out: Array of Char;

where Array of Char denotes a dynamic array - rather different from 
the parameter-passing declaration.



--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Got Pointer, expected Open Array Of Char

2013-01-13 Thread leledumbo
Actually, rather than continuing this, if what you need is only to copy a
dynamic array then you can simply:

dst := Copy(src,0,Length(src));




--
View this message in context: 
http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-Got-Pointer-expected-Open-Array-Of-Char-tp4028513p4028525.html
Sent from the Free Pascal - Lazarus mailing list archive at Nabble.com.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Got Pointer, expected Open Array Of Char

2013-01-13 Thread Florian Klämpfl


leledumbo leledumbo_c...@yahoo.co.id schrieb:

Actually, rather than continuing this, if what you need is only to copy
a
dynamic array then you can simply:

dst := Copy(src,0,Length(src));

dst:=Copy(src);

works as well. 




--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Got Pointer, expected Open Array Of Char

2013-01-12 Thread Howard Page-Clark

On 12/1/13 6:10, Dave Coventry wrote:


dst and src are passed to the function that calls Copybytes();

function copy_compressed_bytes(var dst: array of Char; var dloc, sloc:
integer; src: array of Char;
   len: integer): integer;
begin
   Copybytes(@dst[dloc],@src[sloc],16);
   return 0;
end;


I think making src also a var parameter and structuring the signatures 
for the routines without @ as follows will work:


procedure Copybytes(var dst, src: array of Char; len: integer);
...

function copy_compressed_bytes(var dst: array of Char;
   var dloc, sloc:integer;
   src: array of Char;
   len: integer): integer;
begin
  Copybytes(dst[dloc],src[sloc],16);
  Exit(0);
end;


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] Got Pointer, expected Open Array Of Char

2013-01-11 Thread Dave Coventry
Hi,

I have a procedure defined as follows:

procedure Copybytes(var dst: array of Char; src: array of Char; len: integer);

If I call it using the following:

Copybytes(@dst[dloc],@src[sloc],16);

I get an error:

dwg.pas(116,36) Error: Incompatible type for arg no. 2: Got Pointer,
expected Open Array Of Char

Can anyone suggest a solution?

Kind Regards,

Dave Coventry

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Got Pointer, expected Open Array Of Char

2013-01-11 Thread leledumbo
What's the type of dst and src that you pass to the function? Array is not
pointer, and I have no idea about open array with var modifier. Open array
is compatible with any array (and its subarrays through slicing).



--
View this message in context: 
http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-Got-Pointer-expected-Open-Array-Of-Char-tp4028513p4028514.html
Sent from the Free Pascal - Lazarus mailing list archive at Nabble.com.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Got Pointer, expected Open Array Of Char

2013-01-11 Thread Dave Coventry
Hi, thanks for the response.

On 12 January 2013 07:51, leledumbo leledumbo_c...@yahoo.co.id wrote:
 What's the type of dst and src that you pass to the function? Array is not
 pointer, and I have no idea about open array with var modifier. Open array
 is compatible with any array (and its subarrays through slicing).

dst and src are passed to the function that calls Copybytes();

function copy_compressed_bytes(var dst: array of Char; var dloc, sloc:
integer; src: array of Char;
  len: integer): integer;
begin
  Copybytes(@dst[dloc],@src[sloc],16);
  return 0;
end;

You may be onto something. dst is passed as a *var* because I'm
interested in the destination array but can discard the src after it's
been read.

I'll look into how the memory is allocated for src.

Many thanks.

Dave

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus