Building RTD servers for Excel in Delphi

Add-in Express™
for Microsoft® Office and Delphi® VCL

Add-in Express Home > Add-in Express for Office and Delphi VCL > Online Guide > Developing Excel RTD servers

Building Excel Real-Time Data servers

Using Add-in Express for Office and Delphi VCL you can create Real-Time Data servers for Microsoft Excel 2002 (XP), 2003, 2007, 2010, 2013 and Excel 2016. You can download this Real-Time Data server project as well as many other examples on the How-To pages: Delphi for Outlook and Delphi for Excel.

Step 1. Creating a new Excel RTD Server project

Make sure that you have administrative permissions before running Delphi. Also, if you have Windows Vista, Windows 7, Windows 8, or Windows 10, run Delphi via Run as Administrator.

In the Delphi IDE, close all opened projects, select the File | New | Others item of the main menu, and run the Add-in Express Excel RTD Server wizard by clicking on the Add-in Express RTD server template in the "New Item" dialog.

Creating a new RTD server project

In the RTD Server Project wizard window, enter the name of the project and the destination folder for it, and click Next.

Entering the project name and destination folder

The wizard generates a new RTD project and opens it in the Delphi IDE. The Real-Time Data server project includes the following items:

  • The project source files (ProjectName.*)
  • The type library files: binary (ProjectName.tlb) and Object Pascal unit (ProjectName_TLB.pas)
  • The RTD server module (ProjectName_IMPL.pas and ProjectName_IMPL.dfm) discussed in the next step.

RTD server project in Delphi

Step 2. RTD Server module

The RTD server module (MyRtdServer1_IMPL.pas and MyRtdServer1_IMPL.dfm) is the core part of the RTD Server project. The module is a container for TadxRTDTopic components.

The code of MyRtdServer1_IMPL.pas is as follows:


unit MyRtdServer1_IMPL;

interface

uses
  SysUtils, Classes, ComServ, MyRtdServer1_TLB, adxRTDServ;
  
type
  TcoMyRtdServer1 = class(TadxRTDServer, IcoMyRtdServer1)
  end;
  
  TRTDServerModule = class(TadxXLRTDServerModule)
  private
  protected
  public
  end;
  
implementation

{$R *.dfm}

initialization
  TadxRTDFactory.Create(ComServer, TcoMyRtdServer1, 
	CLASS_coMyRtdServer1, TRTDServerModule);
  
end.

Step 3. RTD Server designer

The module designer allows setting RTD Server properties and adding components to the module. You set the properties of your RTD server module in the Object Inspector window.

Setting the properties of your Excel RTD server

The only Add-in Express component available for the module is the TadxRTDTopic component.

Step 4. Adding and handling a new topic

To add a new topic to your Excel RTD Server, in the Tool Palette, select the Add-in Express tab and drag-n-drop the TadxRTDTopic component onto the RTD Server Module.

Setting the properties of the RTD topic component

Select the newly added component and, in the Object Inspector, specify the topic using the String## properties. Write your code to handle the RefreshData event of the RTD Topic component:

RTD topic component

Write your code to handle the RefreshData event of the RTD Topic component:


function TRTDServerModule.adxRTDTopic1RefreshData(Sender: TObject): OleVariant;
begin
  Result := RandomRange(-100, 100);
end;

Step 5. Running the RTD server in Excel

Choose the Register ActiveX Server item in the Run menu, restart Excel, and enter the RTD function to a cell.

The newly created RTD server in Excel 2010

Step 6. Debugging the RTD server

To debug your Real-Time Data server, just indicate Excel as the Start Program in the Project Options window.

Debugging the RTD server

To debug your add-in in Excel 64-bit, you have to register the add-in DLL using regsvr32; run it from an elevated 64-bit Command Prompt. In addition, you must explicitly specify to run Excel 2010, 2013 and 2016 64-bit in the dialog window shown above.

Step 7. Deploying your Real-Time data server

Make sure your setup project registers the RTD Server DLL (or EXE). Say, in Inno Setup projects you use the 'regserver' command.

Building Outlook plugins in Delphi <<

>> Writing smart tags