请用Delphi编写一个小程序。全部分数悬赏

请用Delphi编写一个小程序。全部分数悬赏,第1张

//加个opendialog,代码不难,应该看得明白

var

p :PChar

i,n :Integer

list :TStringList

str :string

begin

if opendialog1.execute then

begin

list := TStringList.Create

list.LoadFromFile(opendialog1.FileName)

str := list.Text

p := PChar(str)

while p^ <>#0 do

begin

case p^ of

'0'..'9':

else p^ := #32

end

Inc(p)

end

list.clear

list.Delimiter := #32

list.DelimitedText := str

n := 0

str := ''

for i := 0 to list.Count - 1 do

begin

n := n+strtoint(list.Strings[i])

if str = '' then

str := list.Strings[i]

else

str := str+'+'+list.Strings[i]

end

list.Free

showmessage(inttostr(n)+'='+str)

end

end

可以定义一个全局变量用来记录正确的数目,并在窗体创建时赋初始值:

procedure TForm1.FormCreate(Sender: TObject)

begin

i := 0

end

//随机生成数:

procedure TForm1.Button1Click(Sender: TObject)

var z,j : integer

begin

Randomize

j := random(1000)

z := random(1000)

label1.Caption := inttostr(j)

label2.Caption := inttostr(z)

end

//当按下enter键时判断答案是否正确:

procedure TForm1.Edit1KeyPress(Sender: TObjectvar Key: Char)

begin

if key = #13 then

begin

if edit1.Text =inttostr(strtoint(label1.Caption) + strtoint(label2.Caption)) then

begin

label3.Caption :='タ絋'

i := i+1

edit2.Text := inttostr(i)

end

else

label3.Caption := ''

end

end


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/12143735.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-21
下一篇 2023-05-21

发表评论

登录后才能评论

评论列表(0条)

保存