Tag Archives: Clarion#

New Clarion language features

Some exciting new features in the Clarion language will be introduced in the next build for C11: Reference variables of Procedure types are supported by the compiler, and corresponding support is added to the linker and RTL.

Declaration of a Procedure reference

A reference variable of a procedural type is declared as follows:

Ref &<procedure label>

where <procedure label> is the label of a previously declared Procedure, a parameter of procedural type, or the label of a method in a CLASS or INTERFACE. If there is more than one Procedure or Class/Interface method with the label (for example, a class method is overloaded), or there is a data declaration with the same label in the current scope/context, the compiler returns an error.

A previous MAP structure must contain the corresponding Procedure type declaration to allow references to a Class or Interface method:

  MAP 
    MethodNameType  PROCEDURE (*ClassId, <other parameters>),...,TYPE       
  END

Ref   &MethodNameType

We’re also considering a possible extension in the future is to allow the <procedure label> to include the Class or Interface identifier as part of the declaration, for example:
Ref &ClassId.MethodName

2. Procedure Reference assignments

The reference assignment to a reference variable of procedural type has the same form as for any other reference assignment:

RefVar &= <source>

For reference assignments to reference variables of procedural types the right-hand side can be any one of the following:

1) NULL
2) an expression where the value can be converted to a LONG type
3) the label of a reference variable of procedural type
4) the label of a parameter of procedural type
5) the label of a Procedure declared in a MAP structure
6) the label of a Class method

For (3),(4) and (5) the profile of a Procedure, or a procedural type on the right hand side must be exactly the same as the profile of the procedural type used in the declaration of the reference variable on the left hand side:

meaning it must match the number of, the types of parameters, the return type, and the calling convention. (or both sides can have no return type)

For (6) if the method label on the right side is overloaded, the compiler tries to find the method with the most suitable profile. In this case “suitable” means that the first parameter (class type) on the right side can also be of a type which is a descendant
of the class type of the first parameter in the profile of the reference variable’s type. All other parameters, their order, return type, and the calling convention must be exactly the same.

The identifier on the right side can include:

  • the label of an instance of a class type, or the label of an interface
  • the label of a reference variable assigned to a class type
  • the label of a reference variable assigned to an interface type
  • the SELF or PARENT keywords
  • the label of a Class type

For example:

CType    CLASS,TYPE
M          PROCEDURE (LONG),LONG,PASCAL,VIRTUAL
         END

         MAP
PType     PROCEDURE (*CType, LONG),LONG,PASCAL
         END

R1       &PType
R2       &MESSAGE  ! the MESSAGE - built-in function
RC       &CType
AClass   CType

  CODE

  RC &= AClass
  R1 &= NULL
  R1 &= AClass.M
  R1 &= RC.M
  R1 &= CType.M
  R2 &= 0 + SYSTEM {PROP:MessageHook}

3. Reference equality operator

The reference equality operator for the reference variable of a procedural type has the same form as for any other reference variables:

Ref &= <right side>

If the left side of the reference equality operator is a reference variable of procedural type,
the <right side> can be of any form as the <source> described above in the “Procedure Reference Assignments” section.

There is one exception for this: if the <right side> is a label of a Class/Interface method, and this label is overloaded, the compiler reports an error; “Error: Ambiguous reference type“, rather than trying to choose the intended matching variation of the method.

4. Usage

A Reference variable of a procedural type can be used in any context where procedures/functions with the same profiles are valid:

  • call statements
  • a parameter of a procedural type
  • the Sort function parameter in QUEUE statements ADD, GET, PUT and SORT
  • as a parameter of the ADDRESS function
  • as a parameter of the BIND statement

Probably the most typical variations of usage for procedural type references are:

  • Calling DLL functions from addresses returned by the Windows API’s GetProcAddress function
  • SYSTEM hooks properties are no longer write-only in the upcoming RTL release. The result of getting these properties are RTL internal functions implementing corresponding statements:
    MESSAGE, COLORDIALOG, FONTDIALOG and other standard dialogs,
    OPEN for Windows and Reports, CLOSE for Windows and Reports, changing SYSTEM properties, etc.

    This means your program can retrieve the RTL’s hook function and replace it with your own function, which calls the original RTL code internally
  • Simulation of virtual functions in cases where the actual function can be changed at run time.

5. Some General info

  • Reference variables of procedural type can be declared as a field in GROUP/QUEUE/CLASS declarations
  • The DIM attribute is currently invalid for declarations of reference variables, and that same rule applies for reference variables of procedural types.
  • The ADDRESS function supports Class type labels in the identifiers of methods passed as parameters, for example, using the declarations from the example above the following expression:

    ADDRESS (CType.M)

    is valid in the upcoming release.

