25.03.2011, 09:24
|
|
Let Me Show You
|
|
Регистрация: 30.04.2010
Адрес: Северодвинск
Сообщения: 5,426
Версия Delphi: 7, XE5
Репутация: 59586
|
|
еще вариант. пробовал на похожем объекте:
Код:
unit Unit1;
interface
uses
InterfacedObjectDispatch,
S7PROSIMLib_TLB,
ComObj,
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
procedure InvokeEvent(DispID: Integer; const IID: TGUID; LocaleID: Integer;
Flags: Word; var Params; VarResult, ExcepInfo, ArgErr: Pointer);
public
{ Public declarations }
S7ProSim: IS7ProSim;
FEventDispatch: TInterfacedObjectDispatch;
FEventsConnection: Longint;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
punk: IUnknown;
begin
FEventDispatch:=TInterfacedObjectDispatch.Create(InvokeEvent, IS7ProSimEvents);
punk:=CreateComObject(CLASS_S7ProSim);
InterfaceConnect(punk, IS7ProSimEvents, FEventDispatch, FEventsConnection);
S7ProSim:=punk as IS7ProSim;
S7ProSim.Connect;
S7ProSim.SetScanMode(ContinuousScan);
S7ProSim.SetState('RUN');
// завершение работы
// InterfaceDisconnect(S7ProSim, IID_IS7ProSimEvents, FEventsConnection);
// FEventDispatch.Free;
end;
procedure TForm1.InvokeEvent(DispID: Integer; const IID: TGUID;
LocaleID: Integer; Flags: Word; var Params; VarResult, ExcepInfo,
ArgErr: Pointer);
begin
// события
case DispID of
1: begin
// OnScanFinished
end;
2: begin
Memo1.Text:='close';
// OnConnectionError
end;
3: begin
// OnPLCSimStateChanged
end;
4: begin
// OnPauseStateChanged
end;
5: begin
// OnScanModeChanged
end;
end;
end;
end.
InterfacedObjectDispatch.pas:
http://data.cod.ru/94902
__________________
Пишу программы за еду.
__________________
|