Solved

Read Text File Lines in Seperate Variables

Posted on 2002-06-16
7
150 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
[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
  • 4
  • 2
7 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 50 total points
ID: 7082127
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
ID: 7082373
Hello Kretzschmar
i am getting undeclared identifier  loadfronfile ??
thanks
0
 

Author Comment

by:Dinkleburger
ID: 7082413
Hello Kretzschmar
i am getting undeclared identifier  loadfronfile ??
thanks
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!

 

Author Comment

by:Dinkleburger
ID: 7082438
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
ID: 7082812
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
ID: 7083132
yep, was a typo,
for conversion see crazyone's comment
(didn't know that your variableX are PChars)

meikl ;-)

0
 

Author Comment

by:Dinkleburger
ID: 7084121
Thanks people
that works fine
Regards Dinkleburger
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

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…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

696 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