欢迎来到天天文库
浏览记录
ID:15157279
大小:43.50 KB
页数:19页
时间:2018-08-01
《第二章 delphi面向对象的编程方法(三)(the second chapter is delphi object-oriented programming method (three))》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、第二章delphi面向对象的编程方法(三)(ThesecondchapterisDelphiobject-orientedprogrammingmethod(three))Thestatementsectionofthe2.1.8.4procedureandfunctionThestatementofaprocedureorfunctionstartswithbeginandendswithend.Thefunctionneedsareturnvalue.Youcanassignthereturnvaluetothefunctionna
2、me,oryoucanassignthereturnvaluetotheResultvariable.Thefollowingroutineassignsthereturnvaluetothefunctionname:FunctionCalculateInterest(Principal,InterestRate:,Double):Double;BeginCalculateInterest:=Principal*InterestRate;End;ItisalsopossibletoassignthereturnvaluetotheRes
3、ultvariable,andthentheaboveprogramchangesto:Result:=Principal*InterestRate;Hereisacalltothisfunction:InterestEarned:=CalculateInterest(2000,0.012);TheprocessesandfunctionsbehindtheImplementationcanandcanonlybeusedbytheeventhandlingofthislibraryelement.Tomaketheprocessand
4、functioncanbeusedinotherlibraryunit,youwillneedtheinterfacepartofthetitlesectionoftheprocedureorfunctiononthebaseunit,andthewholeprocessorfunctionwithtitleintheinplementationpartofthelibraryunit,andtheusesclauseinthelibraryunittoaccesstheprocessorfunctionofaddedtothedesc
5、riptionoftheprocessorfunctionofthebaseunit.Recursivecalltothe2.1.8.5functionInObjectPascal,theprocedureorfunctionmustfirstexplainandthencall.TheNoValuefunctionabovemustbeexplainedandexecutedbeforetheeventhandlerusingit,otherwisetheprogramwillreportanerrorwithanunknownide
6、ntifier.Theaboverulesareexceptionswhenrecursivecallsaremade.RecursivecallmeansthatthefunctionAcallsthefunctionB,andthefunctionBcallsthefunctionA.Inrecursivecalls,thefunctiontakesprecedence,i.e.,thelastwordinthetitleofthefunctionorprocessisaddedtothereservedword"forword".
7、Thefollowingroutineisatypicalexampleofarecursivecall:...ImplementationVarAlpha:Integer;ProcedureTest2(VaRA:Integer):forword;{Test2isdescribedasapreprocess}ProcedureTest1(VaRA:Integer);BeginA:=A-1;IfA>0thenTest2(A);{callTest2}thathasnotbeenexecutedbypredeclarationWriteln(
8、A);End;ProcedureTest2(VaRA:Integer);{}theexecutionpartoftheprespecifiedTest2}BeginA:=Adiv2;IfA>0rhenTes
此文档下载收益归作者所有