Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Help! I can't get this right ....

Posted on 1999-07-17
Medium Priority
Last Modified: 2010-04-06
This may sound silly, but no matter what I try, I just can't get this right.

Here's my problem

My friend asked me to create a program that simply reads info from a text file and converts it to an index of links.
He has a txt file containing descriptions, type and url of hundreds of webpages and he wanted me to create a program that would open up the file and create one link from each 3 lines in the file.

This is the format of the file:

[Description of page1]
[Type of page1]
[URL of page1]
[Description of page2]
[Type of page2]
[URL of page2]
etc ....

I have two richedit controls, one loads up the file
and the other one displays the file after conversion.
Then I have one button, and when I click it
the program has to add one line to richedit2 from
every three lines in richedit1, thus creating a link
with the description, type and url.

So, each line in richedit2 should look like this
<A HREF="[URL of page1]">[Description of page1], [Type of page1]</A>

Hope someone can show me how to do this!
Question by:hagur
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
  • 2
LVL 15

Accepted Solution

simonet earned 600 total points
ID: 1389247
Here it goes, hagur:

 RE_LINE = '<A HREF="%s">%s, %s</A>';
  URL, Desc, PType : string;
  fin : textfile;
  AssignFile(fin, 'C:\your_file_goes_here.txt');
     while not eof(fin) do
        Readln(fin, Desc);
        Readln(fin, PType);
        Readln(fin, URL);
        RichEdit1.lines.add(Format(RE_LINE, [URL, Desc, Type]));

That's it. There might be some types in the code above, since I wrote it "on the fly" while answering this Q, but it's nothing that crucial.

Let me know if you have more questions on this.


Athena's Place:


Author Comment

ID: 1389248
Excellent, superb! This is exactly what I needed and it's
fast too. Much faster than reading through the file
for counter := re1.lines.count -1 do

Thank's simonet!

LVL 15

Expert Comment

ID: 1389249
Anytime, man!

Just a note: anytime you want to concatenate more than 2 strings, or even concatenate numbers to strings (using IntToStr, FloatToStr, DateTimeToStr), use the Format function. It's a lot faster than using the " + " operator.

Thus, the line:
 RichEdit1.lines.add(Format(RE_LINE, [URL, Desc, Type]));

will run *a lot* (and I mean *A LOT*) faster than creating the string using "+" to concatenate the strings.


Athena's Place:

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

705 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