Question : How do I handle AutoCAD events by a Delphi program?

I have deveoped a Delphi function library over the AutoCAD.Application and I would add to this library a full support to document and entities events.
I use Delphi 7 and AutoCAD 2010. How can I use the BeginSave, EndSave, etc... events invoked by AutoCAD VBA Documentation?

Answer : How do I handle AutoCAD events by a Delphi program?

>> Witch is the way to intercept events fired by AutoCAD?

It depends on how AutoCAD event model. I asked you to attach AutoCAD_TLB file to watch how exactly  ACAD defines its events.

For example if your AutoCAD_TLB looks like this:

TAcadDocumentBeginSave = procedure(ASender: TObject; const FileName: WideString) of object;
...
TAcadDocument = class(TOleServer)
   ....
    property OnBeginSave: TAcadDocumentBeginSave read FOnBeginSave write FOnBeginSave;
    property OnEndSave: TAcadDocumentEndSave read FOnEndSave write FOnEndSave;
    property OnBeginCommand: TAcadDocumentBeginCommand read FOnBeginCommand write FOnBeginCommand;
    property OnEndCommand: TAcadDocumentEndCommand read FOnEndCommand write FOnEndCommand;
   ...

When you can do something like this:

type
  TForm1 = class(TForm)
  ...
  private
     procedure HandlerForAcadDocBeginSave(ASender: TObject; const FileName: WideString);
  ...

procedure TForm1.Button1Click(ASender:TObject);
var
  Acad: IAcadApplication;
  AcadDocument: TAcadDocument;
begin
  Acad := CreateOleObject('AutoCAD.Application')as IAcadApplication;
  Acad.Visible := true;
  AcadDocument:=TAcadDocument.Create(Application);
  AcadDocument.OnBeginSave:= HandlerForAcadDocBeginSave;
  AcadDocument.ConnectTo(Acad.ActiveDocument);  
 ...
Random Solutions  
 
programming4us programming4us