Change in inserting objects

  • <gulp> I guess I'm the first one to add an entry to this new forum...:)

    Julian, please feel free to correct any misstatements I make in what follows.

    In previous versions, if you wanted to fine-tune an inserted object, personalize it differently than the defaults, you might use code similar to the following:

    Code
    function Form1.InsertGraphicObject( strObjFilename : string ) : boolean;var  obj    : TWPObject;  wObj : word;  pObj : PTTextObj;begin   result := FALSE:   obj := WPLoadObjectFromFile( Self, strObjFilename, FALSE );   if( obj = nil ) then        exit;   obj.Transparent := TRUE;   wobj := WPRichText1.TextObjects.Insert( obj );   pObj := WPRichText1.TextObjects.TextObjectGet( wObj );   if( pObj <> nil ) then begin      pObj^.wrap := wpwrLeft;      pObj^.typ   := wpotPar;      Result := TRUE;   end;end;


    As you can see, start with Insert, which returns a value of type Word, which can then be passed to TextObjectGet, who would then return a pointer to a text object. That pointer would then be worked with, as shown above. It works, but it's a little Rube Goldberg-esque.

    With WPTools 5, the TextObjects.Insert function has changed. It no longer returns the ID (tag) of the inserted object. Now the reference to this object is returned directly!!! Talk about clean. And that's a good thing, with pointers no longer used in WPTools5.

    So the above snippet can now become simply:


    ---< Notes >---

    o If you still need a text object's tag/ID, get it with <TWPTextObj>.ID

    o InsertNameLink, InsertName, formerly in WPTools 4, have both been replaced with <TWPTextObj>.Insert

    o the Insert function now has some additional, optional parameters that you might find userful. Check it out in Help!

    o in WPTools5, WPLoadObjectFromFile's first parameter type has changed. In WPTools 4 it was of type TComponent, presumably the object's owner. Now, it's of type TWPRtfDataCollection.

    Hopefully that clears some things up, or might be the starting point for other WPTools users to expand on.

    There's a lot of power, and elegance, new with WPTools 5. This only begins to scratch the surface.

    I encourage anyone (and everyone) to please share your suggestions and solutions in this new forum Julian has created for our use. We all benefit! I look forward to seeing what others uncover, and create.

    JazzMan (aka diamond)

  • <ack> <yuck>

    Hey ya'll, I really don't code like it appears in this one. As I just found out, it seems my code formatting got done in by HTML, and/or the use of tab and spaces.

    Apologies to anyone who is put off by the monolithic look of the example code. I would (and did) react the same way...:)

    <hanging my head in shame>

    diamond

    • Offizieller Beitrag

    Diamond,

    many thanks for the article. You can, BTW - embed the code into CODE tags (in square parentheses) - so it will appear formatted as it was. I edited the article to include this tags.

    According to the text object tags:

    In WPTools 5 the tags were used to find a special record (the TTextObj) in a list. This means the tags were unique in a document, except for the times when they were also used in the undo buffer.
    The 'Tag' in WPTools 5 TWPTextObj is only used by objects which are used pairwise to find the sibling.

    The TWPTextObj in WPTools 5 is an object which is hosted by the TParagraph - it is never reused at a different position. But it is usually quite smalle since it is (as it was in V4) only a reference to probably much larger bitmap data.
    But in many cases this reference (to bitmap or TWPObject data) is not required. This is the case for hyperlinks, bookmarks, textfields, mailmerge fields. All these TWPTextObj have 'nil' in their ObjRef property.

    The TWPTextObj has several properties, most important 'Name' and 'Source' - which are used by the fields, links etc.
    For hyperlinks it is important to remember that 'NAME' is not the URL, 'Source' is. 'Name' will be used for a popup hin (title) later.

    All the different TWPTextObj are using the same class. (using inheritance here would slow down thing a lot since the 'is' operator is one of the slowest)

    Which the TWPTextObj is used for is distinguished by 'ObjType', a parameter of type

    Code
    TWPTextObjType = (    wpobjCustom, // can be anything     // These objects are usually used pairwise    wpobjMergeField, // Name=fieldname, Source=Command A field (used to be Insertpoint - now always use Start/End !    wpobjHyperlink, // Name=Title, Source = HREF, StyleName=class    wpobjBookmark, // Name=Title, Source = bookmark Name, StyleName=class    wpobjTextProtection, // Text cannot be edited within    wpobjSPANStyle, // Special texts styles , StyleName=class (=parstyle = name), Source=style as read from file    wpobjCode, // Custom Codes    // This objects are usually used sigular    wpobjTextObject, // A text object field (one char text, such as PAGE), Source=FieldMask    wpobjReference, // A page number    wpobjPageSize, // Set a new page size from here    wpobjPageProps, // reserved    wpobjFootnote, // Name=IntToStr(nr), IParam=Char(C), Source=string, Params=Format    wpobjImage, // a TWPObject  - referenced by ObjRef    wpobjHorizontalLine // used to be a TWPObject    );  TWPTextObjTypes = set of TWPTextObjType;

    If the object is used pairwise (such as a hyperlink) or a merge field is controlled by property Mode which is also a set:

    Other thoughts are very welcome :-)

    Julian