- Mastering Delphi Programming:A Complete Reference Guide
- Primo? Gabrijel?i?
- 369字
- 2021-06-24 12:33:31
Responsive user interfaces
A user's first contact with any program is always the user interface. A good UI can make or break a program. Leaving the user interface design aside (as I am not qualified to speak about that), I will focus on just one fact.
Users hate user interfaces that are not responsive.
In other words, every good user interface must react quickly to a user's input, be that a keyboard, mouse, touchpad, or anything else.
What are the tasks that can make a user interface unresponsive? Basically, they all fall into one of two categories:
- A program is running a slow piece of code. While it is running, the UI is not responding.
- Updating the user interface itself takes a long time.
The problems from the first category fall into two subsets—functions that have non-blocking (asynchronous) alternatives and functions that don't.
Sometimes we can replace the slow function with another one that runs asynchronously. For example, instead of using a standard function for reading from a file, we can use the Windows Asynchronous File I/O API. File reading will then occur in parallel with our program and we will be notified of successful or unsuccessful reads via some other mechanism.
Often, however, this is not possible (there is no alternative for the slow function) or the asynchronous version is too complicated to implement. In that case, we can execute the slow code in a thread. This will be covered in chapters 5 to 7.
An excellent candidate for the multithreaded approach is the file reading example. True, Windows offers an asynchronous API for that, but it is quite complicated and tricky to implement correctly. Pushing a read operation into a thread is simpler and cross-platform compatible if that is important for your application.
The second category (updating the UI takes a long time) is typically solved with a simple solution: Do less updating! Delphi/Windows controls are typically very fast and they only fail when we want them to do too many operations in a short time.
We will now focus on that category. I'll show a few examples of overabundant updates and give solutions for faster code.
- Intel FPGA/CPLD設計(基礎篇)
- Learning Cocos2d-x Game Development
- Raspberry Pi 3 Cookbook for Python Programmers
- Linux KVM虛擬化架構實戰指南
- 計算機應用與維護基礎教程
- Unity 5.x Game Development Blueprints
- 數字邏輯(第3版)
- 深入淺出SSD:固態存儲核心技術、原理與實戰(第2版)
- CC2530單片機技術與應用
- 單片機系統設計與開發教程
- Neural Network Programming with Java(Second Edition)
- 筆記本電腦芯片級維修從入門到精通(圖解版)
- IP網絡視頻傳輸:技術、標準和應用
- Istio實戰指南
- USB應用分析精粹:從設備硬件、固件到主機端程序設計