1、Delphi 變量的定義及命名


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.

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM