Classes tutorial to create a class from scratch

Hi,
I have been programming in Clarion for the last 22 years and never created a single class (never needed to create one).

But I think it is time to expand my knowledge for this as templates and functions are covering this area so far.

So where can I find simple detailed tutorial about how to create a class from scratch.

Regards

Good, I’m also listening :slight_smile:

2 Likes

Also, check out @Bruce’s Deriving a ABC class. A good first class is to derive an ABC class, like BrowseClass or WindowManager, and make a change for some functionality you want in all of your windows.
Then using this class throughout your APPs creates this functionality for you.
http://www.mediafire.com/file/3r6ms3v25xsvsri/ClarionLive327_20150821_BruceJohnsonOnDerivingABC_Classes.wmv/file

There are lots of resources on Clarion Live about writing classes.

1 Like

thank you all

Regards

Hi,

can anybody kindly send me a complete very simple class sample which contains let’s say two or three procedures like adding, substracting or multiplying two numbers, with the project or application sample using this class (clarion 6.3 style).

I checked the video suggested and it was interesting but so many details that I lost focus (too old for follow up lectures :frowning_face:)

with lots of thanks in advance.

Regards

A very simple example, can you cut and paste from here into the appropriate places?

   PROGRAM
            
MathClass      CLASS
Add2              Procedure(LONG in1,LONG in2),LONG
Add3              Procedure(LONG in1,LONG in2,LONG In3),LONG
               .  

   MAP            
   END

   CODE
      MESSAGE('Add 1 + 2 = ' & MathClass.Add2(1,2))
      MESSAGE('Add 1 + 2 + 3 = ' & MathClass.Add3(1,2,3))
      MESSAGE('Finished')

      
MathClass.Add2 PROCEDURE(LONG in1,LONG in2)
   Code
      RETURN(in1 + in2)
              
MathClass.Add3 Procedure(LONG in1,LONG in2,LONG In3)
   Code
      RETURN(SELF.Add2(in1,in2) + in3)

Nice. that’s a good start.

Thank you

Regards

Sorry one more question; how to use the class inside the application.

I know these are basics but I never tried user made classes.

Thanks

Hi,

Take a look at excellent example that Donald Ridley made.

Regards
Johan de Klerk

It seems very good from the exe supplied, but unfortunately I did not compile with clarion 6.3

Thank you

My MathClass example shows that MathClass is defined at PROGRAM level, ie: it has GLOBAL scope, it will be visible to all procedures that follow in the main program and standard member modules.

You can use this GLOBAL instance inside any procedure without redeclaring it thus …

myFirstProc Procedure
a LONG
b LONG
x LONG
Code
 a = 1
 b = 2
 x = MathClass.Add2(a,b)

but it is more common to define a CLASS type, think of this this as what a CLASS should be “like” rather than what it “is”.
So, let’s change the previous example into a TYPE, we’ll rename it slightly to make it more obvious, and append the ,TYPE attribute to its declaration:

PROGRAM
            
MathClassType      CLASS,TYPE
Add2              Procedure(LONG in1,LONG in2),LONG
Add3              Procedure(LONG in1,LONG in2,LONG In3),LONG
               .  

   MAP            
   END

   CODE
      !-- Main program code called here

      
MathClassType.Add2 PROCEDURE(LONG in1,LONG in2)
   Code
      RETURN(in1 + in2)
              
MathClassType.Add3 Procedure(LONG in1,LONG in2,LONG In3)
   Code
      RETURN(SELF.Add2(in1,in2) + in3)

We have redefined the class and still have the methods that do something, namely add 2 or 3 numbers together, you can now declare an individual instance of this class in a procedure of your own and use it independently of other instances in other procedures, ie: it is safe, the individual instances won’t interfere with each other.

AnotherProcedure Procedure
myAdder  MathClassType
a LONG
b LONG
x LONG
  Code
    a = 1
    b = 2
    x = myAdder.Add2(a,b)

Hope that helps a bit more.

A good place to start when writing your own class is to try and find some code that you’ve used several times, have you cut and pasted between apps or procedures to reuse it, if so, that’s a prime candidate for making into a CLASS … code it once, use it many times.

Thank you for your patience.

I could run it and do changes successfully by opening a project, but did not work as an application.

what I did in the application is adding the .clw as an external source module and in general declaration of the procedure I put
MyClass MathClassType

then put a code for a button as
stop(MyClass.Add2(1,2) )

but did not work, so where did I go wrong (I think I missed up)?

thank you again

It might help you to make more sense of things if you take some time to review how the ABC classes are constructed. They are in Clarion\libsrc\win. You’ll see matching filenames with inc/clw extensions. The .inc file has LINK() statements and other stuff that you might want to know.
You should never really need to link a class manually to your app. That’s handled via the .inc file.

Will do. Thank you for your guidance

regards

Which example?
And what where the error messages

This one. I have clarion 6.3 and it is for clarion 8

Regards

Here is a C6 demo using the MathClassType via an inc/clw pair of files. I created it manually so you’ll need to look at the embeds.

It demonstrates auto and manual instantiation of myMaths1 and myMaths2 respectively and calling the .Add() method to add two numbers.

I suggest looking at these files with Notepad, then compare them to my earlier posts in this forum:

MathClass.inc
MathClass.clw
MathD001.clw

This functionality was achieved using a single line …
INCLUDE('MathClass.inc'),ONCE
placed in the global embeds “Before the Global INCLUDES”

As Jeff indicated, this method is very typical so you’ll need to get to grips with its syntax … if you create your own file pair for your first class I’d suggest copying the basic format from these sample files.

Thereth ends my lesson.

MathDemo.zip (88.2 KB)

1 Like

Hi,

I have forked the repository above and created a clone of the clarion 8 version for clarion 6.

msarson/ClarionClassExample: Simple example app compiled with Clarion 8 and Clarion 6 Example (github.com)

I hope it helps you.

Mark

Thank you guys, I a so glad for your support which is highly appreciated.

Best Regards