@getmem
First, i really apreciated your time and help.
I read and run your code, and i do not understand many things (i had never worked with classes, for example). But for what i understood from your test project, it is the same thing i posted in this topic, but with another aproach. Anyway, i will use it to study and try to learn using reverse engineering
What i can do with my (very) limited lazarus/fpc knowledge looks easy to do, but not in an "elegant" (or easy) way. I was thinking in a possible solution, but due to the very hard job it minds for my entire project, this is the basic idea(i will create a backup of my project first anyway)(off topic: it is time to add a simple "Rename Project" option to the lazarus GUI)
var // Global
URLtoRead : string;
StringFromURL : string;
ThreadNumber:Integer;
procedure Read_URL_GET();
begin
with TFPHTTPClient.Create(nil) do
try
StringFromURL := Get(URLtoRead);
except
on E:Exception do
begin
StringFromURL := 'ERROR';
end;
end;
end;
procedure GetDataFromServer(URL:String;TimeOUTQuery:integer);
begin
URLtoRead := URL;
StringFromURL := 'DOWN': // set by default
ThreadNumber:= BeginThread(TThreadFunc(@Read_URL_GET));
WaitForThreadTerminate(ThreadNumber,TimeOUTQuery);
end;
EDITED: This is working perfectly (until now)!! I even dont need a timer.
GetDataFromServer('https://myweb.com/',1500); // this page returns 'ok'
if StringFromURL = 'DOWN' then // what to do if server is down
else if StringFromURL = 'ERROR' then // if the server gives a bad answer
else // and here what to do if everything go fine
;
I dont know if this code could be improved, but do the job.