Delphi realizes led Digital tube simulation display Program

Source: Internet
Author: User

Widely used in electronic equipment led digital display data, in many applications also often analog LED digital tube display data, so that the program screen looks very distinctive. Using the Delphi program to realize the simulation of LED digital tube is very easy, the specific steps are as follows:

1. Start Delphi 4.0. In the Tools Tool menu, select the Delphi Image Editor "Image Editor", create a new bitmap, and set the size of the location map, Width: 48, height is: 64. The background color of the positioning chart is purplish red and the foreground colour is red. Select the appropriate width of the line on the bitmap to draw a square of 8 words, and the square type of 8 words each corner of the diagonal break, so that the image simulation more realistic. Bitmap_0.bmp Storage by file name when finished. Then use this file to copy 9 files, the file name is bitmap_1-9. Using the Image editor, these square 8-character bitmaps are modified to 0-9 digital bitmaps in the order of the filename ordinal, and are stored for standby.

2. Create a new project, add the Panel component Panel1 on the form Form1, and set the properties of the Panel component: bevelouter=bmraised; bvevelinner=bvlowered; Borderwidth=4, set to form a raised border on the Panel1 component. Add an "artboard" component PaintBox1 on the Panel1, set the PaintBox1 properties hight and width to 64 and 318, and adjust the PANEL1 panel size appropriately to enclose the artboard component exactly.

3. Add an image list component ImageList1 to the form. Double-click on the component, pull up the Add Image dialog box, the previously produced bitmap bitmap_0 to Bitmap_9 sequentially added to the image list components, so that the image list of the bitmap number and the bitmap itself represents the same numbers , and note that you set the bitmap to opaque.

4. Go to the Cell editing window and add a procedure description statement that displays the LEDs in the class description section of Tform1:

Procedure display_led (Number:integer);.

Add a global variable below the implementation statement and the process body that corresponds to the procedure described above. The contents are as follows:

implementation
{$R *.DFM}
var
 dis_number:integer;
procedure Tform1.display_LED(number:integer);
var
 I:integer;
 digital:array[0..5]of integer;
begin
 {限制显示位数小于6位}
 if number>999999 then number:=0;
 for I:=0 to 5 do digital[I]:=0;
 {分离数字位}
 I:=0;
 while (number)>0 do
 begin
  digital[I]:=number mod 10;
  number:=number div 10;
  I:=I+1;
 end;
 {显示数字}
for I:=5 downto 0 do
  imagelist1.draw(paintbox1.canvas, (5-I)*54,0,digital[I]);
end;

5. Enter the statement in the Oncreated event of the Form1 form: dis_number:=0; So that the initial value shown is 0. Enter the statement in the on Paint event of the artboard component: display_led (Dis_number); , this statement is important to display initial value 0 at initial startup, and still display normal values when the window itself is overwritten and restored to the foreground. This completes the programming of the display function. Calling the Display_led function in a program that needs to display a number can display the number on the LED's emulated display panel. This example program displays only 6 digits below.

6. To test the display, we add an edit box component Edit1 to the form, and a button symbol button1. Double-click the button symbol to jump to the Click event Edit window and enter the following statement:

  dis_number:=strTOint(Edit1.text);
  display_LED(dis_number);

When you are done, press F9 to compile and run the program. In the edit box of the Run window, enter an integer number below 6 digits, click the button, and the number in the edit box is displayed on the LED simulation display panel.

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.