全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1333
推到 Plurk!
推到 Facebook!

idpop保存内容时出现问题?

缺席
sl@cableplus.com.cn
高階會員


發表:168
回覆:359
積分:130
註冊:2004-03-26

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-05-20 09:38:07 IP:218.80.xxx.xxx 未訂閱
代码如下: if IdMessage1.MessageParts.Items[i] is TIdText then begin AdoInsertMail.Parameters.ParamByName('Content').Value := TIdText(IdMessage1.MessageParts.Items[i]).Body.Text; end; 好象没有把邮件的内容保存进字段里,大多数都没保存进去,请问是为什么?
sl@cableplus.com.cn
高階會員


發表:168
回覆:359
積分:130
註冊:2004-03-26

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-05-20 11:02:33 IP:218.80.xxx.xxx 未訂閱
我的整体代码如下: if IdMessage1.MessageParts.AttachmentCount > 0 then begin AdoInsertMail.Parameters.ParamByName('HadAttach').Value := 1; for i := 0 to IdMessage1.MessageParts.Count - 1 do begin if (IdMessage1.MessageParts.Items[i] is TIdAttachment) then begin AdoOAEAttach.SQL.Clear; AdoOAEAttach.Parameters.Clear; AdoOAEAttach.SQL.Add('insert into OAEAttach(pkey,pripkey,attachname,attach,operator,operdate)'); AdoOAEAttach.SQL.Add('values (:pkey,:pripkey,:attachname,:attach,:operator,:operdate)'); AdoOAEAttach.Active := False; QryEAttachMaxPkey.Active := False; QryEAttachMaxPkey.Active := True; AdoOAEAttach.Parameters.ParamByName('PKey').Value := QryEAttachMaxPkey.FieldByName('PKey').AsInteger 1; AdoOAEAttach.Parameters.ParamByName('pripkey').Value := QryMaxPkey.FieldByName('Pkey').AsInteger 1; AdoOAEAttach.Parameters.ParamByName('attachname').Value := Base64Decode(TIdAttachment(IdMessage1.MessageParts.Items[i]).FileName); fName := Base64Decode(TIdAttachment(IdMessage1.MessageParts.Items[i]).Filename); if FileExists(fName) then DeleteFile(fName); try if TIdAttachment(IdMessage1.MessageParts.Items[i]).SaveToFile(fName) then AdoOAEAttach.Parameters.ParamByName('attach').LoadFromFile(fName, ftBlob); AdoOAEAttach.Parameters.ParamByName('Operator').Value := UserName; AdoOAEAttach.Parameters.ParamByName('OperDate').Value := Date(); AdoOAEAttach.ExecSQL; except ShowMessage(SysErrorMessage(GetLastError)); end; end else begin if IdMessage1.MessageParts.Items[i] is TIdText then begin AdoInsertMail.Parameters.ParamByName('Content').Value := TIdText(IdMessage1.MessageParts.Items[i]).Body.Text; end; end; 以上代码如果在没有附件的情况下就不会运行到 if IdMessage1.MessageParts.Items[i] is TIdText then begin AdoInsertMail.Parameters.ParamByName('Content').Value := TIdText(IdMessage1.MessageParts.Items[i]).Body.Text; end; 这段代码,请教应该如何解决?
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-05-20 11:31:20 IP:202.39.xxx.xxx 未訂閱
  if IdMessage1.MessageParts.AttachmentCount > 0 then
  begin
    AdoInsertMail.Parameters.ParamByName('HadAttach').Value := 1;
    for i := 0 to IdMessage1.MessageParts.Count - 1 do
    begin
      if (IdMessage1.MessageParts.Items[i] is TIdAttachment) then
      begin
        AdoOAEAttach.SQL.Clear;
        AdoOAEAttach.Parameters.Clear;
        AdoOAEAttach.SQL.Add('insert into OAEAttach(pkey,pripkey,attachname,attach,operator,operdate)');
        AdoOAEAttach.SQL.Add('values (:pkey,:pripkey,:attachname,:attach,:operator,:operdate)');
        AdoOAEAttach.Active := False;            QryEAttachMaxPkey.Active := False;
        QryEAttachMaxPkey.Active := True;            AdoOAEAttach.Parameters.ParamByName('PKey').Value := QryEAttachMaxPkey.FieldByName('PKey').AsInteger   1;
        AdoOAEAttach.Parameters.ParamByName('pripkey').Value := QryMaxPkey.FieldByName('Pkey').AsInteger   1;            AdoOAEAttach.Parameters.ParamByName('attachname').Value := Base64Decode(TIdAttachment(IdMessage1.MessageParts.Items[i]).FileName);
        fName :=
        Base64Decode(TIdAttachment(IdMessage1.MessageParts.Items[i]).Filename);
        if FileExists(fName) then
          DeleteFile(fName);
        try
          if TIdAttachment(IdMessage1.MessageParts.Items[i]).SaveToFile(fName) then
            AdoOAEAttach.Parameters.ParamByName('attach').LoadFromFile(fName, ftBlob);
          AdoOAEAttach.Parameters.ParamByName('Operator').Value := UserName;
          AdoOAEAttach.Parameters.ParamByName('OperDate').Value := Date();
          AdoOAEAttach.ExecSQL;
        except
          ShowMessage(SysErrorMessage(GetLastError));
        end;
      end
    end
  end
  else
  begin
    AdoInsertMail.Parameters.ParamByName('HadAttach').Value := 0;
    for i := 0 to IdMessage1.MessageParts.Count - 1 do
    begin
      if IdMessage1.MessageParts.Items[i] is TIdText then
      begin
        AdoInsertMail.Parameters.ParamByName('Content').Value := TIdText(IdMessage1.MessageParts.Items[i]).Body.Text;
      end;
    end;
  end;