The new language enhancements can be likened to a pointer-to-method, and reference-to-method in C++. But in C++ a special syntax is used to allow the compiler and linker to handle these language constructs properly. No special syntax is required in Clarion.


TYPEd Class Methods

Another powerful language enhancement available in the upcoming release is support for TYPEd Class methods. I’ll be making a separate post on typed Class methods with an example of usage.

Clarion Community Edition

Over the next days I’ll be sharing news about announcements we made at the conference (CIDC 2019).

As the title suggest we are introducing a new, and totally free, Clarion Community Edition. Here are the details:

  • It’s not a Trial version (it never expires)
  • Database Drivers:
    • SQLite, Dos, Ascii, Basic
  • Templates: Both ABC and Clarion chains
  • The only limitations are:
    • No ability to add any additional database drivers
    • No ability to register any additional Templates

This is a great opportunity for members of the Clarion community to get fellow developers who are using other tools to try out Clarion. If every Clarion dev could get ONE new developer to get a copy, we can double the size of the community! Also, if you are a Clarion developer who is using an older version of Clarion this is your opportunity to see what you’ve been missing out on.

We’ll also be making a free training course available on one of the online learning platforms. The course will be designed to teach the essentials of Clarion; both the IDE (Data Dictionary, AppGen, using embeds, and much more.) as well as the language itself.

We expect to release the new edition late October, or early November.

.Net Application Generator

In this post I’ll try to provide a complete overview and our best estimate on when you’ll have this new technology in your own hands. Diego Borojovich is leading the team working on the new .Net Application Generator (AppGen.Net), and if you have attended any DevCon events over these last years then you probably have met Diego. He’s been working with Clarion for over 16 years, and joined the SoftVelocity development team 8 years ago. You’ll be hearing a lot more from Diego in blog posts in the upcoming weeks as he talks in-depth about the new AppGen.Net, the template language, and how the new code generation/template system works.

Let’s start from the top; the Code Generation engine in AppGen.Net is completely new. It has its architectural and conceptual roots in the Clarion Win32 AppGen, and that technology is blended with the functionality found in the Text Template Transformation Toolkit (T4).

The template language used in the new AppGen.Net is a complete departure from the syntax used by the templates in our Win32 Application Generator.  It uses an extended set of the T4 template directives. It’s very easy to work with the template code and templates can be used in any type of project (WinForm, WebForm, CompactForms, Web Services, etc.). And just like with our Win32 AppGen you can write templates to create any type of output that you need – CLN, CS, ASPX, HTML, SQL, XML, or anything else you need.

The syntax for the new templates is similar to what you see in an ASP.NET .ASPX source file – here’s a small snippet so that you get a feel for what it looks like:

<#@ template language=”C#” debug=”true” type=”ProcedureExtension” name = “DescriptionOutput” family = “Clarion.Linq”#>
<#@ assembly name=”mscorlib.dll” #>
<#@ assembly name=”System.dll” #>
<#@ import namespace=”System” #>
<#@ import namespace=”SoftVelocity.TextTemplating” #>
<#@ property processor=”PropertyProcessor” name=”MyDescription” type=”System.String” defaultValue=”None”#>
<#%+ CustomGlobalData priority = “1000”#>

I already mentioned that the AppGen.Net template system supports an extended set of the T4 template directives, these extended directives include equivalence for our #PROCEDURE, #CODE, #GROUP, #CONTROL, #EMBED and #AT and #EXTENSION directives as found in our Win32 template system. And you may have noticed in the first line of the template snippet where it reads “template language=C#”? In the first release, all the templates are coded in C#, but in a future release we plan to let you use any .Net language to write your own templates. The templates themselves can utilize the entire .Net Framework, including any 3rd party components, and that gives us (and you) incredible power and flexibility in the template system; meaning there are really no limits to what you can do in a template (outside of is your own imagination). If you plan on writing templates you’ll be glad to know that inside the IDE we already have T4 syntax highlighting in the editor, and in the near future we’ll be adding code completion support.

The template system has the concept of a template registry, just as we have now. But with AppGen.Net when templates are registered into the IDE they are automatically compiled into a binary assembly. Compiling the templates provides for faster code generation, immediate detection of syntax errors, and makes it easy to share templates within a team.

In the initial public release the generated data access layer will let you select from two data access frameworks; LINQ to File, and LINQ to SQL.  (It’s possible that we will also provide a template set for generating a plain ADO.NET data access)

