Can you search for a graphic by name?

  • Let's say I want to do
    wprichtext1.InsertGraphic(extractfilepath(application.exename)+'Pin.bmp',false,[]);

    and I may do this 10 or more times in a document to mark positions in the text to come back and review later.
    Can I then search for the occurances of the Pin.bmp in the text to locate the position? Like using an HTML book mark in the file...

    thanks, d

    • Offizieller Beitrag

    Hi,

    it is possible to get a list of all objects using WPRixhText.TextObjects.List

    and there you can read the stream name.

    I don't think its a good idea though, I would rather use ownerepainted TWPTextObj instead images. The TWPTextObj are saved directly in the paragraph while the TWPObjects are data containers certain TWPTextObj refer to. (ObjRef property)

    See the annotation demo under tasks for an example.

    Julian

  • I am having a hard time understanding how to locate the object.
    I found these examples
    where does ('<<Graphic-Signature>>') and ('[sig]') come from?
    I just want to locate an object I put in with this code:

    Code
    postit := TWPOAnnotation.Create(WPRichText1.Memo.RTFData);
          postit.WidthTW := 300;
          postit.HeightTW := 650;
          postit.Caption := 'PostIt';
    
    
          // WPRichText1.Modified := True;
          WPRichText1.Textobjects.Insert(postit);

    examples from documentation on textobjects:
    begin
    GSFile := 'C:\testfile.jpg';
    if FileExists(GSFile) then
    with WPRichText1 do
    begin
    Finder.ToStart;
    while Finder.Next('<<Graphic-Signature>>') do
    begin
    TextObject := TWPOImage.Create(WPRichText1.Memo.RTFData); // !
    TextObject.LoadFromFile(GSFile);
    SetSelPosLen(Finder.FoundPosition, Finder.FoundLength);
    TextObjects.Insert(TextObject);
    end;
    end;
    end;
    Alternative, using a graphic from an TImage object:
    WPRichText1.Finder.ToStart;
    while WPRichText1.Finder.Next('[sig]') do
    begin
    WPRichText1.CPPosition := WPRichText1.Finder.FoundPosition;
    WPRichText1.Finder.FoundText := '';
    WPRichText1.TextObjects.InsertCopy(Image1.Picture.Graphic);
    end;

    • Offizieller Beitrag
    Zitat

    where does ('<<Graphic-Signature>>') and ('[sig]') come from?

    That is standard text inside the template. It is not the name of an object.

    Zitat

    I am having a hard time understanding how to locate the object.

    If you insert images without reference to a file you cannot loacte a filename. Only if you inserte links it makes sense to read out "StreamName". However you can assign a name when you insert an object.

    You get a reference to a TWPObject by InsertGraphic.
    You could set the property ObjName but that is not really useful, since the same objects can be used more than once in a file.

    You can use this code to insert your pin

    obj :=WPRichText1.TextObjects.InsertCopy(Image2.Picture.Graphic,300,300);
    obj.Name := 'XYZ'

    And this code to locate it later

    WPRichText1.CodeMoveTo('XYZ',wpobjImage, [], [wpCompareName]);