鱼C论坛

 找回密码
 立即注册
查看: 324|回复: 0

[学习笔记] 用户自定义类型3

[复制链接]
发表于 2023-8-28 18:06:17 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids;

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    Button1: TButton;
    Button2: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
type
  Fishoil=Record
  name:String;
  sex:String;
  age:Integer;
  end;

var
  i:Integer=1;

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  With StringGrid1 do
  begin
    cells[0,0]:='姓名';
    cells[1,0]:='性别';
    cells[2,0]:='年龄';
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
fishc1:Fishoil;
begin
  if i<6 then
  begin
    fishc1.name :=InputBox('昵称','请输入'+IntToStr(i)+'个账号的昵称             ','');
    fishc1.sex :=InputBox('性别','请输入'+IntToStr(i)+'个账号的性别             ','');
    fishc1.age :=StrToInt(InputBox ('年龄','请输入'+IntToStr(i)+'个账号年龄             ',''));

    With StringGrid1 do
    begin
      cells[0,i]:=fishc1.name;
      cells[1,i]:=fishc1.sex;
      cells[2,i]:=IntTOStr(fishc1.age);
    end;
    Inc(i);
  end
  Else
  ShowMessage('数据已满,请清空后重新输入');
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  i,j:Integer;
begin
  For i:=1 to 5 do
  begin
    For j:=0 to 2 do
    begin
      StringGrid1.cells[j,i]:='';
    end;
  end;
end;

end.
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-6-23 10:06

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表