Based on a discussion hold in AFP newsgroups about mail texts and templates to send we got the following results:
Starting with a solution that assembles the whole line for line:
<%
lcMessage = "Folgendes Objekt wurde neu angelegt: " + chr(13) + ;
lcplz +" "+ lcort + ", Objektart: " + cobjektart + ","+ chr(13) + ;
"Objektbeschreibung: " + lcanzeige + Space(20) + chr(13) + ;
"*********************************" + chr(13) + ;
"Ein Service der XXXXX Internetwerbung" + chr(13) + ;
"mailto:info@xxxxx.de"
...
%>
(modified)
we thumbled over the problem of carriage returns - actually Chr(13) + Chr(10) on Windows - and ended very quickly at this question:
How do you assemble your mail messages?
During the discussion three solutions made the race which provide more efficieny and more flexibility than hard-coding the text blocks inside an AFP document.
- Text..Endtext
- FileToStr() und TextMerge()
- Memo-Feld und TextMerge()
Solution #1: Text..EndText
This solutions was presented by Marco:
Text To lcMessage TextMerge NoShow
Dies ist der Mail-Body,
welcher an meinen Empfänger <<lcName>>
versandt wird.
Und so weiter...
EndText
The whole text is written the normal way. Because of the clause TextMerge any expressions surrounded by the delimiters << and >> VFP evaluates by default. These expressions could be any kind of variable, table field or function calls - TextMerge converts them automagically to character.
Solution #2: FileToStr() and TextMerge()
The second solution uses an external text file. This should be more flexible and elegant than placing the text inline.
lcTemplate = FileToStr(File.FullPath("message.txt"))
lcMessage = TextMerge(m.lcTemplate)
The interesting aspect in this case is that the template can be created and edited with any simple text editor - there is no need to stop AFP services - and in combination with HTML/XML you get really phantastic results...
The function TextMerge() does nearly the same as the TextMerge clause only as stand-alone function.
Solution #3: Memo field and TextMerge()
Again Marco did the logical and consequent steps based on the just mentioned solution.
Instead of using external files you place your templates into memo fields of your VFP database or varchar fields on a MS SQL Server.
lcMessage = TextMerge(myTable.Message)
Database and tables have to be open already and access to the field is granted.
Resumé
Well, all three solutions are more convenient than the original one. Which one you actually choose for your AFP application depends on your local needs and your experiences.
Maybe a small peek behind the scenes:
The ProLib-Shop uses each of those three solutions - dependend on the task and requirements:
- #1 mainly used during placing an order.
- #2 does all mail templates. This provides flexibility to our sales staff to modify the templates easily.
- solution #3 is used to present the products.
Okay, enough *g* - and again Active FoxPro Pages offers a lot of opportunities to solve a specific problem. So, it's on you if you do it the easy way and enjoy the whole stuff or not...
Enjoy the AFP FAQ, JoKi