Self-made dynamically displayed control in Delphi

Source: Internet
Author: User

Delphi with its excellent interface and simple usage by the majority of programmers love. After groping, the author made a control with dynamic display characteristics. You can implement a dynamic display by simply invoking a method of the control in the main program.

In the dynamic display, in order not to affect the main program to do other things, the author used a more popular threading technology.

A Scheme

A control with a parent class of tedit should have a text property that can freely enter the content to be displayed dynamically; And there is a moveshow method, so that the content of the text can be dynamically displayed. When a thread is created in the main program, the Moveshow method of the control is invoked when the thread is started.

Two Making controls

Start the new Component, select Tedit as the parent class, establish the L_tedit1 class, and create the L_edit.pas. Rewrite the L_edit.pas as follows:

Unit L_edit
Interface
uses
Windows, Messages, Sysutils, Classes, Graphics,
Controls, Forms, Dia Logs,
Stdctrls
Type
L_tedit1 = Class (Tedit)
Private
{private declarations}
protected
{prot ected declarations}
Public
{public declarations}
Constructor Create (aowner:tcomponent); override
Proc Edure moveshow;
published
{published declarations}
Property Text;
End;
procedure Register;
Implementation
C Onstructor l_tedit1.create (aowner:tcomponent);
Begin
inherited create (Aowner);
Color:=clblue
Font. Color:=clyellow;
Font. size:=12;
Font. name:= ' @ imitation _gb2312 ';
Tabstop:=false;
Update;
End;
Procedure L_tedit1.moveshow;
var
edit_length,i:integer
Edit_char:char
chars:string;
begin
Chars:= ';
if (length text =0) then
text:= ' welcom ' to use the software! ';
Edit_length:=length (text);
for I:=1 to Edit_length do
begin
Edit_char:=text[1];
if (Ord (Edit_char) >127) then
if Length (chars) >1 then
begin
Text:=copy (text,2,edit_length-2) + Chars
Chars:= ';
End
Else
begin
Chars:=copy (text,1,2),
Text:=copy (text,2,edit_length-1);
End
Else
Begin
Text:=copy (text,2,edit_length-1) +edit_char
end;
Update;
Sleep (M);
End;
Procedure Register;
Begin
Registercomponents (' Samples ', [l_tedit1]);
End;
End.
Save the file again.

Start image Editor Create L_EDIT.DCR, select new->bitmap, make an icon yourself, save named L_tedit1 (with the new name). Note that L_EDIT.DCR and L_edit.pas are in the same directory (the default is the \delphi\lib directory). And then click Install Component. Select into the new Package property page, fill in the path and file name of L_edit.pas, and create a new L_EDIT1.DPK file under that path. then click OK. At this time we can see the Delphi Toolbar sample one of the icon you created.

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.