我尝试从Indy TCP server线程连接到(Uni)DDE服务器。从普通应用程序中,我可以连接,并可以获取/设置任何PLC变量。
但是当我从Indy线程(从Execute(AThread: TIdPeerThread)事件)使用相同的命令时,SetLink命令失败。
procedure ReadDDE(AppPath, Service, Topic, Cmd: string; out Eredmeny : string; out HibaSzint : string);
var
DDE: TDDEClientConv;
pc : PChar;
begin
Eredmeny := '';
HibaSzint := '';
DDE := TDDEClientConv.Create(nil);
try
DDE.ConnectMode := ddeAutomatic;
DDE.ServiceApplication := AppPath;
DDE.FormatChars := False;
HibaSzint := 'SetLink';
if DDE.SetLink(Service, Topic) then begin
HibaSzint := '';
pc := DDE.RequestData(PChar(Cmd));
Eredmeny := StrPas(pc);
StrDispose(pc);
end;
finally
DDE.Free;
end;
end;也许DDE正在使用Windows消息,或者其他东西不是threadsafe,或者在线程级别不能捕获?
感谢您提供的相关信息: dd
发布于 2013-02-25 20:25:24
DDE是建立在windows消息之上的。您需要确保在具有DDE连接的线程上调度消息。
发布于 2015-07-27 08:44:01
我知道为时已晚,但也许有人需要这个指导。我已经在上面做了太多的工作。我也有同样的问题(但是openlink方法,而不是Set Link方法。我使用了连接模式ddeManual而不是自动).At最后我发现了一些东西。Delphi位于VCL单元中,需要像Synchronize(yourProcedure)一样调用ddeMgr。当我编写另一个过程(该过程包括我所有的dde交互)时,在线程Execute方法中,我使用Synchronize调用我的过程。我的代码如下所示。
procedure TAskYTSThread.MakeDDEConv;
begin
with TDDEClientConv.Create(Form1) do
begin
ConnectMode:=ddeManual;
ServiceApplication:='explorer.exe';
SetLink('Folders', 'AppProperties') ;
Form1.Memo1.Lines.Add('Openlink çağrılacak Gönderilecek.');
if OpenLink then
begin
Form1.Memo1.Lines.Add('Link Open Edildi.');
ExecuteMacro('[FindFolder(, C:\)]', False) ;
CloseLink;
end
else
begin
Form1.Memo1.Lines.Add('OLMADIIIIIII');
end;
Free;
end;
end;
procedure TAskYTSThread.Execute;
var
blnRunning : boolean ;
FYtsTopicName, strMacro : string ;
begin
inherited;
FDDE_BUSY.Enter ;
try
blnRunning := IsYTSRunning;
Synchronize(MakeDDEConv); // this is key point
finally
FDDE_BUSY.Leave ;
end;
end;我希望这些信息能帮助其他人:)
https://stackoverflow.com/questions/15066705
复制相似问题