本文介绍了Delphi:来自Indy TCPServer线程的DDE调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从Indy TCP Server线程连接到(Uni)DDE服务器.在正常的应用程序中,我可以连接,并且可以获取/设置任何PLC变量.

I try to connect to (Uni)DDE server from an Indy TCP Server thread.From normal application I can connect, and can get/set any PLC variables.

但是当我从Indy线程(从Execute(AThread:TIdPeerThread)事件)使用相同的命令时,SetLink命令失败.

But when I use same command from Indy thread (from Execute(AThread: TIdPeerThread) event), the SetLink command failed.

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消息,或者其他东西不是线程安全的,或者在线程级别上是不可捕获的?

Maybe the DDE is using Windows messages, or other things are not threadsafe, or not catchable in the thread's level?

感谢您提供有关此信息: dd

Thanks for any info about this: dd

推荐答案

DDE构建在Windows消息之上.您需要确保在具有DDE连接的线程上调度消息.

DDE is built on top of windows messages. You need to make sure that messages are dispatched on the thread that has the DDE connection.

这篇关于Delphi:来自Indy TCPServer线程的DDE调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 12:57