unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ActiveX, ComObj;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}


function AcPoint(x, y, z: double) : OleVariant;
begin
  Result := VarArrayCreate([0, 2], VT_R8);
  Result[0] := x; Result[1] := y; Result[2] := z;
end;

procedure TForm1.Button1Click(Sender: TObject);
const
  appid = 'MYAPPID';
var
  Acad, Objects, vaPoint, vaType, vaData: OleVariant;
  i : integer;
begin

  Acad := GetActiveOleObject('AutoCAD.Application');

  // Get a selection set
  Objects := Acad.ActiveDocument.SelectionSets.Add('');
  Objects.SelectOnScreen;

  // Register application
  Acad.ActiveDocument.RegisteredApplications.Add(appid);

  // Create group code and data arrays
  vaType := VarArrayCreate([0, 4], varSmallInt); 
  vaData := VarArrayCreate([0, 4], varVariant);

  // Create 3D point variant array
  vaPoint := AcPoint(4.0, 6.0, 0.0);

  // Load arrays
  vaType[0] := 1001;      // Application Name must be first
  vaData[0] := appid;

  vaType[1] := 1070;      // An integer
  vaData[1] := 99;

  vaType[2] := 1040;      // A real
  vaData[2] := 2.5;

  vaType[3] := 1000;      // A string
  vaData[3] := 'Hello';

  vaType[4] := 1010;      // A 3D world point
  vaData[4] := vaPoint;

  // Iterate through selection set and
  // attach XData to each object

  For i := 0 to Objects.Count - 1 do
    Objects.Item(i).SetXData(vaType, vaData);

  Objects.Delete;

end;

end.