Solved

Converting a string to an Array

Posted on 2000-04-25
7
207 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
  • 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
Technology Partners: 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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to debug For loops? 3 60
Why can't I create any project with my delphi EXE file? 6 43
Get weeknumber and year from date 4 25
Using MMsystem To change audio input 1 14
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 The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

679 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