1. Definitions and naming Delphi variables

1 , the definition of variables

      WHERE

            Variable name: variable type;

     Example: Var

             sex: string; ( colon and semicolon are in English input )

   Define multiple variables of the same type

        WHERE

            Variable name 1 , variable name 2 , the variable name 3 : variable type;

      Example: Var

             sex,taste,grade:string;

2 , variable naming

     ( 1 ) The first character must be in English.

     ( 2 ) can only consist of letters, numbers, and underscores.

 

Example: production of radio buttons and check buttons

unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;
type
  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    GroupBox1: TGroupBox;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    CheckBox3: TCheckBox;
    CheckBox4: TCheckBox;
    CheckBox5: TCheckBox;
    CheckBox6: TCheckBox;
    RadioGroup1: TRadioGroup;
    Button1: TButton;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
    procedure RadioButton2Click(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure RadioGroup1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
  sex,taste,grade:string;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
 showmessage('您的姓名是:'+ Edit1.Text + # 13 # 10 + ' your gender: ' + Sex + # 13 # 10 + ' s your hobby: ' + Taste + # 13 # 10 + ' Your score is: ' + Grade);
 End ;
 Procedure TForm1.RadioButton2Click (Sender: TObject);
 the begin IF   radiobutton2.Checked   the then 
         Sex: = ' M ' the else IF   radiobutton1.Checked   the then 
         Sex: = ' female
              
              
              

   ' ;
end;
procedure TForm1.CheckBox1Click(Sender: TObject);
begin
       taste:='';
       if checkbox1.Checked then
          if taste='' then
            taste:=checkbox1.Caption
            else
            taste:=taste+''+checkbox1.Caption ;
       if checkbox2.Checked then
          if taste='' then
            taste:=checkbox2.Caption
            else
            taste:=taste+''+checkbox2.Caption ;
       if checkbox3.Checked then
          if taste='' then
            taste:=checkbox3.Caption
            else
            taste:=taste+''+checkbox3.Caption ;
       if checkbox4.Checked then
          if taste='' then
            taste:=checkbox4.Caption
            else
            taste:=taste+''+checkbox4.Caption ;
        if checkbox5.Checked then
          if taste='' then
            taste:=checkbox5.Caption
            else
            taste:=taste+''+checkbox5.Caption ;
        if checkbox6.Checked then
          if taste='' then
            taste:=checkbox6.Caption
            else
            taste:=taste+''+checkbox6.Caption ;
end;
procedure TForm1.RadioGroup1Click(Sender: TObject); 
begin
     case radiogroup1.ItemIndex of
      0:grade:='';
      1:grade:='';
      2:grade:='';
      3:grade:='';
      end;
end;
end.

 

Guess you like

Origin www.cnblogs.com/jijm123/p/12630113.html