[delphi]小程序一例,自动生成随机数。

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Label2: TLabel;
    Label3: TLabel;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Label4: TLabel;
    Label5: TLabel;
    edit: TEdit;
    edit2: TEdit;
    edit3: TEdit;
    Label1: TLabel;
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  sum:Integer;
  aver:Single;

implementation

{$R *.dfm}

procedure TForm1.Button2Click(Sender: TObject);
begin
  sum:=strtoint(edit.text)+strtoint(edit2.text)+strtoint(edit3.text);
  aver:=sum/3.0;
  label5.Caption:=Format('%.3f',[aver]);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  randvalue1,randvalue2,randvalue3:integer;
begin
      Randomize;
      edit.Clear;
       edit2.Clear;
       edit3.Clear;
       randvalue1:=random(9);
      if randvalue1=0 then
      randvalue1:=randvalue1+1;

      edit.text:=inttostr(randvalue1);

         randvalue2:=random(99);
          if randvalue2<=9 then
      randvalue2:=randvalue2+10;
      edit2.text:=inttostr(randvalue2);

        randvalue3:=random(999);
        if randvalue3<=99 then
     randvalue3:=randvalue3+100;
      edit3.text:=inttostr(randvalue3);

end;

procedure TForm1.Button3Click(Sender: TObject);
begin
edit.Clear;
       edit2.Clear;
       edit3.Clear;
end;

end.


注意:

autosize设为False

strtoint

edit.Clear;

Format

random

inttostr

你可能感兴趣的:(开发笔记)