Я пытаюсь построить RTD-сервер для Excel в Delphi и не могу заставить эту часть кода работать:
function TRtdServer.RefreshData(var TopicCount: Integer): PSafeArray;
//Called when Excel is requesting a refresh on topics. RefreshData will be called
//after an UpdateNotify has been issued by the server. This event should:
//- supply a value for TopicCount (number of topics to update)
//- The data returned to Excel is an Object containing a two-dimensional array.
// The first dimension represents the list of topic IDs.
// The second dimension represents the values associated with the topic IDs.
var
Data : OleVariant;
begin
//Create an array to return the topics and their values
//note:The Bounds parameter must contain an even number of values, where each pair of values specifies the upper and lower bounds of one dimension of the array.
Data:=VarArrayCreate([0, 1, 0, 0], VT_VARIANT);
Data[0,0]:=MyTopicId;
Data[1,0]:=GetTime();
if Main.Form1.CheckBoxExtraInfo.Checked then Main.Form1.ListBoxInfo.Items.Add('Excel called RefreshData. Returning TopicId: '+IntToStr(Data[0,0])+' and Value: '+Data[1,0]);
TopicCount:=1;
// RefreshTimer.Enabled:=true;
//Result:=PSafeArray(VarArrayAsPSafeArray(Data));
Result:=PSafeArray(TVarData(Data).VArray);
end;
Я не уверен насчет этой части:
Result:=PSafeArray(TVarData(Data).VArray);
Но это может быть любая часть кода.
Excel просто не показывает никакого результата в ячейке, содержащей вызов функции rtd (). Мне удалось получить результат в ячейку в первый раз, когда Excel вызывает мою функцию «ConnectData», которая просто возвращает строку вместо PSafeArray (хотя самый первый вызов этой функции не дает результата (N / A). Только после изменения темы в вызове RTD () отображается результат (только один раз))
Я основал код на примере в C # из https://blog.learningtree.com/excel-creating-rtd-server-c/
Кто-нибудь может указать мне правильное направление?