sl@cableplus.com.cn
高階會員


發表:168
回覆:359
積分:130
註冊:2004-03-26

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-05-20 11:39:51 IP:218.80.xxx.xxx 未訂閱
根据大大写的 根本不执行for i := 0 to IdMessage1.MessageParts.Count - 1 do 循环,IdMessage1.MessageParts.Count - 1 为0,请问是什么原因?
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-05-20 11:52:34 IP:202.39.xxx.xxx 未訂閱
那這樣咧?
    for i := 0 to IdMessage1.MessageParts.Count - 1 do
    begin
      if (IdMessage1.MessageParts.Items[i] is TIdAttachment) then
      begin
        AdoInsertMail.Parameters.ParamByName('HadAttach').Value := 1;            AdoOAEAttach.SQL.Clear;
        AdoOAEAttach.Parameters.Clear;
        AdoOAEAttach.SQL.Add('insert into OAEAttach(pkey,pripkey,attachname,attach,operator,operdate)');
        AdoOAEAttach.SQL.Add('values (:pkey,:pripkey,:attachname,:attach,:operator,:operdate)');
        AdoOAEAttach.Active := False;            QryEAttachMaxPkey.Active := False;
        QryEAttachMaxPkey.Active := True;            AdoOAEAttach.Parameters.ParamByName('PKey').Value := QryEAttachMaxPkey.FieldByName('PKey').AsInteger   1;
        AdoOAEAttach.Parameters.ParamByName('pripkey').Value := QryMaxPkey.FieldByName('Pkey').AsInteger   1;            AdoOAEAttach.Parameters.ParamByName('attachname').Value := Base64Decode(TIdAttachment(IdMessage1.MessageParts.Items[i]).FileName);
        fName :=
        Base64Decode(TIdAttachment(IdMessage1.MessageParts.Items[i]).Filename);
        if FileExists(fName) then
          DeleteFile(fName);
        try
          if TIdAttachment(IdMessage1.MessageParts.Items[i]).SaveToFile(fName) then
            AdoOAEAttach.Parameters.ParamByName('attach').LoadFromFile(fName, ftBlob);
          AdoOAEAttach.Parameters.ParamByName('Operator').Value := UserName;
          AdoOAEAttach.Parameters.ParamByName('OperDate').Value := Date();
          AdoOAEAttach.ExecSQL;
        except
          ShowMessage(SysErrorMessage(GetLastError));
        end;
      end
      else
      begin
        AdoInsertMail.Parameters.ParamByName('HadAttach').Value := 0;
        if IdMessage1.MessageParts.Items[i] is TIdText then
          AdoInsertMail.Parameters.ParamByName('Content').Value := TIdText(IdMessage1.MessageParts.Items[i]).Body.Text;
      end;
    end;
