lock Method

Summary

Locks this AnnObject with the specified password.

Syntax
TypeScript
JavaScript
AnnObject.prototype.lock = function( 
   password 
) 
lock( 
   password: string 
): void; 

Parameters

password

String containing the password used to lock the annotation object.

Remarks

Only unlocked objects can be locked. If an object is already locked, it will stay locked with its original password. You must pass the same password to Unlock to unlock this AnnObject.

If this method succeeds, password will be stored inside the object and can be retrieved with the Password property.

An object must be unlocked in order to change that object in automated mode.

For more information, refer to Implementing Annotation Security.

Example
TypeScript
JavaScript
example: function SiteLibrary_DefaultPage$example() { 
   var inch = 720.0; 
 
   // Get the container 
   var container = this._automation.get_container(); 
 
   // Add the lock picture to the container resources 
 
   // Create a new instance of AnnResources if the automation manager does not already have one 
   var resources = this._automation.get_manager().get_resources(); 
   if (resources == null) { 
      resources = new lt.Annotations.Engine.AnnResources(); 
      this._automation.get_manager().set_resources(resources); 
   } 
 
   // Get the images collection 
   var imagesResources = resources.get_images(); 
 
   // Add our picture to it 
   imagesResources.add(new lt.Annotations.Engine.AnnPicture("Resources/Lock.png")); 
   var pictureIndex = imagesResources.length - 1; 
 
   // Add a blue on yellow rectangle from 3in 3in to 4in 4in 
   var rectObj = new lt.Annotations.Engine.AnnRectangleObject(); 
   rectObj.set_rect(lt.LeadRectD.create(3 * inch, 3 * inch, 1 * inch, 1 * inch)); 
   rectObj.set_stroke(lt.Annotations.Engine.AnnStroke.create(lt.Annotations.Engine.AnnSolidColorBrush.create("blue"), lt.LeadLengthD.create(1))); 
   rectObj.set_fill(lt.Annotations.Engine.AnnSolidColorBrush.create("yellow")); 
 
   // Set its lock picture 
   rectObj.set_lockPicture(pictureIndex); 
 
   // Add it to the container 
   container.get_children().add(rectObj); 
 
   // Show the object lock state (default) 
   alert("Default lock state"); 
   this.showLockedState(rectObj); 
 
   // Lock it with a password 
   alert("Locking now with a password"); 
   rectObj.lock("secret"); 
 
   // Show the object lock state, it should say locked and the object should be painted with the lock picture 
   this.showLockedState(rectObj); 
 
   // Now try to unlock it with a wrong password 
   alert("Unlocking with a wrong password"); 
   rectObj.unlock("wrong password"); 
 
   // Check again, it should still be locked 
   this.showLockedState(rectObj); 
 
   // Finally unlock it with the correct password 
   alert("Unlocking with a correct password"); 
   rectObj.unlock("secret"); 
 
   // Check again, it should still be unlocked 
   this.showLockedState(rectObj); 
}, 
 
showLockedState: function SiteLibrary_DefaultPage$showLockedState(annObj) { 
   this._automation.invalidate(lt.LeadRectD.get_empty()); 
 
   // Show the object lock state (default) 
   alert("Locked: " + annObj.get_isLocked()); 
 
}, 
private AnnObject_LockExample(): void { 
   const inch: number = 720.0; 
 
   // Get the container 
   const container: lt.Annotations.Engine.AnnContainer = this._automation.container; 
 
   // Add the lock picture to the container resources 
 
   // Create a new instance of AnnResources if the automation manager does not already have one 
   let resources: lt.Annotations.Engine.AnnResources = this._automation.manager.resources; 
   if (resources == null) { 
      resources = new lt.Annotations.Engine.AnnResources(); 
      this._automation.manager.resources = resources; 
   } 
 
   // Get the images collection 
   const imagesResources: lt.Annotations.Engine.AnnPicture[] = resources.images; 
 
   // Add our picture to it 
   imagesResources.push(new lt.Annotations.Engine.AnnPicture("Resources/Lock.png")); 
   const pictureIndex = imagesResources.length - 1; 
 
   // Add a blue on yellow rectangle from 3in 3in to 4in 4in 
   const rectObj: lt.Annotations.Engine.AnnRectangleObject = new lt.Annotations.Engine.AnnRectangleObject(); 
   rectObj.rect = lt.LeadRectD.create(3 * inch, 3 * inch, 1 * inch, 1 * inch); 
   rectObj.stroke = lt.Annotations.Engine.AnnStroke.create(lt.Annotations.Engine.AnnSolidColorBrush.create("blue"), lt.LeadLengthD.create(1)); 
   rectObj.fill = lt.Annotations.Engine.AnnSolidColorBrush.create("yellow"); 
 
   // Set its lock picture 
   rectObj.lockPicture = pictureIndex; 
 
   // Add it to the container 
   container.children.add(rectObj); 
 
   // Show the object lock state (default) 
   alert("Default lock state"); 
   this.showLockedState(rectObj); 
 
   // Lock it with a password 
   alert("Locking now with a password"); 
   rectObj.lock("secret"); 
 
   // Show the object lock state, it should say locked and the object should be painted with the lock picture 
   this.showLockedState(rectObj); 
 
   // Now try to unlock it with a wrong password 
   alert("Unlocking with a wrong password"); 
   rectObj.unlock("wrong password"); 
 
   // Check again, it should still be locked 
   this.showLockedState(rectObj); 
 
   // Finally unlock it with the correct password 
   alert("Unlocking with a correct password"); 
   rectObj.unlock("secret"); 
 
   // Check again, it should still be unlocked 
   this.showLockedState(rectObj); 
} 
 
private showLockedState(annObj): void { 
   this._automation.invalidate(lt.LeadRectD.empty); 
 
   // Show the object lock state (default) 
   alert("Locked: " + annObj.isLocked); 
} 

Requirements

Target Platforms

Help Version 20.0.2019.3.11
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2019 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Annotations.Engine Assembly