InsertNewObject Method

[Top]  [Chapter]  [Previous]  [Next]

Applies to

IWPParInterface

Declaration

function InsertNewObject(Index: Integer; ObjType: Integer; HasClosing: WordBool; ClosingOfPtr: IntPtr; CharAttrIndex: Integer; const Name: WideString; const Command: WideString): Integer;

Description

This method creates a new object in the paragraph. The result is the ID of the object, it is != 0 if the insertion was successful. This method can also be used to create paired objects, such as hyperlinks, bookmarks or merge fields. You can use the result value in a subsequent call to this function as value for parameter ClosingOfPtr.

 

This procedure can be useful to create links and bookmarks in an event, such as OnEnumParOrStyle without having to change the cursor position. It can also be used to insert images.

 

Note: You can use GetCharObj to acquire an interface to manipulate the object.

Parameters

Index

The position to insert the object. Use a large integer to append at the end of the paragraph.

ObjType

The object type.

HasClosing

If true a paired object will be created.

ClosingOfPtr

The ID of the start object. This object ID was returned by a previous call to InsertNewObject.

CharAttrIndex

The CharAttr index to be used for the new object placeholder.

Name

The name of the object.

Command

The command for this object, hyperlinks use this parameter as URL.

Category

Image Support


 

InsertNewObject Example

 

This event handler creates an image object in all paragraphs and loads an image file.

private void wpdllInt1_OnEnumParOrStyle(

 object Sender,

 bool IsControlPar,

 int StartPos,

 int Count,

 WPDynamic.IWPParInterface ParText,

 WPDynamic.IWPAttrInterface ParAttr,

 int EventParam,

 ref bool Abort)

{

// Make sure there is an image place holder at the start of the paragraph

WPDynamic.IWPTextObj obj = ParText.CharObj(0);

if ((obj==null)||  (obj.ObjType!=WPDynamic.TextObjTypes.wpobjImage))

{

 if(ParText.InsertNewObject(0,(int)WPDynamic.TextObjTypes.wpobjImage,false,

 0, 0, "", "")==0) obj=null;

 else obj = ParText.CharObj(0);

}

// Now update the image placeholder by loading a PNG file

if(obj!=null)

{

 obj.LoadFromFile("c:\\Test.PNG");

 obj.Width = obj.Contents_Width();

 obj.Height = obj.Contents_Height();

}

}

The test is updated with

wpdllInt1.Memo.EnumParagraphs(false,1);

wpdllInt1.Memo.ReformatAll(true,true);

Please note that you could clone the images if you have a global integer variable to hold the ID of the first image data object:

// Now update the image placeholder by loading a PNG file

if(obj!=null)

{

 if (objid==0)

 {

  obj.LoadFromFile("c:\\Test.PNG");

  objid = obj.GetContentsID();

 }

 else obj.SetContentsID(objid);

 obj.Width = obj.Contents_Width();

 obj.Height = obj.Contents_Height();

}

 


[idh_iwpparinterface_insertnewobject.htm]    Copyright © 2007 by WPCubed GmbH