As far as I know, there is no way to combine two objects into 1, but you can keep both objects selected so they move as a single object.
You can do this by making the 'Spot' selectable, moveable and visible and make the text moveable and visible.... but NOT selectable.
// This adds a ellipse 'Spot' and a text object but only the 'Spot'
// is selectable. Therefor the two objects act as one with respect to movement.
procedure TFormMain.AddSpot1Click(Sender: TObject);
var
i: integer;
SpothObj: integer;
TexthObj: integer;
ix: integer;
iy: integer;
iRight: integer;
iBottom: integer;
iListItem: TListItem;
begin
if AddSpot1.Down then
with ImageEnVect1 do
begin
// Add the spot
SpothObj := AddNewObject;
ObjStyle[SpothObj] := [];
// make spot object Selectable, Moveable and Visible
ObjStyle[SpothObj] := [ievsSelectable, ievsMoveable, ievsVisible];
ObjKind[SpothObj] := iekEllipse;
ObjName[SpothObj] := 'Spot';
ObjWidth[SpothObj] := 10;
objHeight[SpothObj] := 10;
ObjLeft[SpothObj] := ImageEnVect1.ClientWidth div 2;
ObjTop[SpothObj] := ImageEnVect1.ClientHeight div 2;
objBrushColor[SpothObj] := clMaroon;
objBrushStyle[SpothObj] := bsSolid;
MouseInteractVt := [miPutEllipse];
// add the text
TexthObj := AddNewObject;
ObjStyle[TexthObj] := [];
// make text object moveable and visible bit not selectable
// Text object moves along with Spot object
ObjStyle[TexthObj] := [ ievsMoveable, ievsVisible];
ObjKind[TexthObj] := iekText;
ObjName[TexthObj] := 'Text';
ix := ObjLeft[SpothObj] + ObjWidth[SpothObj] + 10;
iy := ObjTop[SpothObj] - 5;
ObjPenWidth[TexthObj] := 0;
ObjText[TexthObj] := 'Spot';
ObjLeft[TexthObj] := ix;
ObjTop[TexthObj] := iy;
ObjHeight[TexthObj] := 16;
ObjPenColor[TexthObj] := clBlack;
ObjPenStyle[TexthObj] := psClear;
//ObjTextAutoSize[Texthobj] := True;
SelAllObjects;
for i := 0 to ObjectsCount - 1 do
begin
iListItem := ListViewObjects1.Items.Add;
iListItem.Caption := IntToStr(ListViewObjects1.Items.Count);
iListItem.SubItems.Add(string(ObjName[i]));
iListItem.SubItems.Add(IntToStr(ObjWidth[i]) + ' x ' +
IntToStr(ImageEnVect1.ObjHeight[i]));
iListItem.Selected := True;
end;
Update;
AddSpot1.Down := False;
SelectObject1.Down := True;
ImageEnVect1.MouseInteractVt := [miObjectSelect];
end
else if SelectObject1.Down then
ImageEnVect1.MouseInteractVt := [miObjectSelect];
end;
// Move the 'Text' along with the 'Spot'
procedure TFormMain.ImageEnVect1ObjectMoveResize(Sender: TObject; hobj, Grip: Integer; var OffsetX,
OffsetY: Integer);
var
iTextObj: integer;
begin
if hobj = 0 then
begin
iTextObj := hobj + 1;
ImageEnVect1.ObjLeft[iTextObj] := ImageEnVect1.ObjLeft[hobj] + ImageEnVect1.ObjWidth[hobj] + 10;
ImageEnVect1.ObjTop[iTextObj] := ImageEnVect1.ObjTop[hobj];
end;
end;
William Miller
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html