2012-07-03 34 views
2

我在下面的代碼中遇到了問題,它指的是StoredPathName。由於Indy 10不使用StoredPathName,我不確定如何更改此代碼以從V9調整到V10。下面的代碼不是我自己寫的,當談到這種類型的代碼時,我仍然是一個新手,所以我會很感激代碼示例,展示如何儘可能地糾正問題。將Delphi Indy v9代碼轉換爲v10

vlist:TStringList; 

... 
for j:=numEmails downto 1 do 
    begin 
    Msg.Clear; 
    Retrieve(j,Msg); 

    for k:=0 to Msg.MessageParts.Count-1 do 
     with Msg.MessageParts[k] do 
     if Msg.messageParts[k] is TIdAttachmentFile then 
      begin 
      //Get the name of the file that was sent. 
      aname := TIdAttachmentFile(Msg.MessageParts[k]).FileName; 

      if SameText(aname,ExtractFilename(PacketFilename)) 
      and FileExists(Longfilename(StoredPathName)) then 
       begin 
       //Read attachment and do call-back if defined. 
       vlist.LoadfromFile(LongFilename(StoredPathName)); 

       if assigned(OnReceive) then 
        OnReceive; 
       end 
      end; 
    end; 

Disconnect; 

except 
    on E:Exception do 
    result := E.Message; 
end; 

同樣的代碼,另外一個位是... Connect(9000); 由於9000是不是允許的說法我只是把它改爲Connect;這樣可以嗎?

+0

在印地如圖9所示,參數爲'連接()'是'ConnectTimeout'。在Indy 10,這是移動自己的財產。 –

回答

1

StoredPathName是從TIdMessagePart移到TIdAttachmentFile的屬性。如果你改變代碼在頂部進行類型轉換,它應該都可以工作。

變化這樣的:

with Msg.MessageParts[k] do 
    if Msg.messageParts[k] is TIdAttachmentFile then 

到:

if Msg.messageParts[k] is TIdAttachmentFile then 
    with TIdAttachmentFile(Msg.MessageParts[k]) do 
+0

是的,解決了這個問題。非常感謝。 – Col