正在加载图片...
654 GLOBAL OBJECTS AND CONSTANTS $18.6 Message:STRING is --String of length 12,with successive characters --S,y,n,t,a,x,,e,r,r,o,r once !Result.make (12) Result.put ('S,1) Result.put (y,2) Result.put ('r,12) end The creation procedure for strings takes as argument the initial expected length of the string;put (c,i)replaces the i-th character with c. Such string values are therefore not constants but references to shared objects.Any class that has access to Message may change the value of one or more of its characters. You can also use string constants as expressions,for argument passing or assignment: Message window.display ("CLICK LEFT BUTTON TO CONFIRM EXIT") greeting :"Hello!" 18.6 UNIQUE VALUES It is sometimes necessary to define an entity that has several possible values denoting possible cases.For example a read operation may produce a status code whose possible values are codes meaning“successful'",“error on opening”and“error on reading”. A simple solution is to use a variable integer attribute code:INTEGER with a set of associated integer constants,such as U1] Successful:INTEGER is I Open error:INTEGER is 2 Read error:INTEGER is 3 so that you can write conditional instructions of the form U2] if code Successful then .. or multi-branch instructions of the form See“fulti--branch', [U3] page 449. inspect code when Successful then when .. end654 GLOBAL OBJECTS AND CONSTANTS §18.6 Message: STRING is -- String of length 12, with successive characters -- S, y, n, t, a, x, , e, r, r, o, r once !! Result ● make (12) Result ● put ('S', 1) Result ● put ('y', 2) … Result ● put ('r', 12) end The creation procedure for strings takes as argument the initial expected length of the string; put (c, i) replaces the i-th character with c. Such string values are therefore not constants but references to shared objects. Any class that has access to Message may change the value of one or more of its characters. You can also use string constants as expressions, for argument passing or assignment: Message_window ● display ("CLICK LEFT BUTTON TO CONFIRM EXIT") greeting := "Hello!" 18.6 UNIQUE VALUES It is sometimes necessary to define an entity that has several possible values denoting possible cases. For example a read operation may produce a status code whose possible values are codes meaning “successful”, “error on opening” and “error on reading”. A simple solution is to use a variable integer attribute code: INTEGER with a set of associated integer constants, such as [U1] Successful: INTEGER is 1 Open_error: INTEGER is 2 Read_error: INTEGER is 3 so that you can write conditional instructions of the form [U2] if code = Successful then … or multi-branch instructions of the form [U3] inspect code when Successful then … when … end See “Multi-branch”, page 449
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有