procedure TMailServer.GetListStr();
var
MailStrings: String;
CdStrings:String;
i:integer;
begin
for i := 0 to ListStr.Count-1 do
begin
application.ProcessMessages;
MailStrings := CutStr(ListStr.Strings[i],1);
CdStrings := Cutstr(ListStr.Strings[i],0);
if mailstrings = '[email protected]' then
begin
SendMail(MailStrings,CdStrings);
end;
end;
end;
上面是从邮箱中收取邮件,然后一条一条对比,如果发件人是[email protected],那么就回复一封邮件。
cutstr是把发件人和主题分割开。但是每次运行到这里就会提示:List index out of bounds(1)怎么回事呢?请大家帮我解决一下。
var
MailStrings: String;
CdStrings:String;
i:integer;
begin
for i := 0 to ListStr.Count-1 do
begin
application.ProcessMessages;
MailStrings := CutStr(ListStr.Strings[i],1);
CdStrings := Cutstr(ListStr.Strings[i],0);
if mailstrings = '[email protected]' then
begin
SendMail(MailStrings,CdStrings);
end;
end;
end;
上面是从邮箱中收取邮件,然后一条一条对比,如果发件人是[email protected],那么就回复一封邮件。
cutstr是把发件人和主题分割开。但是每次运行到这里就会提示:List index out of bounds(1)怎么回事呢?请大家帮我解决一下。
即运行时先将油箱中的邮件动态添加到liststr中;
已经添加到liststr中了。我试2楼的方法看看。
最好用 i := ListStr.Count-1 downto 0 do 因为你删除1时,2就变成第一个了。 你再去删除第二个,第二个可能就已经不存在了。
同样的问题也会出现。如果把部分内容注释掉就不会出问题
procedure TMailServer.GetListStr();
var
MailStrings: String;
CdStrings:String;
i:integer;
begin
for i := 0 to ListStr.Count-1 do
begin
application.ProcessMessages;
MailStrings := CutStr(ListStr.Strings[i],1);
CdStrings := Cutstr(ListStr.Strings[i],0);
//if mailstrings = '[email protected] ' then
// begin
// SendMail(MailStrings,CdStrings);
// end;
end;
end;
procedure TForm1.Button4Click(Sender: TObject);
var
MailStrings:String;
i:integer;
listStr:TStringlist;
begin
liststr:=TStringList.Create;
liststr.Delimiter:=',';
liststr.DelimitedText:='[email protected],[email protected],[email protected],[email protected]';
for i:=0 to ListStr.Count-1 do
begin
application.ProcessMessages;
MailStrings:=ListStr.Strings[i];
if mailstrings='[email protected]' then
begin
showmessage(MailStrings);
end;
end;
liststr.Free;
end;感觉可能是你CutStr函数的问题
function CutStr(MailStr:string;k:integer):String;
var
ASource: PChar;
ACount,i: Integer;
AStrings: TStringList;
begin
ASource := PChar(MailStr);
AStrings := TStringList.Create;
try
ACount := ExtractStrings(['|'], [' ','.','"'], ASource, AStrings);
Result := AStrings.Strings[k];
finally
AStrings.Free;
end;end;
'邮件主题2|[email protected]'
procedure TForm1.Button5Click(Sender: TObject);
var
MailStrings:String;
CdStrings:String;
i:integer;
liststr:TStringlist;
begin
liststr:=TStringList.Create;
liststr.Add('邮件主题1|[email protected]');
liststr.Add('邮件主题2|[email protected]');
for i:= 0 to ListStr.Count-1 do
begin
application.ProcessMessages;
MailStrings:=CutStr(ListStr.Strings[i],1);
CdStrings:=Cutstr(ListStr.Strings[i],0);
if mailstrings='[email protected]' then
begin
showmessage(MailStrings+' '+CdStrings);
//SendMail(MailStrings,CdStrings);
end;
end;
liststr.free;
end;
还是一点问题没有