android - (Indy) How to catch a Button click event before ConnectTimeout is reached -
i want make simple function user clicks on on/off button , makes indy tcp client try connect ip, connection takes long (due bad phone signal) , user may tap once again button turn off. indy catch event (button click) when connecttimeout reached or when connection succeed. thinking in put low connecttimeout , make multiple tries connect can catch button click without waiting long, there way catch button click event anytime when trying connect? thank you.
@edit: well, decided make first idea: multiple tries connect low connecttimeout , count them until reach desired connecttimeout, while in mean time can check button press turn off.
i tested using phone hspa+ connection , metal plate (to simulate bad signal) , apparently work.
the simplified code ended this:
var disconnectedonce: integer; procedure tform1.idtcpclient1disconnected(sender: tobject); begin if buttoniniciar.text = 'stop' begin try idtcpclient1.connect; except if disconnectedonce = 0 begin disconnectedonce := 1; // try 1 more time connect, in case connecttimeout must set half desired application.processmessages; idtcpclient1.ondisconnected(idtcpclient1); end else begin buttoniniciar.text = 'start'; end; end; end; end;
the bad or unsafe on idea?
Comments
Post a Comment