I have a piece of hardware which is handled using an ActiveX component in Delphi. If I drop that component on my form during design time, everything works fine. However, if I create it dynamically at run-time using Creat(Self), further execution of a method causes Access Violation in mfc100.dll. The code is pretty simple:
uses
Windows, Messages, ...
OleCtrls, MG17MotorLib_TLB; // <-- The latter is the hardware driver
type
TForm1 = class(TForm)
motorX: TMG17Motor;
...
end;
...
procedure TForm1.FormCreate(Sender: TObject);
begin
motorX := TMG17Motor.Create(Self);
motorX.HWSerialNum := 94835472;
motorX.StartCtrl; // <--- This causes AV in mfc100.dll
end;
The TMG17Motor class is a descendant of TOleControl and is supplied by a hardware producer.
Do I make a mistake in dynamically creating the ActiveX object, or does it rather look like a bug in TMG17Motor class? Perhaps, there is a way to cheat and create an object of TMG17Motor class in the same way as the application does it, if I avoid using Create(Self) by dropping the control on the form at design time?
P.S. The reason I want to be able to dynamically create a control is that I want to move the code for hardware handling to a worker thread.