Clarion (programming Language) - Hello World

Hello World

The simplest way to achieve this is with the built in message function that is similar to the windows MsgBox.

PROGRAM CODE MESSAGE('Hello World!','Clarion') RETURN

Here is another, requiring only a minimum of code. This example opens a window in the program and use ACCEPT to handle the events.

PROGRAM Window WINDOW('Clarion'),AT(,,124,72),GRAY STRING('Hello World'),AT(21,26),USE(?String1) BUTTON('Close'),AT(76,53,45,14),USE(?Button1),STD(STD:Close) END Code Open(Window) Accept End RETURN

A more real world example uses a Clarion structure to declare a window and the Clarion Accept loop to process events from that window.

PROGRAM ! Declares this is a main program procedure MAP ! Determines which procedures will be called HelloProcedure ! This is a procedure HelloFunction,STRING ! This is a function, that returns a string ArgumentFunction( LONG pArg ),STRING ! This is a function that receives an argument END CODE HelloProcedure ! Executes the procedure MESSAGE( HelloFunction ) ! Executes the function, as an argument to the MESSAGE MESSAGE( ArgumentFunction( 4 ) ) ! The MESSAGE is an internal function, a message dialog RETURN ! Explicitly ends the program HelloFunction PROCEDURE ! The compiler spots the difference, based on the MAP CODE RETURN 'Hello, World!' ! This is how one returns a value ArgumentFunction PROCEDURE( LONG pArg ) CODE RETURN pArg * 2 ! Clarion does automatic type conversion HelloProcedure PROCEDURE Window WINDOW('Clarion for Windows'),AT(,,222,116), | FONT('Tahoma',8,,FONT:regular),ICON('Hey.ICO'),SYSTEM,GRAY STRING('Hello World!'),AT(91,22),USE(?String1) BUTTON('Close'),AT(92,78,37,14),USE(?CloseBtn) END CODE ! Marks the beginning of executable code OPEN( Window ) ! Opens the Window structure ACCEPT ! Main keyboard/mouse reading loop CASE EVENT ! Any event was raised? OF EVENT:OpenWindow ! Window is open and displayed OF EVENT:CloseWindow ! Window is about to be closed OF EVENT:Accepted ! Was it a control being accepted? CASE FIELD ! If so, which control generated the event? OF ?CloseBtn ! the Close button generated that BREAK ! We just need to break the accept loop END ! End the control test branch END ! End the event test branch END ! End of the accept loop CLOSE(Window) RETURN

Here is another example implementing a simple class to demonstrate Hello World, it was converted from the similar Delphi Wiki example.

PROGRAM HelloClassType CLASS,TYPE CONSTRUCT PROCEDURE DESTRUCT PROCEDURE Run PROCEDURE HelloText STRING(80) END CHello &HelloClassType !Reference to class CODE CHello &= NEW HelloClassType CHello.HelloText = 'Hey You Dudes!' CHello.Run DISPOSE(CHello) RETURN HelloClassType.CONSTRUCT PROCEDURE !Class Constructor, fires on New CODE SELF.HelloText='Hello World' RETURN HelloClassType.DESTRUCT PROCEDURE !Class Destructor CODE RETURN HelloClassType.Run PROCEDURE Window WINDOW('Clarion'),AT(,,124,72),GRAY STRING,AT(21,1,124,10),USE(?String1),CENTER BUTTON('Close'),AT(76,53,45,14),USE(?Button1),STD(STD:Close) END CODE Open(Window) ?String1{PROP:Text} = SELF.HelloText Accept End RETURN

As mentioned, Clarion is Template driven when using the "AppGen". This means that the AppGen uses templates to "form" the generated application. The template presents choices to the developer so the developer are able to modify the generated code. The generated code is as said - not editable - but it has points in code where the developer can change behaviour, still being able to rerun the generator.

An example of the template code:

#CODE(ShowMessageBox, 'Show a MessageBox to the user') #PROMPT('Message to show:', @s255), %TheMessageToShow !Code Generated by the template #EMBED(%EmbedPointBefore, 'The Developer can add code before the Message appears') Message(%TheMessageToShow) #EMBED(%EmbedPointAfter, 'The Developer can add code after the Message has been shown')

Example Loop Array Code:

Clear(VAR:Record) VAR:CodScript = SCR:CodScript Set(VAR:KCodigoScript,VAR:KCodigoScript) Loop Until Access:Variaveis.Next If VAR:CodScript = SCR:CodScript Sp# = 1 If Upper(VAR:Busca) <> Upper(VAR:Troca) Loop L# = Instring(Upper(VAR:Busca),Upper(Loc:Script),1,1) If Not L# Break End Loc:Script = Sub(Loc:Script,1,L#-1) & VAR:Troca & Sub(Loc:Script,L#+LEN(VAR:Busca),Len(Loc:Script)) R# += 1 Sp# = L#+LEN(VAR:Busca)+1 End End !message(Clip(Loc:Script) &' '& R# &' '& SP# &' '& L#) Else Break End End Loc:Script = Clip(Loc:Script)



Read more about this topic:  Clarion (programming Language)

Famous quotes containing the word world:

    The world has held great Heroes,
    As history books have showed;
    But never a name to go down to fame
    Compared with that of Toad!
    Kenneth Grahame (1859–1932)

    You can’t put fourteen hundred people out of work because the world has a stomach ache.
    Fredric M. Frank (1911–1977)