Monday 15 September 2014

performance - Delphi - delay processing if user still typing -



performance - Delphi - delay processing if user still typing -

i have application has edit field. user type search phrase in field. trying show in real time hits against user's text. after entering 3 characters, first search, , after every character or backspace search performed again.

the problem search algorithm getting more advanced, takes longer search. user can type faster results before generated/displayed. result, app feeling sluggish/slow. have couple options: (1). wait until user hits come in (2). set search in different thread , asynchronously. kinda hesitant here since have never worked threads before (3). implement type of delay if user still typing, wait user stop.

i leaning towards alternative 3, how observe if user still typing? have maintain timestamp associated every keystroke?

if stick threading solution.

it faster, not lag , - if written - not introduce additional problems, , great chance larn threading not risky or hard problem. if take solution have perform 4 easy steps:

create onsearchfinished() event handler on form , assign message code (like wm_user + 1). message sent thread when has finished producing search results. create tthread descendant search code in .execute() method perform search. has have field search term. (the .execute() not called straight can't handle parameters. execute tthread descendents .resume()ing them.) instance of class can created in constructor of form , needs created in suspended state. assuming search code has main cycle, you have check if main programme called .terminate() on object. if has, have exit cycle. in .onchange() or .onkeydown() handle search, should (first) .terminate() thread (to stop running search if there any), set field new search term , .resume() it.

performance delphi user-interface

No comments:

Post a Comment