A simple example of component design based on Delphi

Source: Internet
Author: User

The next step is to do a component, I think of a counter component, functional aspects are relatively simple, but this is not the focus of this chapter, this chapter focuses on the production of a component of the entire process. In which I can learn a lot of component production skills, of course, these are also I learned from the book.

This is a component that can be counted, in order to be simple, I'm in seconds, and when it starts, he starts to increase from 0, and it shows up, by 3600, it goes back to 0, so it loops. Of course it can also stop, pause, continue. In addition, he has a time event, that is, you can set the number of times to trigger this event, which is a good feature, we can set a half-hour trigger event, in the event handler function to a sound, and then sleep, half an hour later, the voice to remind you to get up.

Instead of creating a new component unit in the first place, we used it as a class in a project to make it easier to debug, so we created a new project and created a new blank cell for the class.

First, determine the parent class:

Next to this class called Ttimecount, then its parent should be what it is, it should be able to display, have a capacity to let him show that Tpanel is a good choice, I looked at the source code, found that Tpanel did not do anything, Just to manifest the attributes of its parent class Tcustompanel (This is a wait-and-see), Tcustompanel a lot of attributes as protected, providing a choice for his subclasses, whose subclasses if they are to be seen in the object Viewer, You can make a published again, if you don't want to, you don't have to ignore him. And our counter component just doesn't need so many attributes, just right. So I decided to use Tcusompanel as the parent class.

Class is established as follows:

TTimeCount=class(TCustomPanel)
private
protected
public
published
end;

Ii. determining members, methods and properties and events

Fcount; Read-only private members, save count values

Factive:boolean; /Determine if the class's time interval event occurs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.