Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Macro language for Delphi?



Permlink Replies: 10 - Last Post: Oct 9, 2017 11:42 PM Last Post By: Arnaud Bouchez
Ian Branch

Posts: 442
Registered: 9/23/99
Macro language for Delphi?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 2, 2017 10:53 PM
Hi Team,
Win 10, D10.2.1.

I'm sure there are more than one macro style language that can be embedded in Delphi. Or perhaps with native Delphi
code.

I currently fill the 'Text' field of an email with the following..
====================================================
eMail.Text := ' Appointment details as follows.' + #10 + #13 + 'The Appointment was sent by ' + msuUserID + #10 + #13 +
'The Job is for ' + sJobFor + #10 + #13 + 'Date Time = ' + Appointments.FieldByName('ApptDate').AsString + '
- ' +
Appointments.FieldByName('ApptTime').AsString + #10 + #13 + 'Job # = ' + Appointments.FieldByName('Job
#').AsString + #10 + #13 +
'Customer = ' + Appointments.FieldByName('Name').AsString + #10 + #13 + 'Details = ' +
Appointments.FieldByName('Description').AsString;
=====================================================

I would like to enable the users to write their own eMail.Text by them creating an external text file, or similar,
looking like the following..
=====================================================
Appointment details as follows.
The Appointment was sent by 111111.
The Job is for 222222.
Date Time = 333333 - 444444.
Job # = 555555.
Customer = 666666.
Details = 777777.
==================================================
Where:
111111 = User ID.
222222 = Who the appointment is for.
333333 = Appointment Date.
444444 = Appointment Time.
555555 = The relevant Job #.
666666 = The Customer's name.
777777 = The Job Details.
888888 = TBA. For future use.
999999 = TBA. For future use.
are database fields.

The concept is that the 'routine' would read the text file in, parse it to replace the 111111 - 999999 variables with
the relevant database/table field contents. This would then become the eMail.Text.

Thoughts/suggestions on how this might be efficiently achieved would be appreciated.

Regards & TIA,
Ian
Roy Lambert

Posts: 1,063
Registered: 8/7/01
Re: Macro language for Delphi?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 3, 2017 12:18 AM   in response to: Ian Branch in response to: Ian Branch
Ian

Looks like something to do with recruitment - my field.

You're (sort of) describing mailmerge. How you handle it depends on what you use to write the emails. These days I use WPTools which has mailmerge built in. If you're using a simple text editor then you'll need to implement your own.

First thing is to come up with a unique identifier that there's a merge field coming. Using 111111 may seem like a good idea but I will guarantee that at some point some one will enter that as part of the email.

With WPTools what I have is a drop down menu. Users type in the text of an email (templates can be created) and when a merge field is wanted click the drop down and select the appropriate field. That puts a unique merge marker (which includes a number) into the text for that field which is invisible to the user and a bit of text so they can see something there. When the email is sent the document is parsed and the merge fields extracted. The unique number is determined

if ValidNumber(SubFld(inspname, '_', 2)) then begin
FldType := SubFld(inspname, '_', 1);
FldNo := StrToInt(SubFld(inspname, '_', 2));

This is then passed to a routine which uses it to fetch the data from tables which is then used to replace the merge field in the document.

Contents.StringValue := GetFieldData(FldNo);

Because mailmerge is built into WPTools a lot of the work was already done for me. I'm working on something at the moment which will probably use KSDHTMLEdit rather than WPTools so I can do much prettier html and will be reinventing what I did for mailmerge before I bought WPTools.

With KSDHTMLEdit I'll probably use a pair of comments like <!- mmf_27 ->Contact's surname<!- mmf_27 -> All the user will see is Contact's surname

Roy Lambert

Ian Branch

Posts: 442
Registered: 9/23/99
Re: Macro language for Delphi?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 3, 2017 1:28 AM   in response to: Roy Lambert in response to: Roy Lambert
Thanks Roy,
I shall have a look at wptools has to offer.

Regards,
Ian
Roy Lambert

Posts: 1,063
Registered: 8/7/01
Re: Macro language for Delphi?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 3, 2017 1:42 AM   in response to: Ian Branch in response to: Ian Branch
Ian

Be warned - WPTools isn't cheap. You can also look at RichView - I think that has mailmerge and is a lot less pricey, there's even a lite version which I seem to recall is free.

Finally have a look at https://delphihtmlcomponents.com/editor.html - don't think it has mailmerge built in but easy enough to do.

Whereaouts are you based?

Roy Lambert

Matthew Jones

Posts: 337
Registered: 1/25/98
Re: Macro language for Delphi?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 3, 2017 1:53 AM   in response to: Ian Branch in response to: Ian Branch
Ian Branch wrote:

I'm sure there are more than one macro style language that can be embedded in Delphi. Or perhaps with native Delphi
code.

http://tmssoftware.com/site/scriptstudiopro.asp

I had a dig in my archive to see if I could find the one I used years ago to great effect, and it appears that it was Scripter Studio. Good pedigree.

Alex Sv

Posts: 92
Registered: 1/11/04
Re: Macro language for Delphi?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 3, 2017 10:12 AM   in response to: Ian Branch in response to: Ian Branch
HTML Editor Library has build-in mail merge fuunctionality, including
+ special tags which marks template as read-only and highlight it
+ template can have complex structure, f.e.
{{CUSTOMER.ADDRESS.ZIP}}
+ Editor has several display modes for template - name, caption, sample so template above will look like
CUSTOMER.ADDRESS.ZIP
Customer.Mail Address.ZIP Code
10840

+Editor has methods for registering templates and creating template menu
+ Library supports template functions, f.e.

