Creating a "branching" document

  • My objective is to create a script (think survey document or sales call) which will branch if a whatever is clicked in the document. The type of branching will probably be to load another document.

    At its simplest think click YES load document 2 click NO stay in document 1, but at another point YES may mean stay in document 1 and NO load document 23.

    The text displayed and the action will be user settable.

    I want to use hyperlinks and images as normal so it looks as though TextObjects are what I want, but from the demo I can't see how to do it (WPRichText1TextObjGetTextEx is not the way).

    Any suggestions?

    • Offizieller Beitrag

    Hi,

    You really need hyperlinkls. Use the even "HyperlinkEvent" - it is called with the URL mentioned in the link property. TextObjects are not for links.

    But this applies to WPTools, not WPViewPDF.

    There also an event is triggered before a hyperlink is executed.

    This makes it possible to load a different PDF document, there, too.

    Julian

  • Julian

    I'd like to leave hyperlinks for hyperlinks so that users don't get confused. I'm assuming that there is only one style for hyperlinks - eg underlined blue or is it possible to have multiple styles?

  • Is there any way of setting the properties of a text object? I've looked at the bookmark demo and the textobject demo, read the help and battered my head against a nearby wall and all I can manage so far is the name (via your functions) and the Tag via SetTag.

    My ideal would be Extra, but I could make do with EmbeddedText

    • Offizieller Beitrag

    Hi,

    No, SetTag may not be used. That is the internal reference number and may not be used.

    Exception: There are some examples which create a pair of objects (hyperlinks, bookmarks) which use endobj.SetTag( startobj.NewTag ).

    You should use the string property
    obj.Source

    for your link data.

    Instead of damaging Your head or possibly the wall :-) please check out the source code. Even the standard version includes lots of it - and good coding examples can be found in the unit WPCtrMemo, WPCtrRich, WPIOHTML, not to mention the 50+ demo projects.

    EmbeddedText is used for paired objects, fields, links and bookmarks. TextObjects use name, Source and Params.

    I move this to WPTools.

    Julian

  • Can you tell me where in the source or demos to look for the answer to this:

    procedure TForm1.Button2Click(Sender: TObject);
    begin
    with WPRichText1.InputTextFieldName('NLH') do begin
    Source:='Branch';
    Params := 'ParamString';
    end;

    procedure TForm1.WPRichText1TextObjGetTextEx(RefCanvas: TCanvas;
    TXTObject: TWPTextObj; var PrintString: WideString; var WidthInPix,
    HeightInPix: Integer; var PaintObject: TWPTextObj; Xres, YRes: Integer);
    begin
    if TXTObject.Name='NLH' then
    begin
    WidthInPix := RefCanvas.TextWidth(TXTObject.Name+#32);
    TXTObject.OnPaint := OnPaintNLH;
    // This line is required:
    PaintObject := TXTObject;
    end ;
    end;

    procedure TForm1.OnPaintNLH(Sender : TWPTextObj;
    OutCanvas : TCanvas;
    XRes, YRes : Integer;
    X, Y, W, H, BASE: Integer );
    var
    o : Integer;
    s:string;
    begin
    { OutCanvas.Rectangle(x,y,x+w,y+h);
    OutCanvas.MoveTo(x+w,y+1);
    OutCanvas.LineTo(x+w,y+h);
    OutCanvas.LineTo(x+1,y+h); }
    OutCanvas.TextOut(x+2,y+BASE,Sender.Name);
    end;

    The displayed output is overlaid by ParamString

  • If frame doesn't work how can I get text centred in a rectangle regardless of font size.

    Using the TWPTextObj.OnPaint event and adapting your code I can centre the text horizontally but not vertically. I have no idea what the BASE parameter refers to, and the normal approach

    OutCanvas.Rectangle(x, y , x + w, y + h);
    OutCanvas.MoveTo(x + w, y + 1);
    OutCanvas.LineTo(x + w, y + h);
    OutCanvas.LineTo(x + 1, y + h);
    OutCanvas.TextOut(x + 2, y + 2, ' ' + Sender.Name);

    Leaves the text sitting on top of the rectangle.

    The adjustment needed is dependant (I think) in some way on the font size but I can't figure out the relationship.

  • >You need to clear

    >PrintString

    That's fixed - thanks

    >You can draw pretty much everything on OnPaint, also frames.

    >The bookmarkdemo shows how.

    That's exactly what I used as a start point

    >For the text you need to use SetAlign API - it defaults to baseline since
    >this is used by WPTools.

    I've looked in your OLH, D2006's OLH and google - where do I find this SetAlign?

  • Very nearly there now. The last bit is how to make the frame properly font size independent.

    What I have is:

    procedure TForm1.OnPaintNLH(Sender: TWPTextObj;
    OutCanvas: TCanvas;
    XRes, YRes: Integer;
    X, Y, W, H, BASE: Integer);
    var
    xFrame, yFrame, hFrame, wFrame: integer;
    begin
    xFrame := x - 5;
    yFrame := y - 5;
    hFrame := h + 10;
    wFrame := w + 5;
    OutCanvas.Brush.Color := clBtnFace;
    OutCanvas.Font.Color := clBlack;
    OutCanvas.Rectangle(xFrame, yFrame, xFrame + wFrame, yFrame + hFrame);
    OutCanvas.MoveTo(xFrame + wFrame, yFrame + 1);
    OutCanvas.LineTo(xFrame + wFrame, yFrame + hFrame);
    OutCanvas.LineTo(xFrame + 1, yFrame + hFrame + 1);
    OutCanvas.Font.Height := -Round(YRes / 72 * StrToInt(edit1.Text));
    SetTextAlign(OutCanvas.Handle, TA_TOP);
    OutCanvas.TextOut(x + OutCanvas.TextWidth(Sender.Name[1]), y, Sender.Name);
    SetTextAlign(OutCanvas.Handle, TA_BASELINE);
    end;

    Which is great for 16pt but if I use say 9pt or 36pt the extra framing lines are wrong.