What is LINQ to FILE?

LINQ to FILE utilizes our own LINQ provider that encapsulates an ABC-styled framework — using LINQ syntax for accessing and updating data via our underlying File Driver technology. The LINQ to FILE provider maintains referential integrity and also handles auto incrementing of keys. The LINQ to File data access layer can also utilize our managed .Net IP driver. If you’re not already familiar with LINQ syntax here is a simple example of the syntax used for retrieving data:

query? = from class in ClassesQuery    |
where class.RoomNumber < 10   |
select class

This LINQ query will retrieve all records where the column RoomNumber is less then 10, it’s really that simple. And using a LINQ query with a Where clause instead of filtering records in a Loop provides a noticeable increase in performance. Using the LINQ to File lets us work with powerful SQL-like query and update capabilities, working with all of our FILE Drivers, and integrated into the LINQ to FILE provider is functionality essentially equivalent to that in our existing ABC framework.

What Is LINQ to SQL?

LINQ to SQL is itself a light-weight ORM (object relational mapping) implementation that ships as part of .NET 3.5, that allows you to model a relational database using .NET classes.  You can then query the database using LINQ, as well as update/insert/delete data from it. LINQ to SQL supports transactions, views, and stored procedures.  The templates provide an easy way to integrate data validation and business logic rules directly into your data model.

In addition to the two LINQ frameworks we plan to add template support for working with several additional technologies for the data access layer;  options for data access will look like this:

•    LINQtoFile
•    LINQtoSQL
•    ASP.NET MVC
•    NHibernate
•    CSLA
•    ADO.Net

We also plan to have templates for supporting these technologies:

•    Windows Communication Foundation (WCF) is the .Net programming model for building service-oriented applications.
•    Web Services (for exchanging data)

And I should mention that we’re providing template sets to support the three target platforms; Winforms (desktop), WebForms (Web) and Compact Forms (Mobile devices). The templates being developed for .Net offer code generation in 2 language flavors C# and Clarion#, and eventually we’ll add VB to the list.

I want to mention a few things about the user interface generated by the templates. These are options that the templates will provide for the user interface layer:

•    Winforms (using the standard .Net Framework controls, or a designated 3rd party component set)
•    CompactForms (using the standard .Net Framework controls, or a designated 3rd party component set)
•    Webforms (using the standard .Net Framework controls, designated 3rd party component set, Ajax Library, and in the future Silverlight)
•    WPF – Windows Presentation Foundation: (using the standard .Net Framework controls, or a designated 3rd party component set)
(The WPF support will come after the initial release, and although we don’t presently have a full-blown designer, we will have UI edit capabilities, and of course you can use many different external tools to create and work on the UI as the code is completely separate from the other layers)

For creation of the UI the templates read the control settings from the Dictionary, just as we do now in the Win32 AppGen, but we plan to provide (as a configuration option) the ability to specify that the templates use an external file for control mappings, and in this file we’ll store the fully-qualified name of the control, along with its properties (i.e. font, width, height, etc.). The controls specified in the config file will map back to the controls supported in the templates for generating the UI. This feature means that you can specify the use of 3rd party components and the Template Wizards will generate the UI using those controls and properties.

Here are a few miscellaneous new features that are worthy of mention which are planned to be introduced with the new AppGen.Net:

•    Option to generate test cases (nUnit) for aspects of the APP
•    Ability to attach developer documentation/working notes directly into the .APP and/or to individual procedures

And something else exciting is coming up; we are happy to announce that the templates to power these technologies will be made part of an open collaborative community project so that anyone interested can participate in their ongoing development. This collaborative project will contain all of the new Clarion templates and sample Apps.

And this project is not just for the new .Net templates, we’ll be adding all of our Clarion templates (Win32 and .Net), as well as new example Apps. With this project the Clarion community will always have access to the very latest updates, as well as contribute patches, and add new templates and sample Apps.

Now the question at hand is when will you get it?  We have had to revise our earlier estimates to allow extra time for some of the integration tasks in our switch over to the new AppGen.Net, and the revised estimate for delivering a full beta is now about 5-6 weeks from today, putting it into a late-May early-June time frame. However, it is very likely that we’ll release the new AppGen.Net with some reduced template support before that. That first early release will support generation of code targeted at the data access layer, in other words it will be without the tie-in with the Designers. And that release also will likely include Application and Procedure Wizard functionality. So that first release will provide a big increase in productivity in two areas, and it’ll also allow those who are interested, to start working on the template code itself. Very importantly it’ll also let us get feedback from you on the AppGen.Net UI itself, which is very valuable to us all.