Hi Julian,
Is there a way in the WP4 top get the list of the merge fields in a single method like in WP5:
CodeListTags(wpobjMergeField, '*ALL*', True)
Or do I have to loop through all the Fields, that I "Find"
Thanks
The little green man
Hi Julian,
Is there a way in the WP4 top get the list of the merge fields in a single method like in WP5:
CodeListTags(wpobjMergeField, '*ALL*', True)
Or do I have to loop through all the Fields, that I "Find"
Thanks
The little green man
Excecute MergeText and fill a list with all fields which are reported to the event OnMailMergeGetText
I've create an event that will handle the problem I had in th OP
I can create a List of all the inspname EditFields for the document.
My problem is with the MergeText, I can't seem to figure out what step I'm forgetting ....
for i:= 0 to FEditor.HeaderFooter.Count - 1 do begin if not (FEditor.HeaderFooter.Items[i].Empty) then begin FEditor.HeaderFooter.Items[i].WorkOnText := True; FEditor.MergeText; end; end; FEditor.WorkOnText := wpBody; FEditor.MergeText;
I know I have seen a example on your site, but can't seem to find it, I just can't seem to make the Merge part work, this is the Merge Event
if dstMotsCles.Locate('DESCRIPTION', inspname, []) then
begin
try
// Field in query that contains the data
vFieldName := ParseNomChampsToAlias(dstMotsCles.FieldByName('NOMCHAMP').AsString);
// Content Options, deletes mergefield markers
//Contents.Options := [mmDeleteUntilFieldEnd];
// If the field is a Blob and not null, assign the data directly
if (qryGeneric.FieldByName(vFieldName).IsBlob) then
begin
// Blob is not of sub type text
if qryGeneric.FieldByName(vFieldName).Data.sqlsubtype <> isc_blob_text then
begin
// Insert an blob field image
vObjImage := TWPOImage.Create(FEditor);
vObjImage.FileExtension := 'BMP';
// Assign MemoryStream to TWPOImage object
vObjImage.LoadFromStream(GetBlobStream(vFieldName));
// Save Image for Compare test
if inspname = 'LOGO ETABLISSEMENT' then
vObjImage.SaveToFile(LOGO_FILE);
// Size of image
//vObjImage.WidthTW := vObjImage.ContentsWidth;
//vObjImage.HeightTW := vObjImage.ContentsHeight;
// If already replaced don't do nothing
if Contents.CurrentObject = nil then
begin
Contents.Options := Contents.Options + [mmInsertObject];
Contents.Obj := vObjImage;
end;
end
else
begin
vBlobText := TStringList.Create;
if qryGeneric.BlobToStrings(vFieldName, vBlobText) then
Contents.StringValue := vBlobText.Text;
end;
end
else
begin
try
Contents.StringValue := qryGeneric.FieldByName(vFieldName).AsString;
except
end;
end;
except
//Contents.Options := Contents.Options - [mmDeleteUntilFieldEnd];
end;
end;
end;
Alles anzeigen
TIA, for the help and suggestions...
the Little green man
Hi,
this is the full blown merge example incl images, what about this line in the event OnMailMergeGetText:
Contents.StringValue := qryGeneric.FieldByName(inspname).AsString;
Julian
the inspname is used to locate in a DataSet the map to the table-field pair that will contain the data to be inserted in the EditField.
Once it is located it's set to a local var
vFieldName := ParseNomChampsToAlias(dstMotsCles.FieldByName('NOMCHAMP').AsString);
...
Contents.StringValue := qryGeneric.FieldByName(vFieldName).AsString;
qryGeneric, is a TQuery, that has been built dynamically from the list of merge fields found in the current document being asked to merge.
I'm just trying to figure out what part I'm not doing right, because I can't see the values that were used to replace the MergeFields [inspname], but I see the values when debugging, that is returned by the query, but when looking at the end printed result I only see the static text that is in the document.... So that's why I think I'm just missing a small part for it to work ...
I have tried a couple of things but I can't make it work so far...
Any suggestions or questions are welcome.
The little green man
Hi,
please note, MaileMerge does not "replace" fields, it inserts the data after the "insertpoint". (In WPTools 5 it inserts BETWEEN start and end tag)
I hope you do not call MergeText for each field, such as MergeText('name'), MergeText('str') etc. That is not a perfect approach and can be the reson no field is merged since the field name ios not found.
Use MergeText('') and check for property inspname in the event.
I ask this because you equation
vFieldName := ParseNomChampsToAlias(dstMotsCles.FieldByName('NOMCHAMP').AsString);
does NOT have a variable.
Kind Regards,
Julian Ziersch
Zitat
please note, MaileMerge does not "replace" fields, it inserts the data after the "insertpoint". (In WPTools 5 it inserts BETWEEN start and end tag)I hope you do not call MergeText for each field, such as MergeText('name'), MergeText('str') etc. That is not a perfect approach and can be the reson no field is merged since the field name ios not found.
Use MergeText('') and check for property inspname in the event.
As I said in a previous post, this is the code that will call the MergeText event, no data manipulation with inspname at this point.
for i:= 0 to FEditor.HeaderFooter.Count - 1 do begin if not (FEditor.HeaderFooter.Items[i].Empty) then begin FEditor.HeaderFooter.Items[i].WorkOnText := True; FEditor.MergeText; end; end; FEditor.WorkOnText := wpBody; FEditor.MergeText;
As for this part of the code
This is just to get the name of the field in the generic query that is associated with the inspname and will have the data that needs to be merged in that position.
I know I'm not that far because when I debug I see that the right values are returned from the generic query, the part I still haven't figured out is why I can't see the values I have inserted in the document.
Is there any options I should make sure are set ?
Am I missing a key Refresh/ReformatAll/ or something else ?
I could create a sample that doesn't involve a database to show you the entire code, so you can see where I make my mistake.
The Little Green_Man
Hi,
please assign some fixed text to "StringValue" to make sure something is changed. This ParseNomChampsToAlias thing is too complicated for debugging.
A ReformatAll IS required after MergeText.
Julian
I'll work on that and keep you posted on the results.
Is a ReformatAll required for EACH call tp MergeText or just one after all is done ?
TIA,
The little green man