MODULE Showcase17; // Session showcase: Clarion CLASS lowering, CHAR-array string // concatenation, and ISO ConvResults. // // A Bounded counter class (single inheritance from Counter) is driven // through its hidden THIS receiver; a value is parsed with the // ConvResults API, and a label is built by CHAR-array concatenation // for the output line. // Expected ExitCode: 42. IMPORT TextIO, Conversions; FROM Conversions IMPORT strAllRight, strWrongFormat, strOutOfRange; TYPE CLASS Counter; total : INTEGER; PROCEDURE Bump(by : INTEGER); PROCEDURE Value() : INTEGER; END Counter; CLASS Bounded (Counter); (* single inheritance *) limit : INTEGER; PROCEDURE SetLimit(v : INTEGER); PROCEDURE Over() : BOOLEAN; END Bounded; CLASS IMPLEMENTATION Counter; PROCEDURE Bump(by : INTEGER); BEGIN total := total + by END Bump; PROCEDURE Value() : INTEGER; BEGIN RETURN total END Value; END Counter; CLASS IMPLEMENTATION Bounded; PROCEDURE SetLimit(v : INTEGER); BEGIN limit := v END SetLimit; PROCEDURE Over() : BOOLEAN; BEGIN RETURN total > limit END Over; END Bounded; VAR ExitCode : INTEGER; VAR c : Bounded; VAR n : INTEGER; VAR label : ARRAY [0 .. 31] OF CHAR; VAR msg : ARRAY [0 .. 63] OF CHAR; VAR r : Conversions.ConvResults; BEGIN ExitCode := 0; (* class methods: own + inherited, through the receiver *) c.SetLimit(100); c.Bump(15); c.Bump(27); (* total = 42 *) IF c.Value() = 42 THEN ExitCode := ExitCode + 1 ELSE ExitCode := 100 END; IF NOT c.Over() THEN ExitCode := ExitCode + 2 ELSE ExitCode := 100 END; (* ISO ConvResults *) r := Conversions.StrToInt("-42", n); IF (r = strAllRight) AND (n = -42) THEN ExitCode := ExitCode + 4 ELSE ExitCode := 100 END; r := Conversions.StrToInt("nope", n); IF r = strWrongFormat THEN ExitCode := ExitCode + 8 ELSE ExitCode := 100 END; r := Conversions.StrToInt("99999999999", n); IF r = strOutOfRange THEN ExitCode := ExitCode + 16 ELSE ExitCode := 100 END; (* CHAR-array concatenation *) Conversions.IntToStr(c.Value(), label); msg := "showcase17 total=" + label; TextIO.WriteString(msg); TextIO.WriteLn; IF ExitCode = 31 THEN ExitCode := c.Value() END (* 42 *) END Showcase17.