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
  • 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: http://www.bhnet.com.br/~simonet


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: http://www.bhnet.com.br/~simonet

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

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…
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…
Planning to migrate your EDB file(s) to a new or an existing Outlook PST file? This video will guide you how to convert EDB file(s) to PST. Besides this, it also describes, how one can easily search any item(s) from multiple folders or mailboxes…
Watch the video of Kernel Migrator for SharePoint, which demonstrate the process easily of migration from SharePoint to SharePoint, OneDrive for Business & Google Drive servers, Public Folder to SharePoint, File Server to SharePoint. The tool has va…

607 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