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.
好的代码像粥一样,都是用时间熬出来的
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期
· 全程使用 AI 从 0 到 1 写了个小工具
· 从文本到图像:SSE 如何助力 AI 内容实时呈现?(Typescript篇)
2019-04-04 SQL Server 只安装客户端的方法
2019-04-04 116记账保存批号,库存的过程
2019-04-04 Delphi中带缓存的数据更新技术