<< Click to Display Table of Contents >> Navigation: Programming > Objects > Images > C) Work with images > Images and Mailmerge |
This code will insert a mail merge field:
procedure TForm1.InsertImageFieldClick(Sender: TObject);
begin
WPRichText1.InputMergeField('IMAGEFIELD','[IMAGE]');
end;
This code launches the merge process
procedure TForm1.MergeTextClick(Sender: TObject);
begin
WPRichText1.MergeText;
end;
The event handler for inserts the image or replaces an existing image with different data.
procedure TForm1.WPRichText1MailMergeGetText(Sender: TObject;
const inspname: String; Contents: TWPMMInsertTextContents);
begin
if Contents.StartInspObject.Source<>'GREEN' then
begin
Contents.LoadImageFromFile(
ExtractFilePath(Application.ExeName) +
'green.bmp',-1,-1);
Contents.StartInspObject.Source := 'GREEN';
end
else
begin
Contents.LoadImageFromFile(
ExtractFilePath(Application.ExeName) +
'red.bmp',-1,-1);
Contents.StartInspObject.Source := 'RED';
end;
end;
We use Contents.LoadImageFromFile to load and update the image. The Parameters w and h are set to -1 to make it use the default size (=physical) or the current width and height.
The Source parameter of the image is used to remember which file was loaded. This makes it possible to toggle between two states.