Excellent, thx
"Tony Tanzillo" wrote in message
news:B5B2E11D0AA6F623A2E7A0891EFD73C7@in.WebX.maYIadrTaRb...
> "Joe Parker" wrote in message
>
> See below for some comments on using modeless
> Delphi forms in AutoCAD.
>
> > 1. I was hoping not to ShowModal as I want the
> > user to be able to interact with Acad. I only
> > want the Automation Object destroyed if the Ok
> > button is selected
>
> You cannot destroy your ActiveX object, as long as
> there is one or more references to it in the VBA
> client. This is what's causing the AV. You have
> to keep in mind that a COM object's lifetime is
> controlled by its clients. As long as one or more
> clients holds a reference to your COM object, you
> cannot destroy it.
>
> To get around this, you can do the following:
>
> In your form, declare a public property of type
> IUnknown, and a private variable of the same
> type:
>
> type
> TForm1 = class(TForm)
> private
> FCOMObject: IUnknown;
> //.....
> public
> Property ComObject: IUnknown read FCOMObject write FCOMObject;
> //...
> end;
>
> In your COM object's Initialize() method:
>
> procedure TTest.Initialize;
> begin
> Inherited Initialize;
> FForm1 := TForm1.Create(nil);
> // Let the form keep a reference to this COM object
> FForm1.ComObject := Self As IUnknown;
> end;
>
> Then, add an OnClose handler to your form, and
> in it, set the CloseAction to caHide, and release
> the COM object:
>
> TForm1.OnClose((Sender: TObject; var Action: TCloseAction);
> begin
> CloseAction := caHide;
> FComObject := Nil;
> end;
>
> > I suppose what I want to do is know is whether the form is operating
from
> > inside a dll or is it the main form of a standalone application
>
> Just call IsLibrary() and if it returns True, then
> you are running in a .DLL.
>
> Some comments on using modeless Delphi forms in AutoCAD:
>
> Without some extensive programming, using a Delphi Form
> modelessly in AutoCAD will not work entirely as expected.
> The reason for this is because much of the functionality
> that Delphi forms and controls implement are dependent
> on the Delphi Application object (TApplication) having a
> message pump, which is not the case when your form runs
> in a non-Delphi host.
>
> For example, when your form is shown modelessly in the
> ActiveX dll, you will note that you can't use the TAB
> key to advance focus from one control to the next. A
> number of other things will not work correctly also.
>
> I have a solution for this, but I will need to package
> it up in a form that you can use. I developed a special
> Delphi form class called TAcadForm, which is derived
> from Delphi's TForm, and is "AutoCAD aware". IOW, it
> will function properly as a modeless form when used in
> AutoCAD's process.
>
> I will need some time to put in a package along with
> any other required units, and once I do, I'll post it
> on my web page.
>
>
>
>