{{#upper}} {{NAME}} {{/upper}}
Roy Lambert

Posts: 1,063
Registered: 8/7/01
Re: Macro language for Delphi?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 3, 2017 11:47 PM   in response to: Alex Sv in response to: Alex Sv
Alex

That must have been after I played with it. Good news though.

Roy Lambert

Ian Branch

Posts: 442
Registered: 9/23/99
Re: Macro language for Delphi?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 3, 2017 12:38 PM   in response to: Ian Branch in response to: Ian Branch
Hi Guys,
Thank you all for your suggestions. I have gone the simple, generic route. The following is my test unit code.
unit Unit3;
 
interface
 
uses
  Winapi.Windows, Winapi.Messages, System.AnsiStrings, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Data.DB, adsdata, adsfunc, adstable, adscnnct, Vcl.ExtDlgs;
 
type
  TForm3 = class(TForm)
    AdsConnection1: TAdsConnection;
    Appointments: TAdsTable;
    Button1: TButton;
    Memo1: TMemo;
    Memo2: TMemo;
    OTFD1: TOpenTextFileDialog;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form3: TForm3;
 
implementation
 
{$R *.dfm}
 
function StreamToString(const Stm: TStream): string;
var
  SS: TStringStream; // used to copy stream to string
begin
  // This TStreamStream constructor uses default ANSI encoding in Unicode
  // versions of Delphi.
  SS := TStringStream.Create('');
  try
    SS.CopyFrom(Stm, 0);
    Result := SS.DataString;
  finally
    SS.Free;
  end;
end;
 
function FileToString(const FileName: string): string;
var
  FS: TFileStream; // stream used to read file
begin
  FS := TFileStream.Create(FileName, fmOpenRead or fmShareDenyNone);
  try
    Result := StreamToString(FS); // uses default ANSI encoding
  finally
    FS.Free;
  end;
end;
 
procedure TForm3.Button1Click(Sender: TObject);
var
  sFile, sText, msUserID, sJobFor: string;
begin
  msUserID := 'IJB01';
  sJobFor := 'Ian Branch';
  //
  OTFD1.Execute;
  Edit1.Text := OTFD1.FileName;
  sFile := OTFD1.FileName;
  sText := FileToString(sFile);
  Memo1.Lines.Clear;
  Memo1.Lines.Add(sText);
  sText := ReplaceText(sText, '<<11>>', msUserID);
  sText := ReplaceText(sText, '<<22>>', sJobFor);
  //
  Appointments.Open;
  Appointments.AdsGotoRecord(13);	//  Go to a complete record.
  //
  sText := ReplaceText(sText, '<<33>>', Appointments.FieldByName('ApptDate').AsString);
  sText := ReplaceText(sText, '<<44>>', Appointments.FieldByName('ApptTime').AsString);
  sText := ReplaceText(sText, '<<55>>', Appointments.FieldByName('Job #').AsString);
  sText := ReplaceText(sText, '<<66>>', Appointments.FieldByName('Name').AsString);
  sText := ReplaceText(sText, '<<77>>', Appointments.FieldByName('Description').AsString);
  //
  Appointments.Close;
  //
  Memo2.Lines.Clear;
  Memo2.Lines.Add(sText);
end;
 
end.


Regards,
Ian
Roy Lambert

Posts: 1,063
Registered: 8/7/01
Re: Macro language for Delphi?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 3, 2017 11:50 PM   in response to: Ian Branch in response to: Ian Branch
Ian

That's pretty much what I used to do way back. I think the main difference is I used curly brackets

Roy Lambert

Bernd Maierhofer

Posts: 161
Registered: 9/27/99
Re: Macro language for Delphi?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 8, 2017 10:52 PM   in response to: Ian Branch in response to: Ian Branch
<ijbranch at outlook dot com> wrote:

Hi Team,
Win 10, D10.2.1.

I'm sure there are more than one macro style language that can be
embedded in Delphi. Or perhaps with native Delphi code.

I currently fill the 'Text' field of an email with the following..
====================================================
eMail.Text := ' Appointment details as follows.' + #10 + #13 + 'The
Appointment was sent by ' + msuUserID + #10 + #13 + 'The
Job is for ' + sJobFor + #10 + #13 + 'Date Time = ' +
Appointments.FieldByName('ApptDate').AsString + ' - ' +
Appointments.FieldByName('ApptTime').AsString + #10 + #13 + 'Job # =
' + Appointments.FieldByName('Job #').AsString + #10 + #13 +
'Customer = ' + Appointments.FieldByName('Name').AsString + #10 +
#13 + 'Details = ' +
Appointments.FieldByName('Description').AsString;
=====================================================

I would like to enable the users to write their own eMail.Text by
them creating an external text file, or similar, looking like the
following.. =====================================================
Appointment details as follows.
The Appointment was sent by 111111.
The Job is for 222222.
Date Time = 333333 - 444444.
Job # = 555555.
Customer = 666666.
Details = 777777.
==================================================
Where:
111111 = User ID.
222222 = Who the appointment is for.
333333 = Appointment Date.
444444 = Appointment Time.
555555 = The relevant Job #.
666666 = The Customer's name.
777777 = The Job Details.
888888 = TBA. For future use.
999999 = TBA. For future use.
are database fields.

The concept is that the 'routine' would read the text file in, parse
it to replace the 111111 - 999999 variables with the relevant
database/table field contents. This would then become the eMail.Text.

Thoughts/suggestions on how this might be efficiently achieved would
be appreciated.

Regards & TIA,
Ian

Maybe you want to have a look at
http://blog.synopse.info/post/2014/04/28/Mustache-Logic-less-templates-f
or-Delphi-part-1

HTH Bernd

--
Arnaud Bouchez

Posts: 137
Registered: 8/2/15
Re: Macro language for Delphi?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 9, 2017 11:42 PM   in response to: Bernd Maierhofer in response to: Bernd Maierhofer
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02