0

I'm writing a simple program in Delphi7 that uses a unit written by someone else (IB TWS API 9.71), and I can't handle passing values from that unit to my program. In the opposite direction, everything works without problems. Here is a piece of Unity code:

unit TWSLib_TLB;
const
  LIBID_TWSLib: TGUID = '{0A77CCF5-052C-11D6-B0EC-00B0D074179C}';
  DIID__DTws: TGUID = '{0A77CCF6-052C-11D6-B0EC-00B0D074179C}';
  DIID__DTwsEvents: TGUID = '{0A77CCF7-052C-11D6-B0EC-00B0D074179C}';
  CLASS_Tws: TGUID = '{0A77CCF8-052C-11D6-B0EC-00B0D074179C}';
type
  _DTwsEvents = dispinterface;

// DispIntf:  _DTwsEvents
// Flags:     (4096) Dispatchable
// GUID:      {0A77CCF7-052C-11D6-B0EC-00B0D074179C}
// *********************************************************************//
  _DTwsEvents = dispinterface
procedure currentTime(time: Integer); dispid 32;


// OLE Control Proxy class declaration
// Control Name     : TTws
// Help String      : Tws Control
// Default Interface: _DTws
// Def. Intf. DISP? : Yes
// Event   Interface: _DTwsEvents
// TypeFlags        : (34) CanCreate Control

TTwscurrentTime = procedure(ASender: TObject; time: Integer) of object;

Here is a piece of code in my program:

procedure TForm1.Connect_TWSClick(Sender: TObject);
var 
  Disp:IDispatch;
  Event:_DTwsEvents;
begin
    Tws1.connect('127.0.0.1', 7496, 0, 0);
    Disp:=CreateComObject(CLASS_Tws) as IDispatch;
    Event:=_DTwsEvents(Disp);

    time:=1;
    Tws1.reqCurrentTime;
    Event.currentTime(time);  //in "time" should be the current time, but it is not

This is written in manual of unit: "ActiveX events receive information from the system and make it available to an application. This section defines the ActiveX events you can receive via the DTwsEvents interface." And specifically for the currentTime procedure: "This method receives the current system time on the server side." Can someone please point me in the direction of where I am going wrong? Thank you.

Progman
  • 16,827
  • 6
  • 33
  • 48
keymaker
  • 9
  • 2
  • Was it written foe Delphi 7 ? – Rohit Gupta Sep 12 '22 at 13:38
  • Yes, my program is written in Delphi 7. But I don't know in which language the unit TWSLib_TLB was written. – keymaker Sep 12 '22 at 13:59
  • If you want your `time` parameter to be modified and returned from `currentTime` method, you should pass it using `var` or `out` reserved words I guess. See https://stackoverflow.com/questions/14507310/whats-the-difference-between-var-and-out-parameters – paradise Sep 12 '22 at 14:47

1 Answers1

0

Problem solved, in the end it was very simple. I have connect the events via OncurrentTime

procedure TForm1.Tws1currentTime(ASender: TObject; time: Integer);
var actual_time:integer;
begin
    actual_time:=time;  //in actual_time is now the value I need
keymaker
  • 9
  • 2