0
votes

I have somethin like that:

function DDE_Read(Service, Topic, Items: string): string;
var
  DDE: TDDEClientConv;
begin
  try
    DDE := TDDEClientConv.Create(nil);
    DDE.SetLink(Service, Topic);
    DDE.OpenLink;
    Result:=DDE.RequestData(Items);
  finally
    DDE.Free;
  end;
end;

I connect to DDE server and get data. Sometimes I can get data and sometimes I receive empty string. Can you tell me is this code ok? How often I can connect to dde server to get data?

Have you maybe some *dll or your own code?

//EDIT Im beginer and I dont now always what you mean :) I am very grateful that you're helping me. So my code should be smth like that?

function DDE_Read(Service, Topic, Items: string): string;
var
DDE: TDDEClientConv;
temp:PAnsiCHar;
begin
DDE := TDDEClientConv.Create(nil);
DDE.SetLink(Service, Topic);
DDE.OpenLink;
try
temp:=DDE.RequestData(Items);
Result:=temp;
SysUtils.StrDispose(temp);
finally
DDE.Free;
end;
end;
1
You forgot StrDispose to prevent memory leaks -> TDdeClientConv.RequestData - Sir Rufo
@DavidHeffernan: isn't DDE from the 20th century? I would advise to check if the application has a COM object or OLE automation or ActiveX interface. - Stijn Sanders
@user - Add a call to DdeGetLastError(ddeMgr.DdeInstId) for when the response is empty. Let's see if it returns a useful DMLERR. Use 'ddeml'. - Sertac Akyuz
When response is empty DdeGetLastError(ddeMgr.DdeInstId) returns '0'. - Mlody87
0 is DMLERR_NO_ERROR. So it's not that the server is busy or anything... - Sertac Akyuz

1 Answers

1
votes

IIRC, there are sometimes problems using DDE when a lot of connections are opened and closed in a short time interval. I'm unsure if this is still a problem with modern Windows systems. On the other hand, the pure need for you to use DDE suggests that you are not working in a modern environment.

You can try to keep the TDDEClientConv instance for a specific Service or a combination of Service and Topic alive for a longer time. This might at least reduce your problem.