簡體   English   中英

Delphi:來自Indy TCPServer線程的DDE調用

[英]Delphi: DDE call from Indy TCPServer Thread

我嘗試從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消息,或者其他東西不是線程安全的,或者在線程級別上是不可捕獲的?

感謝您提供有關此信息:dd

DDE建立在Windows消息之上。 您需要確保在具有DDE連接的線程上調度消息。

我知道為時已晚,但可能有人需要此說明。 我已經做了太多的工作。 我有同樣的問題(但使用openlink方法,而不是使用Set Link方法。我使用的連接模式為ddeManual,而不是自動的)。最后我發現了一些問題。 Delphi ddeMgr位於VCL單元中,需要像Synchronize(yourProcedure)一樣調用它。 當我編寫另一個過程(該過程包括我所有的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;

希望這些信息對其他人有所幫助:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM