Solved

Read string into Array of Char?

Posted on 1998-05-20
4
292 Views
Last Modified: 2010-08-05
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.

Thanks.
0
Comment
Question by:sparklin
  • 2
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
kjteng earned 30 total points
Comment Utility
TRY THIS:

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

0
 

Author Comment

by:sparklin
Comment Utility
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.
0
 
LVL 2

Expert Comment

by:kjteng
Comment Utility
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+}
0
 

Author Comment

by:sparklin
Comment Utility
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.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now