You are not logged in.
Hi,
if i execute the connection with the server that is not started, i have a exception.
procedure LoadClientDatabase(var ClientDB: TSQLRestClientDB; ServerName: string; Port: Integer);
begin
try
Model := GetDatabaseModel('root');
ClientDB := TSQLRestClientDB(TSQLite3HttpClient.Create(ServerName, IntToStr(Port), Model));
except
//on E: Exception do
// handle initialization error here
end;
end;
Can I avoid the exception and perform a test to see if the server is reachable or started?
thanks corchi
Offline
What's wrong with the exception?
Just intercept it in the except clause.
In your code, you're typecasting a TSQLite3HttpClient into a TSQLRestClientDB, and those two types are not compatible.
You should use the generic common ancestor TSQLRestClient or TSQLRestClientURI instead.
If you are not sure about the type, don't use forced typecast, but uses the "as" statement:
TSQLite3HttpClient.Create(....) as TSQLRestClientDB
It will raise an exception if the typecast is not correct.
I use forced typecast in my code only when I'm sure that the types are correct.
Offline