Welcome, Guest
Guest Settings
Help

Thread: RTD Server


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 3 - Last Post: Jan 11, 2017 4:11 AM Last Post By: andrajoseph jos... Threads: [ Previous | Next ]
Vaughan Lund

Posts: 1
Registered: 12/13/08
RTD Server  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 17, 2014 5:04 AM
Hi,

I am attempting to develop an RTD Server in Delphi for communication with Excel with no success. This same development in .NET showed results within a couple of minutes.

I did the following in Delphi to attempt to get it going:

a. Created a type library that defines the IRtdServer and IRTDUpdateEvent interfaces. I have confirmed that the type library is 100% against Excel's type library
b. Defined a class that inherits from TAutoObject and defines the IRtdServer methods
c. Implemented the IRTDServer methods including the ServerStart method that returns 1 to indicate to Excel that the server has successfully started
d. Defined the object factory in the initialization section TAutoObjectFactory.Create(ComServer, TRTDServer, CLASS_RTDServer, ciSingleInstance)
e. Registered the dll

Excel successfully loads the dll and calls the ServerStart method. Immediately after calling ServerStart, Excel calls ServerTerminate which according to Microsoft documentation indicates that the ServerStart did not return 1.

Any experience in creating an RTD Server in Delphi?

Google only returns links to Add-In Express components.

nivin pauly

Posts: 1
Registered: 2/5/16
Re: RTD Server  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 5, 2016 12:05 AM   in response to: Vaughan Lund in response to: Vaughan Lund
As an alternative to the approach described below you should consider using Excel-DNA. Excel-DNA allows you to build a registration-free RTD server. COM registration requires administrative privileges which may lead to installation headaches. That being said, the code below works fine.)

To create a real-time Excel automation add-in in C# using RtdServer:

1) Create a C# class library project in Visual Studio and enter the following:

using System;
using System.Threading;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Microsoft.Office.Interop.Excel;

namespace StackOverflow
{
public class Countdown
{
public int CurrentValue { get; set; }
}

[Guid("EBD9B4A9-3E17-45F0-A1C9-E134043923D3")]
[ProgId("StackOverflow.RtdServer.ProgId")]
public class RtdServer : IRtdServer
{
private readonly Dictionary<int, Countdown> _topics = new Dictionary<int, Countdown>();
private Timer _timer;

public int ServerStart(IRTDUpdateEvent rtdUpdateEvent)
{
_timer = new Timer(delegate { rtdUpdateEvent.UpdateNotify(); }, null, TimeSpan.Zero, TimeSpan.FromSeconds(5));
return 1;
}

public object ConnectData(int topicId, ref Array strings, ref bool getNewValues)
{
var start = Convert.ToInt32(strings.GetValue(0).ToString());
getNewValues = true;

_topics[topicId] = new Countdown { CurrentValue = start };

return start;
}

public Array RefreshData(ref int topicCount)
{
var data = new object[2, _topics.Count];
var index = 0;

foreach (var entry in _topics)
{
--entry.Value.CurrentValue;
data[0, index] = entry.Key;
data[1, index] = entry.Value.CurrentValue;
++index;
}

topicCount = _topics.Count;

return data;
}

public void DisconnectData(int topicId)
{
_topics.Remove(topicId);
}

public int Heartbeat() { return 1; }

public void ServerTerminate() { _timer.Dispose(); }

[ComRegisterFunctionAttribute]
public static void RegisterFunction(Type t)
{
Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(@"CLSID{" + t.GUID.ToString().ToUpper() + @"}\Programmable");
var key = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(@"CLSID{" + t.GUID.ToString().ToUpper() + @"}\InprocServer32", true);
if (key != null)
key.SetValue("", System.Environment.SystemDirectory + @"\mscoree.dll", Microsoft.Win32.RegistryValueKind.String);
}

[ComUnregisterFunctionAttribute]
public static void UnregisterFunction(Type t)
{
Microsoft.Win32.Registry.ClassesRoot.DeleteSubKey(@"CLSID{" + t.GUID.ToString().ToUpper() + @"}\Programmable");
}
}
}
2) Right click on the project and Add > New Item... > Installer Class. Switch to code view and enter the following:

