• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 273
  • Last Modified:

Array and dynamic Array , does Aarry name represent first address?

 declare---function test(Avalue:pchar);  

use:
var
  lack: array[0..19] of char;
  lace: array of char ;
 begin
   test(lack);//sucess;
   setlength(lace,20);
   for Index:=0 to SizeOf(lace) do
     lace[Index]:=#255;
   test(lace);//cannot compile ,,why?
 end;

which one can tell me why?

if i use dynamic array ,how can i realize it ?

thank you in advance !




0
bloodbird
Asked:
bloodbird
2 Solutions
 
bloodbirdAuthor Commented:
up
0
 
KalrothCommented:
Hi bloodbird,

I hope this is good enough for you.

(*** CODE ***)

procedure AProc( Value: PChar );
begin
  ShowMessage(Value);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  lack : array[0..19] of Char;
  lace : array of Char;
  idx : Integer;
begin
  lack := '--------------------';
  AProc(lack);

  SetLength(lace,20);
  for idx := Low(lace) to High(lace) do
    lace[idx] := #$2D;

  AProc(@lace[Low(lace)]); // Pass pointer to first character in array.
end;

(*** /CODE ***)
0
 
nestoruaCommented:
HI,
You need only do the following: "test(PChar(lace));" instead of "test(lace);", that's all.
Sincerely,
Nestorua.
0
 
CleanupPingCommented:
bloodbird:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now