Composite Document, with protected areas

  • Hi,

    I need to make a composite document, wich will be generate by "1 or N" documents.

    For example:

    I have 3 documents, wich have some information, paragraphs, etc..

    I need to unify them for print, actually I'm doing this:

    Zitat

    WPRichText.HideSelection;
    WPRichText.CPPosition := MaxInt;
    WPRichText.SelectionAsString := DM.cdsRI_ProtAPTEXTO.AsString;

    These "documents", are stored in many fields of my database, the user will add the right documents to the final report, and then print it.

    Everything is working OK, but I'd like to make these documents, that are add'ed, to be protected from editing, because If the user changes it, I dont know what he changed, and where to save it.

    I was thinking in add the documents as paragraphs, wich are protected, is that possible? Or do you have any suggestions on how can I do that?

    Thanks.

  • Zitat

    Everything is working OK, but I'd like to make these documents, that are add'ed, to be protected from editing, because If the user changes it, I dont know what he changed, and where to save it.


    Whould you like let the user edit the final document, and this changes reflect on fields?
    If the answer is yes u can use bookmark. Bookkmark is a text object and u can put information on Command or Source property. then before add a document u can do.

    <Bookmark1 Tabelax Campoy>
    Your first document
    <\Bookmark1 Tabelax Campoy>
    <Bookmark2 Tabelax Campoy>
    Your second document
    <\Bookmark2 Tabelax Campoy>
    <Bookmark3 Tabelax Campoy>
    Your third document
    <\Bookmark3 Tabelax Campoy>

    Then the user can edit the final document and u could do a For to get the content of each bookmark and change the original field.

    But if u dont like this. make your finaldocument readonly![/b]

  • Wow, thanks for fast replying :}

    I dont want to allow the user to change nothing on the text, but I need to let him "adjust" the form.

    For example, if one document that he added start on the last line of the page, he may want to use a blank line, and force that new content to start in a new page. This is just one case, but the user need to be able to fill the page as he wish.

    Thats why I thought in protected paragraphs, because the user can adjust the paragraphs on the page, but cant edit it's content.

    But I dont know how to insert a database field (using AsString) as a protected paragaph.

    Do you understand me? =o

  • Ok, I found a way to do that using:

    Then, on KeyPress event I check:

    Zitat

    if WPRichText.CPAttr.HasStyle(afsProtected) then
    Key := #0;

    But the problem is:

    I cant add text using "WPRichText.InputString(DM.cdsRI_ProtAPTEXTO.AsString);" because the text comes from a database field, this way the text look like this:

    Zitat

    {rtf1\ansi\deff0\uc1

    And using "WPRichText.SelectionAsString := DM.cdsRI_ProtAPTEXTO.AsString;", seens like the inserted text doesnt accept the "afsProtected" style.

    Any hints?

    Kym

    • Offizieller Beitrag

    Hi,

    The solution requires a callback. The same callback is used by the paste function - but you can create it manually.

    Code
    // This callback will be used right after the loading of the textprocedure TForm1.AfterLoadEvent(  RTFData: TWPRTFDataCollection; Stream: TStream;  Reader: TWPCustomTextReader; OnlyBodyText: Boolean;  var LoadedText: TWPRTFDataBlock);var aPar : TParagraph;    i : Integer;    atr : TWPStoredCharAttrInterface;begin  // Use a TWPStoredCharAttrInterface to update all character attributes  atr := TWPStoredCharAttrInterface.Create(RTFData);  aPar := LoadedText.FirstPar;  // Paragraph Loop  while aPar<>nil do  begin     aPar.ASet(WPAT_ParProtected, 1);     for i:=0 to aPar.CharCount-1 do     begin        atr.CharAttr := aPar.CharAttr[i];        atr.IncludeStyle(afsProtected);        aPar.CharAttr[i] := atr.CharAttr;     end;     aPar := aPar.next;  end;  atr.Free;end;

    Now you can save RTF text to a stream and load it using this callback

    I hope this helps,

    Julian

  • I'm trying to do the same thing now in Delphi 2010 with WPTools6 but the paragraph is not protected anymore, does anything changed from WPTools5 to 6 to do the same thing?

    Here's my code:

    Code
    var  mem : TMemoryStream;  myWP : TWPRichText;begin  inherited;  if modo_impressao then begin    try      myWP := TWPRichText.Create(Self);      myWP.Visible := False;      myWP.Parent  := frm_ri_prot_ap_editor;      myWP.Memo.DisableProtection;      myWP.HideSelection;      myWP.CPPosition := MaxInt;      myWP.CurrAttr.AddStyle([afsProtected]);      myWP.SelectionAsString := sds_ri_prot_apTEXTO.AsString;      myWP.CurrAttr.DeleteStyle([afsProtected]);      myWP.Memo.EnableProtection;      mem := TMemoryStream.Create;      try        myWP.SaveToStream(mem);        mem.Position := 0;        WPRichText.CPPosition := MaxInt;        WPRichText.Memo.LoadFromStream(mem, true, '', true, nil, AfterLoadEvent);        WPRichText.InsertPar;      finally        mem.Free;      end;    finally      FreeAndNil(myWP);    end;  end;

    And the AfterLoadEvent:

    Just to remember, I'm trying to add a text loaded from database as a protected paragraph into a WPRichText.

    Thanks in advance,
    Kym

    EDIT: The text is added to the WPRichText but its not protected!