ImageEn, unit ievect

TImageEnVect.AddNewObject

TImageEnVect.AddNewObject


Declaration

function AddNewObject(bDefaultProps: Boolean = False) : Integer; overload;
function AddNewObject(Kind: TIEVObjectKind; Rect: TRect; Color: TColor; bDefaultProps: Boolean = False): Integer; overload;


Description

Inserts a new object and returns a handle to the object.

if bDefaultProps is true then all properties (position, size, color, etc) are reset to basic values. When false, the properties are the same as the last added object.

The second overload allows you to specify object Kind, rectangle and pen color.


Example

The following three blocks of code produce the same result:

1)
h := ImageEnVect.AddNewObject;
ImageEnVect.ObjKind[h] := iekBOX;
ImageEnVect.SetObjRect(h, Rect(10, 10, 100, 100));
ImageEnVect.ObjPenColor[h] := clRed;


2)
ImageEnVect.ObjKind[IEV_NEXT_INSERTED_OBJECT] := iekBOX;
ImageEnVect.SetObjRect(IEV_NEXT_INSERTED_OBJECT, Rect(10, 10, 100, 100));
ImageEnVect.ObjPenColor[IEV_NEXT_INSERTED_OBJECT] := clRed;
ImageEnVect.AddNewObject;


3)
ImageEnVect.AddNewObject(iekBOX, Rect(10, 10, 100, 100), clRed);



Example

// Paint a red line from 10, 10 inside a rectangle of 100, 100
with ImageEnVect1 do
begin
  hobj := AddNewObject; // hobj is an integer
  ObjKind[ hobj ] := iekLINE;
  ObjLeft[ hobj ] := 10;
  ObjTop[ hobj ] := 10;
  ObjWidth[ hobj ] := 100;
  ObjHeight[ hobj ] := 100;
  ObjPenColor[ hobj ] := clRed;
end;

// Paint a red line from 10, 10 inside a rectangle of 100, 100
// The IEV_NEXT_INSERTED_OBJECT (-1) index is the next image to create
with ImageEnVect1 do
begin
  ObjKind[ IEV_NEXT_INSERTED_OBJECT ] := iekLINE;
  ObjLeft[ IEV_NEXT_INSERTED_OBJECT ] := 10;
  ObjTop[ IEV_NEXT_INSERTED_OBJECT ] := 10;
  ObjWidth[ IEV_NEXT_INSERTED_OBJECT ] := 100;
  ObjHeight[ IEV_NEXT_INSERTED_OBJECT ] := 100;
  ObjPenColor[ IEV_NEXT_INSERTED_OBJECT ] := clRed;
  AddNewObject;
end;

// Paint a red line from 10, 10 inside a rectangle of 100, 100
// The IEV_PREVIOUS_INSERTED_OBJECT (-2) index is the last image created
with ImageEnVect1 do
begin
  AddNewObject; // first create the object, then set its properties
  ObjKind[IEV_PREVIOUS_INSERTED_OBJECT] := iekLINE;
  ObjLeft[IEV_PREVIOUS_INSERTED_OBJECT] := 10;
  ObjTop[IEV_PREVIOUS_INSERTED_OBJECT] := 10;
  ObjWidth[IEV_PREVIOUS_INSERTED_OBJECT] := 100;
  ObjHeight[IEV_PREVIOUS_INSERTED_OBJECT] := 100;
  ObjPenColor[IEV_PREVIOUS_INSERTED_OBJECT] := clRed;
end;

// Load an image from file and add as an object
aBitmap := TIEBitmap.Create;
try
  aBitmap.Read( 'd:\002.png' );
  hObj := ImageEnVect1.AddNewObject();
  ImageEnVect1.ObjKind[ hObj ] := iekBITMAP;
  ImageEnVect1.ObjBitmap[ hObj ] := aBitmap;
  ImageEnVect1.SetObjRect( hobj, Rect( 100, 100, 200, 200 ), True );
finally
  aBitmap.Free;
end;