Read string into Array of Char?

How would I go about reading a string variable into a Character array.  e.g.

Message : array[1..30] of char;

I would like to read in the string variable from a TFileListBox.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


procedure StringToArray(var  arr: array of char; inStr: string);
var i, last:integer;
  last:= length( inStr);
  for i:=0 to high(arr) do
    if i<last then
      arr[i]:= inStr[i+1]
      arr[i]:=' ';


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sparklinAuthor Commented:
This procedure does not seem to work in Delphi 3 as the string and char variables in the line: arr[i]:= inStr[i+1]   are not compatible.
I compiled the code in both on D1 and D3. Seems no problem.
Why are arr[i] and instr[i+1] not compatible? i thought they are both char type.
Did you use any compiler directive in your program? I am using default setting ie. {$H+}
sparklinAuthor Commented:
My misttake..Sorry.  YOUR code is fine but I still had the array[1.14] OFCHAR variable defined.  Array of char works fine.

Thanks again.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.