• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

1、Delphi变量的定义及命名

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

1、变量的定义

      VAR

            变量名:变量类型;

     例:var

             sex:string;      (冒号与分号都是英文输入)

   同类型的多个变量的定义

        VAR

            变量名1,变量名2,变量名3:变量类型;

      例:var

             sex,taste,grade:string;

2、变量的命名

     1)首字符必须是英文。

     2)只能由英文、数字和下划线组成。

 

例:制作单选按钮和复选按钮

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+
              '你的性别是:'+sex+#13#10+
              '你的爱好是:'+taste+#13#10+
              '你的成绩是:'+grade );
end;
procedure TForm1.RadioButton2Click(Sender: TObject);
begin
if  radiobutton2.Checked  then
         sex:=''
  else if  radiobutton1.Checked  then
         sex:='' ;
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.

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap