Can someone tell me why the following code causes the onBarsReceived event to fire off 3 times when you first start?
If you stop and restart the program or click on the form a second time the onBarsReceived event only fires once which is what it should do all the time.
To run the code you'll have to hook up the onCreate and OnClick events for the form and put in your username.
Thanks for any help, Alan
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,IESignal_TLB, StdCtrls;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormClick(Sender: TObject);
private
esignal: THooks;
iHandle: integer;
{ Private declarations }
public
{ Public declarations }
procedure gotBars(ASender: TObject; lHandle: Integer);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormClick(Sender: TObject);
begin
iHandle := esignal.RequestHistory['MSFT', 'D', btDays, 20, -1, -1];
if esignal.IsHistoryReady[iHandle] = 1 then begin
showmessage('history is ready');
gotBars(self, iHandle);
end;
end;
procedure TForm1.gotBars(ASender: TObject; lHandle: Integer);
var i : integer;
bar: bardata;
iNumBars: integer;
begin
iNumBars := esignal.getNumBars[iHandle];
showMessage('handle = ' + intToStr(lHandle) + ' num bars = ' + intToStr(iNumBars));
bar := esignal.GetBar[iHandle, -10];
showmessage('dt = ' + dateTimeToStr(bar.dtTime) + ' Open = ' + floatToStr(bar.dOpen));
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
esignal.ReleaseHistory(iHandle);
esignal := nil;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
eSignal := THooks.Create(self);
esignal.OnBarsReceived := gotBars;
eSignal.SetApplication('yourUserName');
end;
end.
If you stop and restart the program or click on the form a second time the onBarsReceived event only fires once which is what it should do all the time.
To run the code you'll have to hook up the onCreate and OnClick events for the form and put in your username.
Thanks for any help, Alan
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,IESignal_TLB, StdCtrls;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormClick(Sender: TObject);
private
esignal: THooks;
iHandle: integer;
{ Private declarations }
public
{ Public declarations }
procedure gotBars(ASender: TObject; lHandle: Integer);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormClick(Sender: TObject);
begin
iHandle := esignal.RequestHistory['MSFT', 'D', btDays, 20, -1, -1];
if esignal.IsHistoryReady[iHandle] = 1 then begin
showmessage('history is ready');
gotBars(self, iHandle);
end;
end;
procedure TForm1.gotBars(ASender: TObject; lHandle: Integer);
var i : integer;
bar: bardata;
iNumBars: integer;
begin
iNumBars := esignal.getNumBars[iHandle];
showMessage('handle = ' + intToStr(lHandle) + ' num bars = ' + intToStr(iNumBars));
bar := esignal.GetBar[iHandle, -10];
showmessage('dt = ' + dateTimeToStr(bar.dtTime) + ' Open = ' + floatToStr(bar.dOpen));
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
esignal.ReleaseHistory(iHandle);
esignal := nil;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
eSignal := THooks.Create(self);
esignal.OnBarsReceived := gotBars;
eSignal.SetApplication('yourUserName');
end;
end.