using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace StackOverflow
{
[RunInstaller(true)]
public partial class RtdServerInstaller : System.Configuration.Install.Installer
{
public RtdServerInstaller()
{
InitializeComponent();
}

[System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
public override void Commit(IDictionary savedState)
{
base.Commit(savedState);

var registrationServices = new RegistrationServices();
if (registrationServices.RegisterAssembly(GetType().Assembly, AssemblyRegistrationFlags.SetCodeBase))
Trace.TraceInformation("Types registered successfully");
else
Trace.TraceError("Unable to register types");
}

[System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
public override void Install(IDictionary stateSaver)
{
base.Install(stateSaver);

var registrationServices = new RegistrationServices();
if (registrationServices.RegisterAssembly(GetType().Assembly, AssemblyRegistrationFlags.SetCodeBase))
Trace.TraceInformation("Types registered successfully");
else
Trace.TraceError("Unable to register types");
}

public override void Uninstall(IDictionary savedState)
{
var registrationServices = new RegistrationServices();
if (registrationServices.UnregisterAssembly(GetType().Assembly))
Trace.TraceInformation("Types unregistered successfully");
else
Trace.TraceError("Unable to unregister types");

base.Uninstall(savedState);
}
}
}
3) Right click on the project Properties and check off the following: Application > Assembly Information... > Make assembly COM-Visible and Build > Register for COM Interop

3.1) Right click on the project Add Reference... > .NET tab > Microsoft.Office.Interop.Excel

4) Build Solution (F6)

5) Run Excel. Go to Excel Options > Add-Ins > Manage Excel Add-Ins > Automation and select "StackOverflow.RtdServer"

6) Enter "=RTD("StackOverflow.RtdServer.ProgId",,200)" into a cell. [Java training in chennai|http://www.traininginsholinganallur.in/java-training-in-chennai.html#] | [Android training in chennai|http://www.traininginsholinganallur.in/android-training-in-chennai.html#]

7) Cross your fingers and hope that it works!
acemary mary

Posts: 12
Registered: 2/23/16
Re: RTD Server  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 23, 2016 1:07 AM   in response to: Vaughan Lund in response to: Vaughan Lund
we are trying to migrate from DDE to RTD for live trading data support in MS Excel. The RTD server should be part of a trading application running on the local machine which is fed with updated data via a listener interface.

However, I need some help in setting up the basic Java COM RTD server infrastructur. I was able to generate the required interfaces IRtdServer and IRTDUpdateEvent.

What I don't really understand is the difference between IDispatchServer and DispatchComServer (whether I have to write the server extending one or the other) and how this server is registered (not necessarily in the registry if Excel does not require it). Excel is trying to connect to the RTD server via
=RTD("MyComAddIn.Progid",,"Price"), [Web Designing Training in Chennai|http://www.besanttechnologies.com/training-courses/web-designing-training]
so I need to register the ProgId of the server as well. Is Excel always trying to start a new Java process when calling the RTD command or is it possible that the RTD server is started as soon as the main application is started and is waiting for incoming requests then?

As you might get from the random order of my questions, I did not really understand how the whole RTD server thing has to be set up. I hope you can provide some insight and probably provide code snippets on how to get me running. I am running Win 7 (64 bit) with MS Office (32 bit). I would really appreciate your help!

Many thanks in advance, [Web Designing Training in Chennai|http://www.traininginsholinganallur.in/web-designing-training-in-chennai.html]

Edited by: acemary mary on Jan 23, 2016 1:08 AM
andrajoseph jos...

Posts: 2
Registered: 2/6/17
Re: RTD Server  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 11, 2017 4:11 AM   in response to: Vaughan Lund in response to: Vaughan Lund
If I create an RTD server, and "Subscribe" to topics from workbook1.
Will the updates continue if I open new workbook2, workbook3 in the same instance of Excel?
What if I have multiple instances of Excel running, will the updates continue in workbook1?

thank you, we are guide to u. http://www.androidtraininginchennai.in/android-training-in-chennai.html | http://www.traininginannanagar.in/android-training-in-chennai.html | http://www.traininginvelachery.in/android-training-in-chennai.html
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02