sl@cableplus.com.cn
高階會員


發表:168
回覆:359
積分:130
註冊:2004-03-26

發送簡訊給我
#6 引用回覆 回覆 發表時間:2004-05-20 12:00:44 IP:218.80.xxx.xxx 未訂閱
if IdMessage1.MessageParts.Items[i] is TIdText then 执行到该语句后说List index out of bounds(0) 应该i有个值吧,请教
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#7 引用回覆 回覆 發表時間:2004-05-20 14:25:58 IP:202.39.xxx.xxx 未訂閱
小弟這麼試的, 不會出現 List Index Out of bounds 的問題
procedure TForm1.Button1Click(Sender: TObject);
var
  fName: string;
  i, j, iCount: integer;
begin
  Button1.Enabled := False;
  try
    IdPop31.Connect;
    iCount := IdPop31.CheckMessages;
    memo1.Lines.Add('mail count: '   IntToStr(iCount));
    for j := 0 to iCount -1 do
    begin
      IdMessage1.Clear;
      IdPop31.RetrieveHeader(j 1, IdMessage1);          Memo1.Lines.Add(#13#10'mail'   IntToStr(j 1));
      Memo1.Lines.Add('Subject: '   IdMessage1.Subject);          IdMessage1.Clear;
      IdMessage1.NoDecode := False;
      IdPop31.Retrieve(j, IdMessage1);          Memo1.Lines.Add('MessageParts Count: '   IntToStr(IdMessage1.MessageParts.Count));
      for i := 0 to Pred(IdMessage1.MessageParts.Count) do
      begin
        Memo1.Lines.Add('MessageParts'   IntToStr(i));
        if (IdMessage1.MessageParts.Items[i] is TIdAttachment) then
        begin
          fName := TIdAttachment(IdMessage1.MessageParts.Items[i]).Filename;
          Memo1.Lines.Add('Attachement File Name: '   fName);
        end
        else
        begin
          if IdMessage1.MessageParts.Items[i] is TIdText then
            Memo1.Lines.Add(TIdText(IdMessage1.MessageParts.Items[i]).Body.Text);
        end;
      end;
    end;
  finally
    IdPop31.Disconnect;
    Button1.Enabled := True;
  end;
end;
sl@cableplus.com.cn
高階會員


發表:168
回覆:359
積分:130
註冊:2004-03-26

發送簡訊給我
#8 引用回覆 回覆 發表時間:2004-05-20 14:40:01 IP:218.80.xxx.xxx 未訂閱
请教大大我做这句话 for i := 0 to Pred(IdMessage1.MessageParts.Count) do 始终就直接跳出FOR循环,请问是为什么?
sl@cableplus.com.cn
高階會員


發表:168
回覆:359
積分:130
註冊:2004-03-26

發送簡訊給我
#9 引用回覆 回覆 發表時間:2004-05-20 15:05:37 IP:218.80.xxx.xxx 未訂閱
根据大大的写法,碰到现象是有附件的时候就有邮件内容而无附件的时候就没有内容,是何原因?我代码如下: for intIndex := 1 to inMsgCount do begin for i := 0 to pred(IdMessage1.MessageParts.Count) do begin if (IdMessage1.MessageParts.Items[i] is TIdAttachment) then begin AdoInsertMail.Parameters.ParamByName('HadAttach').Value := 1; AdoOAEAttach.SQL.Clear; AdoOAEAttach.Parameters.Clear; AdoOAEAttach.SQL.Add('insert into OAEAttach(pkey,pripkey,attachname,attach,operator,operdate)'); AdoOAEAttach.SQL.Add('values (:pkey,:pripkey,:attachname,:attach,:operator,:operdate)'); AdoOAEAttach.Active := False; QryEAttachMaxPkey.Active := False; QryEAttachMaxPkey.Active := True; AdoOAEAttach.Parameters.ParamByName('PKey').Value := QryEAttachMaxPkey.FieldByName('PKey').AsInteger 1; AdoOAEAttach.Parameters.ParamByName('pripkey').Value := QryMaxPkey.FieldByName('Pkey').AsInteger 1; AdoOAEAttach.Parameters.ParamByName('attachname').Value := Base64Decode(TIdAttachment(IdMessage1.MessageParts.Items[i]).FileName); fName := Base64Decode(TIdAttachment(IdMessage1.MessageParts.Items[i]).Filename); if FileExists(fName) then DeleteFile(fName); try if TIdAttachment(IdMessage1.MessageParts.Items[i]).SaveToFile(fName) then AdoOAEAttach.Parameters.ParamByName('attach').LoadFromFile(fName, ftBlob); AdoOAEAttach.Parameters.ParamByName('Operator').Value := UserName; AdoOAEAttach.Parameters.ParamByName('OperDate').Value := Date(); AdoOAEAttach.ExecSQL; except ShowMessage(SysErrorMessage(GetLastError)); end; end else begin if IdMessage1.MessageParts.Items[i] is TIdText then begin AdoInsertMail.Parameters.ParamByName('Content').Value := TIdText(IdMessage1.MessageParts.Items[i]).Body.Text; end; end; end;
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#10 引用回覆 回覆 發表時間:2004-05-20 21:38:48 IP:202.39.xxx.xxx 未訂閱
引言: 请教大大我做这句话 for i := 0 to Pred(IdMessage1.MessageParts.Count) do 始终就直接跳出FOR循环,请问是为什么?
Pred 函式是得到其所傳入參數前一個值, 比方說 Pred(10) 得到的值為 9 可以看 help 內的 example 至於您說的有附件就有內容, 沒附件就沒內容的問題, 小弟這邊沒發生哩! 發表人 - hagar 於 2004/05/20 21:46:14
sl@cableplus.com.cn
高階會員


發表:168
回覆:359
積分:130
註冊:2004-03-26

發送簡訊給我
#11 引用回覆 回覆 發表時間:2004-05-21 08:44:53 IP:218.80.xxx.xxx 未訂閱
我现在碰到的问题就是如果没有附件它就不去运行这句话 for i := 0 to Pred(IdMessage1.MessageParts.Count) do 请问是为什么?是不是哪里写错了?
sl@cableplus.com.cn
高階會員


發表:168
回覆:359
積分:130
註冊:2004-03-26

發送簡訊給我
#12 引用回覆 回覆 發表時間:2004-05-21 08:54:36 IP:218.80.xxx.xxx 未訂閱
现在收信后正常的正文内容都没有的,有的只是一些HTML的定义如什么HERF,HEAD的东西,请问什么原因?
sl@cableplus.com.cn
高階會員


發表:168
回覆:359
積分:130
註冊:2004-03-26

發送簡訊給我
#13 引用回覆 回覆 發表時間:2004-05-21 09:04:18 IP:218.80.xxx.xxx 未訂閱
谢谢大大,是我自己搞混淆了,现在已经解决问题,非常感谢!
系統時間:2024-05-17 20:01:37
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!