Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing variables to a text file? 1

Status
Not open for further replies.

reisende

Programmer
Mar 16, 2004
74
US
Question for everyone:

I want to use LoadFromFile('html.txt') to set the body of an Indy TIdMessage Body property to HTML that will be sent once some forms in my program are filled out and submitted.

The problem I'm having is that I need to be able to pass data from my InterBase database to the text file so the html email contains the data the user has just entered and I don't have to store a bunch of files on our server.

Is there any way to set place holders in a text file so variables can write to them? Or will I have to write the text file as I go in order to make sure the data is displayed correctly in the HTML?

I'm using a component that allows HTML in the body so I just need to get the variables passed correctly. I want to use the text file as a template so I don't have to put a couple hundred lines of HTML code in my Delphi source.

I hope this made sense. Thanks in advance.
 
If you put each of the tags that need data on it's own line in the file, you could then use the IndexOf method of the TStrings (which is what the Body property of TIdMessage is) to locate each line where you need to place data, put your data where it needs to go. It would look something like this:
Code:
  i := IdMessage1.Body.IndexOf('Data1 Here');
  if i >= 0 then
    IdMessage1.Body[i] := <whatever data it needs>;

-Dell
 
Thanks for the quick reply, Dell. I'll give that a try.
 
OK, here is what I have:

[tt]a := mMailer1.Body.IndexOf('clinic_name');
if a >= 0 then
mMailer1.Body[a] := dm_global_login.ib_select_allCM_CLINIC_NAME.AsString;[/tt]

[tt]clinic_name[/tt] is located in the file html.txt. I'm using [tt]mMailer1.Body.LoadFromFile('html.txt')[/tt] to load the file before attempting to input the data (in this case CM_CLINIC_NAME).

I've stepped through it and [tt]a[/tt] returns -1. is this right? I wouldn't expect to get a negative number.

Thanks again.
 
the -1 means it didn't find it. There is no index for 'clinic_name'.

Leslie
 
Do I need to set an index then? And if so, how?

I haven't used text files that much before and I'm still trying to learn as much as I can.
 
My bad, I forgot to put the string I'm replacing on its own line in the text file.

It's working now.

Thanks for your help, guys.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top