Hi,
I'm starting development of a trading application in equities and Forex
and I'm thinking of using .NET remoting.
The structure would be something like this:
A server for receiving quotes from exchanges and storing them in a
database as well as populating a class designed to store the current
prices.
I would like this server to be on a separate machine from the GUI as
there will be more than one GUI needing the information.
I would like the server to push the information to the clients instead
of them polling the server at a fixed interval so I was thinking of
having an event on the server that sends the data to the clients.
The problem is that I've found no examples of using events through
remoting in Delphi.
Can someone point me to some examples of how to do this?
thanks,
nisbus
|
Ok I've started a sample project to test this, it consists of:
A package containing a class and an interface:
type
[Serializable]
TRemote = class
private
fRandomNumber : integer;
procedure SetRandomNumber(const Value: integer);
published
property RandomNumber : integer read FRandomNumber write
SetRandomNumber;
public
constructor create;
end;
IRemote = interface
function GetNewNumber : integer;
procedure TimerFire(State : TObject);
end;
A unit declaring the interface:
type
TRemoting = class(MarshalByRefObject,IRemote)
private
fRandomNumber : integer;
procedure SetRandomNumber(const Value: integer);
published
property RandomNumber : integer read fRandomNumber write
SetRandomNumber;
public
Time : System.Threading.Timer;
function GetNewNumber : integer;
procedure CreateData;
procedure TimerFire(State : TObject);
constructor Create;
end;
implementation
{ TRemoting }
constructor TRemoting.Create;
begin
inherited;
Time := System.Threading.Timer.Create(TimerFire,nil,0,1000);
end;
procedure TRemoting.CreateData;
begin
Randomize;
RandomNumber := Random(100);
end;
function TRemoting.GetNewNumber: integer;
begin
result := RandomNumber;
end;
procedure TRemoting.SetRandomNumber(const Value: integer);
begin
fRandomNumber := Value;
end;
procedure TRemoting.TimerFire(State: TObject);
begin
CreateData;
end;
and a GUI for retrieving the data:
type
TForm1 = class(TForm)
Label1: TLabel;
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
fChannel : TCPChannel;
fRemote : IRemote;
Remote : TRemote;
State : TObject;
procedure localFire(State:TObject);
end;
var
Form1: TForm1;
implementation
{$R *.nfm}
{ TForm1 }
procedure TForm1.FormShow(Sender: TObject);
begin
fChannel := TCPChannel.Create;
ChannelServices.RegisterChannel(fChannel);
fRemote :=
Activator.GetObject(TypeOf(IRemote),'tcp://localhost:8099/Remoting.TCP')
as IRemote;
Include(fRemote.TimerFire,LocalFire);
end;
procedure TForm1.localFire(State: TObject);
begin
label1.Text := Convert.ToString(fRemote.GetNewNumber);
end;
Now the server runs fine and the timer seems to create a new random
number every second (I added a button to the GUI that called the
GetNewNumber function of the remote object, which worked).
Now when I try to compile the GUI it complains on the
Include(fRemote.TimerFire,LocalFire); with an E2035 Not enough actual
parameters error.
I've used the include command before and then it needed only equivalent
information so what is the problem?
thanks,
nisbus
nisbus wrote:
> Hi,
>
> I'm starting development of a trading application in equities and
> Forex and I'm thinking of using .NET remoting.
>
> The structure would be something like this:
>
> A server for receiving quotes from exchanges and storing them in a
> database as well as populating a class designed to store the current
> prices.
> I would like this server to be on a separate machine from the GUI as
> there will be more than one GUI needing the information.
>
> I would like the server to push the information to the clients instead
> of them polling the server at a fixed interval so I was thinking of
> having an event on the server that sends the data to the clients.
> The problem is that I've found no examples of using events through
> remoting in Delphi.
>
> Can someone point me to some examples of how to do this?
>
> thanks,
> nisbus
|