Extensive DEMO code of Delphi

Source: Internet
Author: User

Code file:
--------------------------------------------------------------------------------
 
Unit unit1;

Interface

Uses
Windows, messages, sysutils, variants, classes, graphics, controls, forms,
Dialogs, stdctrls;

Type
Tform1 = Class (tform)
Memo1: tmemo;
Button1: tbutton;
Button2: tbutton;
Button3: tbutton;
Button4: tbutton;
Button5: tbutton;
Procedure button1click (Sender: tobject );
Procedure button2click (Sender: tobject );
Procedure button3click (Sender: tobject );
Procedure Button4Click (Sender: TObject );
Procedure Button5Click (Sender: TObject );
End;

Var
Form1: TForm1;

Implementation

{$ R *. dfm}

Type
TArr <T> = array [0 .. 9] of T; {defines a Generic array}
{Although T is used to refer to other types, other valid identifiers are also supported}

{Used as Integer}
Procedure TForm1.Button1Click (Sender: TObject );
Var
Arr: TArr <Integer>;
I: Integer;
Begin
For I: = Low (Arr) to High (Arr) do
Arr [I]: = I * I;

Memo1.Clear;
For I: = Low (Arr) to High (Arr) do
Memo1.Lines. Add (Format ('Arr [% d] = % d', [I, Arr [I]);
End;

{Used as string}
Procedure TForm1.Button2Click (Sender: TObject );
Var
Arr: TArr <string>;
I: Integer;
Begin
For I: = Low (Arr) to High (Arr) do
Arr [I]: = StringOfChar (Char (I + 97), 3 );

Memo1.Clear;
For I: = Low (Arr) to High (Arr) do
Memo1.Lines. Add (Format ('Arr [% d] = % s', [I, Arr [I]);
End;

{Used as Single}
Procedure TForm1.Button3Click (Sender: TObject );
Var
Arr: TArr <Single>;
I: Integer;
Begin
For I: = Low (Arr) to High (Arr) do
Arr [I]: = 100/(I + 1 );

Memo1.Clear;
For I: = Low (Arr) to High (Arr) do
Memo1.Lines. Add (Format ('Arr [% d] = % F', [I, Arr [I]);
End;

{Used as record TPoint}
Procedure TForm1.Button4Click (Sender: TObject );
Var
Arr: TArr <TPoint>;
I: Integer;
Begin
For I: = Low (Arr) to High (Arr) do
Arr [I]: = Point (I, I * 2 );

Memo1.Clear;
For I: = Low (Arr) to High (Arr) do
Memo1.Lines. add (Format ('Arr [% d] = (% d, % d) ', [I, Arr [I]. x, Arr [I]. y]);
End;

{Used as a class TButton}
Procedure TForm1.Button5Click (Sender: TObject );
Var
Arr: TArr <TButton>;
I: Integer;
Begin
For I: = Low (Arr) to High (Arr) do
Begin
Arr [I]: = TButton. Create (Self );
Arr [I]. Name: = Concat ('btn ', IntToStr (I + 1 ));
End;

Memo1.Clear;
For I: = Low (Arr) to High (Arr) do
Memo1.Lines. Add (Format ('Arr [% d] is % s', [I, Arr [I]. Name]);

For I: = Low (Arr) to High (Arr) do Arr [I]. Free;
End;

End.
--------------------------------------------------------------------------------
Form file:
--------------------------------------------------------------------------------
 
Object Form1: TForm1
Left = 0
Top = 0
Caption = 'form1'
ClientHeight = 1, 158
ClientWidth = 232
Color = clBtnFace
Font. Charset = DEFAULT_CHARSET
Font. Color = clWindowText
Font. Height =-11
Font. Name = 'tahoma'
Font. Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
Object Button1: TButton
Left = 1, 136
Top = 6
Width = 75
Height = 25
Caption = 'button1'
TabOrder = 0
OnClick = Button1Click
End
Object Memo1: TMemo
Left = 0
Top = 0
Width = 113
Height = 158
Align = alLeft
Lines. Strings = (
'Mo1 ')
ScrollBars = ssVertical
TabOrder = 1
ExplicitHeight = 167
End
Object Button2: TButton
Left = 1, 136
Top = 36
Width = 75
Height = 25
Caption = 'button2'
TabOrder = 2
OnClick = Button2Click
End
Object Button3: TButton
Left = 1, 136
Top = 66
Width = 75
Height = 25
Caption = 'button3'
Taborder = 3
Onclick = button3click
End
Object button4: tbutton
Left = 1, 136
Top = 96
Width = 75
Height = 25
Caption = 'button4'
Taborder = 4
Onclick = button4click
End
Object button5: tbutton
Left = 1, 136
Maximum = 126
Width = 75
Height = 25
Caption = 'button5'
TabOrder = 5
OnClick = Button5Click
End
End

Source code download: http://www.rayfile.com/files/f5fd6dde-1621-11df-a3e2-0015c55db73d/

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.