Solved

Read Text File Lines in Seperate Variables

Posted on 2002-06-16
7
145 Views
Last Modified: 2010-04-04
Hello its me again dinkleburger
I have a text file
in C:\windows\FILENAME.txt

the file looks like this

Line1 WHO
Line2 WHAT
Line3 WHY
Line4 WHERE
Line5 WHEN
Line6 HOW

QUESTION TIME     i want a procedure to read this File and Put WHO in Variable1

WHAT in Variable2
WHY in Variable3 etc etc

Thanks in advance again...
0
Comment
Question by:Dinkleburger
  • 4
  • 2
7 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 50 total points
Comment Utility
hmm, what about

var
  sl : tstringlist;
begin
  sl := tstringlist.create;
  try
    sl.loadfronfile('C:\windows\FILENAME.txt');
    variable1 := sl[0];
    variable2 := sl[1];
    ...
  finally
    sl.free;
  end;
end;

meikl ;-)

0
 

Author Comment

by:Dinkleburger
Comment Utility
Hello Kretzschmar
i am getting undeclared identifier  loadfronfile ??
thanks
0
 

Author Comment

by:Dinkleburger
Comment Utility
Hello Kretzschmar
i am getting undeclared identifier  loadfronfile ??
thanks
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:Dinkleburger
Comment Utility
I found the problem with the undeclred identifier
fronfile was fromfile lol typo (smiles)

i guess its nearly there

with   variable1 := sl[0];
       variable2 := sl[1];
   i get incompatible types String and Pchar
how do i fix this
thanks Kretzschmar





0
 
LVL 44

Expert Comment

by:CrazyOne
Comment Utility
What type is Variable1, Variable, etc declared as.

If they are declared as PChar then either change them to a string or

variable1 := PChar(sl[0]);


The Crazy One
0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
yep, was a typo,
for conversion see crazyone's comment
(didn't know that your variableX are PChars)

meikl ;-)

0
 

Author Comment

by:Dinkleburger
Comment Utility
Thanks people
that works fine
Regards Dinkleburger
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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 Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

12 Experts available now in Live!

Get 1:1 Help Now