Solved

Converting a string to an Array

Posted on 2000-04-25
7
208 Views
Last Modified: 2010-04-04
I'm Pulling information from a DataBase in the form of a string.  I need to know how to convert the data into an array.

D := Table1.FieldByName ('drives').AsString;

I have an array defined
MyArray : array[0..15] of char;
when I try to assign D to MyArray I keep getting incompatible types
'Array' 'String'  
MyArray := D;

I need to look at the data from the database one Character at a time.
0
Comment
Question by:msmouse
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 10

Accepted Solution

by:
Lischke earned 50 total points
ID: 2747126
Aside from the possibility to access each character separately by using D[x] you can do:

  PChar(@MayArray[0]) := Table1.FieldByName ('drives').AsString;

or

  Move(D[1], MyArray, Length(D));

Ciao, Mike
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2747134
Sorry, only the second solution works. Casting the array to anything does only produce the well known "left side cannot be assigned to" error.

Ciao, Mike
0
 
LVL 1

Expert Comment

by:msedi
ID: 2747183
Hello,

First, why don't you use a dynamic array. With the array you use, you are always fixed to a specific size. So try
 
  var
    MyArray : array of Char;

instead of your first thing. Then set the length of the array with SetLength(MyArray, e.g. 15). That's the first thing. You can access the array as usual.

After that you can get the value of your database with

var
  D : string;

begin  
  D := Table1.FieldByName      ('drives').AsString;

  if (D <> '') then
  begin
    MyArray[0] := D[1]; // First element in string
  end
  else MyArray := #0;
end;
   
0
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!

 
LVL 10

Expert Comment

by:Lischke
ID: 2747217
Hi msedi,

welcome on E-E :-) I want to let you know that proposing an answer is considered bad behaviour and against the rules here if someone else (in this case me :-)) has already commented to the question. Of course, if you are very sure you have the solution and all other just have given nonsense then proposing an answer is acceptable. But this usually happens very seldom and when using only comments then the questioneer can pick one and promote it to being an answer. Additionally, it happend quite often (also to me) that the proposed answer has been accepted accidently although another one was meant, because the questioneer thought the answer came from the same person as the previous comments.

Thank you and

Ciao, Mike
0
 
LVL 1

Expert Comment

by:msedi
ID: 2747561
Sorry,

I didn't see that.

Greetings, Martin
0
 
LVL 1

Author Comment

by:msmouse
ID: 2750198
msedi,  I tried your way but you get 'dynamic Array' 'char' error.

Lischke  The move function seems to be a step in the right direction, I'm not getting the types error.

0
 
LVL 1

Author Comment

by:msmouse
ID: 2750201
A step in the right direction, Now I just have to work with getting the array to do what I want.

Thanks
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

734 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