BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

DNSResolver Acces Violation

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Internet Winsock
View previous topic :: View next topic  
Author Message
Saverio Pieri
Guest





PostPosted: Wed Nov 17, 2004 6:19 pm    Post subject: DNSResolver Acces Violation Reply with quote



I wrote a multithread console application to verify email adresses.

Each thread create a datamodule with TIdDNSResolver e TIdTCPClient.

I have problems with TIdDNSResolver.

To find the primary MX server I wrote the method below:

Even if

FdmVer.dns.QueryResult.Count > 0

when I try to access with

mxitem := TMxRecord(FdmVer.dns.queryresult[i]);

I obtain an Access Violation.

Why?


{*************************************************************************}
function TThreadVerifier.ResolveMxRecod(lpHost,lpDomain : string; dwPort :
longWord) : string;
var
mxitem : TMxRecord;
i : integer;
wPref : Word;
sMx : string;
begin

sMx := '';
FdmVer.dns.QueryResult.Clear;
FdmVer.dns.Host := lpHost;
FdmVer.dns.Port := dwPort;
FdmVer.dns.QueryRecords := [qtMx];
FdmVer.dns.AllowRecursiveQueries := true;
FdmVer.dns.ReceiveTimeout := FTimeout;
FdmVer.dns.Resolve(lpDomain);
wPref := $FFFF;
for i := 0 to FdmVer.dns.QueryResult.Count -1 do
begin
mxitem := TMxRecord(FdmVer.dns.queryresult[i]);
if (mxitem.RecType = qtMX) and( mxitem.Preference <= wPref) then
begin
wPref := mxitem.Preference;
sMx := mxItem.ExchangeServer;
if wPref = 1 then break;
end;
end;
result := sMx;
end;
{*************************************************************************}


Back to top
Martin James
Guest





PostPosted: Wed Nov 17, 2004 6:44 pm    Post subject: Re: DNSResolver Acces Violation Reply with quote




"Saverio Pieri" <spad (AT) interconnessioni (DOT) it> wrote

Quote:
I wrote a multithread console application to verify email adresses.

Each thread create a datamodule with TIdDNSResolver e TIdTCPClient.

I have problems with TIdDNSResolver.

To find the primary MX server I wrote the method below:

Even if

FdmVer.dns.QueryResult.Count > 0

when I try to access with

mxitem := TMxRecord(FdmVer.dns.queryresult[i]);

I obtain an Access Violation.


I enclose my own DNSresolver procedure. It looks almost identical to yours,
except that I have:

thisPref:=TmxRecord(QueryResult.items[mxServerIndex]).preference;

but you have:

mxitem := TMxRecord(FdmVer.dns.queryresult[i]);
...
wPref := mxitem.Preference;

Why there should be a difference, I do not know, but mine works :)

Rgds,
Martin

PS don't be misled by the 'postError' calls in my code - it's just a logging
proc that was origninally used for logging only errors but I used it for
debigging & status later & did not rename it :(

Quote:


{*************************************************************************}
function TThreadVerifier.ResolveMxRecod(lpHost,lpDomain : string; dwPort :
longWord) : string;
var
mxitem : TMxRecord;
i : integer;
wPref : Word;
sMx : string;
begin

sMx := '';
FdmVer.dns.QueryResult.Clear;
FdmVer.dns.Host := lpHost;
FdmVer.dns.Port := dwPort;
FdmVer.dns.QueryRecords := [qtMx];
FdmVer.dns.AllowRecursiveQueries := true;
FdmVer.dns.ReceiveTimeout := FTimeout;
FdmVer.dns.Resolve(lpDomain);
wPref := $FFFF;
for i := 0 to FdmVer.dns.QueryResult.Count -1 do
begin
mxitem := TMxRecord(FdmVer.dns.queryresult[i]);
if (mxitem.RecType = qtMX) and( mxitem.Preference <= wPref) then
begin
wPref := mxitem.Preference;
sMx := mxItem.ExchangeServer;
if wPref = 1 then break;
end;
end;
result := sMx;
end;

{*************************************************************************}


procedure makeAttemptToResolve;
var mxServerIndex:integer;
begin
with myDNSresolver do
begin
try
host:=thisDNSserver;
queryRecords:=[qtMX];
postError('DNS server: '+inSendObject.DNSserver);
postError('Calling resolver');
Resolve(messDomain);
postError('Resolver returns with
'+intToStr(QueryResult.count)+
' records');
prefMin:=65535;
indexPrefMin:=0;
postError('Scan for best preference');
for mxServerIndex:=0 to QueryResult.Count-1 do
begin

thisPref:=TmxRecord(QueryResult.items[mxServerIndex]).preference;
if (thisPref begin
prefMin:=thisPref;
indexPrefMin:=mxServerIndex;
end;
end;
postError('wBest server is
'+TmxRecord(QueryResult.items[indexPrefMin]).exchangeServer);

result:=TmxRecord(QueryResult.items[indexPrefMin]).exchangeServer;
postError('Domain '+messDomain+' resolved to: '+result);
except
on e:exception do
begin
postError('Resolve attempt '+intToStr(resolveRetryCount)+
' failed: '+ inSendObject.localMailServer+
': '+e.message);
result:='';
end;
end; //try
end; // with
end;

Quote:




Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Internet Winsock All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.