Jump to content
rones

IdSNTP library Delphi 10.3

Recommended Posts

HELP PLEASE. I'm using the library above to connect to the internet and get the date, but depending on the wifi connection I use, the system generates an exception and doesn't connect to the internet. What can i do?

 

Follow the line of code below:

 

function internetdate: TDateTime;
var
IdSNTP: TIDSntp;
begin
IdSNTP := TIDSntp.Create(nil);
try
IdSNTP.Host := 'pool.ntp.br';
Application.ProcessMessages;
Result := IdSNTP.DateTime;
Application.ProcessMessages;
finally
IdSNTP.Free;
end;
end

Share this post


Link to post

why you needs 2 "Application.ProcessMessages" ?

 

procedure TForm1.Button1Click(Sender: TObject);
var
  LIdSNTP: TIdSNTP;
begin
  LIdSNTP := TIdSNTP.Create(nil);
  try
    LIdSNTP.Host   := 'pool.ntp.br';
    Label1.Caption := DateTimeToStr(LIdSNTP.DateTime); // working!
  finally
    LIdSNTP.Free;
  end;
end;

 

Edited by programmerdelphi2k

Share this post


Link to post
58 minutes ago, rones said:

HELP PLEASE. I'm using the library above to connect to the internet

TIdSNTP, and Indy in general, does not connect you to the Internet.  You have to already be connected beforehand.  It would be more accurate to say that you are using TIdSNTP to connect to a remote time server that is accessible over the Internet.

Quote

and get the date, but depending on the wifi connection I use, the system generates an exception

What type of exception are you seeing, exactly?  What does it say?  Please be more specific.

Edited by Remy Lebeau

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×