Page 1 of 1

Mailmerge, tags and TDBRichViewEdit

Posted: Fri May 13, 2016 10:24 pm
by PioPio
I am adding a mailmerge feature in my application and I have applied the idea in the example MailMergeI
The template is saved in a DB record and later on the application retrieves the template and replace the tags with the data.

For the template editing I drop a TDBRichViewEdit in a form, connect it to the DB and use the following code to add tags to the template:

Code: Select all

function TMyClass.GetFieldStyleNo: Integer;
var
  fi: TFontInfo;
begin
  fi := TFontInfo.Create(nil);
  fi.Assign(FRVEditor.Style.TextStyles[FRVEditor.CurTextStyleNo]);//FRVEditor is a TDBRichViewEdit object
  fi.Protection := [rvprModifyProtect, rvprConcateProtect, rvprDoNotAutoSwitch];
  Result := FRVEditor.Style.TextStyles.FindSuchStyle(0, fi, RVAllFontInfoProperties);
  if Result < 0 then
  begin
    Result := FRVEditor.Style.TextStyles.Count;
    FRVEditor.Style.TextStyles.Add;
    FRVEditor.Style.TextStyles[Result].Assign(fi);
    FRVEditor.Style.TextStyles[Result].Standard := False;
  end;
  fi.Free;
end;

procedure TMyClass.InsertTag(const TagName, MyTag: string);
begin
  FRVEditor.CurTextStyleNo := GetFieldStyleNo;
  FRVEditor.InsertStringTag(Tag, Tag);
  FRVEditor.SetFocus;
end;

When it comes to mailmerge instead I drop a TDBRichView component in a form, connect it with the DB and use the following code:

Code: Select all

  for i := 0 to FTemplate.ItemCount - 1 do//FTemplate is another TDBRichViewEdit object
  begin
    case FTemplate.RVData.GetItemStyle(i) of
      rvsLabel:
        begin
          // do something
        end;
    end;
  end;


When I test the application, FTemplate.RVData.GetItemStyle(i) returns 0 all the time

Where am I doing wrong ?

Many thanks
Alberto

Posted: Sun May 15, 2016 9:11 pm
by PioPio
I made one a short test. I dropped a TDBRichViewEdit and one TDBRichView on a form, connected both to a DB and linked to two different TRVStyle. Added two buttons with the following functionality:

Code: Select all

  TForm2 = class(TForm)
    DBRV: TDBRichView;
    DBRVE: TDBRichViewEdit;
    ...
  end;

// insert item
procedure TForm2.btnInsertTagClick(Sender: TObject);
var
  li: TRVLabelItemInfo;
begin
  li:=TRVLabelItemInfo.CreateEx(DBRVE.RVData,(DBRVE as TDBRichViewEdit).CurTextStyleNo,'123');
  li.Tag:='123';
  (DBRVE as TDBRichViewEdit).InsertItem('',li);
  PgTable1.Post;
end;

//check item
procedure TForm2.btnCheckTabClick(Sender: TObject);
var a,i:Integer;
begin
  for i := 0 to DBRV.ItemCount - 1 do
  begin
    case DBRV.GetItemStyle(i) of
      rvsLabel:
        begin
          // do something
        end;
    end;
  end;
end;
the "// do something" part is never executed. Why is it ? I followed the examples TemplateEditorLI and MailMergeLI

many thanks
Alberto

Posted: Sun May 15, 2016 9:36 pm
by PioPio
Ok, I have found the issue.

The problem was the Datafield was linked to a DB field text only. I connected it to a TBlobField field and it works now.

Alberto