# Classes tutorial to create a class from scratch

**URL:** <https://clarionhub.com/t/classes-tutorial-to-create-a-class-from-scratch/5592>\
**Category:** questions\
**Tags:** class\
**Created:** [November 3, 2022, 3:21pm UTC](https://clarionhub.com/t/classes-tutorial-to-create-a-class-from-scratch/5592 "2022-11-03T15:21:26Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![sk2107](https://clarionhub.com/user_avatar/clarionhub.com/sk2107/32/3135_2.png) [@sk2107](https://clarionhub.com/u/sk2107)\
**Post date:** [November 3, 2022, 3:21pm UTC](https://clarionhub.com/t/classes-tutorial-to-create-a-class-from-scratch/5592/1 "2022-11-03T15:21:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Bostjan\_Laba](https://clarionhub.com/user_avatar/clarionhub.com/bostjan_laba/32/2498_2.png) [@Bostjan\_Laba](https://clarionhub.com/u/Bostjan_Laba)\
**Post date:** [November 3, 2022, 3:53pm UTC](https://clarionhub.com/t/classes-tutorial-to-create-a-class-from-scratch/5592/2 "2022-11-03T15:53:42Z")

</div>

Good, I’m also listening 🙂

---

<div class="post-metadata">

**Author:** ![Jane](https://clarionhub.com/letter_avatar_proxy/v4/letter/j/ecb155/32.png) [@Jane](https://clarionhub.com/u/Jane)\
**Post date:** [November 3, 2022, 4:45pm UTC](https://clarionhub.com/t/classes-tutorial-to-create-a-class-from-scratch/5592/3 "2022-11-03T16:45:44Z")

</div>

[![](https://clarionhub-uploads.s3.eu-north-1.amazonaws.com/original/2X/5/56cc65cdce9cebc929715127a13fc9bd5e56ea04.jpeg "ClarionLive! 625 - Mark Overton - My First Class") ](https://www.youtube.com/watch?v=rbkUgisjJA4)

---

<div class="post-metadata">

**Author:** ![Rick\_UpperPark](https://clarionhub.com/user_avatar/clarionhub.com/rick_upperpark/32/346_2.png) [@Rick\_UpperPark](https://clarionhub.com/u/Rick_UpperPark)\
**Post date:** [November 3, 2022, 4:51pm UTC](https://clarionhub.com/t/classes-tutorial-to-create-a-class-from-scratch/5592/4 "2022-11-03T16:51:22Z")

</div>

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](http://www.mediafire.com/file/3r6ms3v25xsvsri/ClarionLive327_20150821_BruceJohnsonOnDerivingABC_Classes.wmv/file)

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

---

<div class="post-metadata">

**Author:** ![sk2107](https://clarionhub.com/user_avatar/clarionhub.com/sk2107/32/3135_2.png) [@sk2107](https://clarionhub.com/u/sk2107)\
**Post date:** [November 3, 2022, 7:15pm UTC](https://clarionhub.com/t/classes-tutorial-to-create-a-class-from-scratch/5592/5 "2022-11-03T19:15:08Z")

</div>

thank you all

Regards

---

<div class="post-metadata">

**Author:** ![sk2107](https://clarionhub.com/user_avatar/clarionhub.com/sk2107/32/3135_2.png) [@sk2107](https://clarionhub.com/u/sk2107)\
**Post date:** [February 23, 2023, 10:39am UTC](https://clarionhub.com/t/classes-tutorial-to-create-a-class-from-scratch/5592/6 "2023-02-23T10:39:27Z")

</div>

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 ☹)

with lots of thanks in advance.

Regards

---

<div class="post-metadata">

**Author:** ![Julian](https://clarionhub.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@Julian](https://clarionhub.com/u/Julian)\
**Post date:** [February 23, 2023, 11:51am UTC](https://clarionhub.com/t/classes-tutorial-to-create-a-class-from-scratch/5592/7 "2023-02-23T11:51:42Z")

</div>

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

```auto
   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)

```

---

<div class="post-metadata">

**Author:** ![sk2107](https://clarionhub.com/user_avatar/clarionhub.com/sk2107/32/3135_2.png) [@sk2107](https://clarionhub.com/u/sk2107)\
**Post date:** [February 23, 2023, 12:02pm UTC](https://clarionhub.com/t/classes-tutorial-to-create-a-class-from-scratch/5592/8 "2023-02-23T12:02:37Z")

</div>

Nice. that’s a good start.

Thank you

Regards

---

<div class="post-metadata">

**Author:** ![sk2107](https://clarionhub.com/user_avatar/clarionhub.com/sk2107/32/3135_2.png) [@sk2107](https://clarionhub.com/u/sk2107)\
**Post date:** [February 23, 2023, 12:18pm UTC](https://clarionhub.com/t/classes-tutorial-to-create-a-class-from-scratch/5592/9 "2023-02-23T12:18:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Johan\_de\_Klerk](https://clarionhub.com/letter_avatar_proxy/v4/letter/j/f9ae1b/32.png) [@Johan\_de\_Klerk](https://clarionhub.com/u/Johan_de_Klerk)\
**Post date:** [February 23, 2023, 12:36pm UTC](https://clarionhub.com/t/classes-tutorial-to-create-a-class-from-scratch/5592/10 "2023-02-23T12:36:49Z")

</div>

Hi,

Take a look at excellent example that Donald Ridley made.

> **[GitHub - donridley1972/ClarionClassExample: Simple example app compiled with Clarion 8.](https://github.com/donridley1972/ClarionClassExample)**
>
> Simple example app compiled with Clarion 8.

Regards  
Johan de Klerk

---

<div class="post-metadata">

**Author:** ![sk2107](https://clarionhub.com/user_avatar/clarionhub.com/sk2107/32/3135_2.png) [@sk2107](https://clarionhub.com/u/sk2107)\
**Post date:** [February 23, 2023, 1:13pm UTC](https://clarionhub.com/t/classes-tutorial-to-create-a-class-from-scratch/5592/11 "2023-02-23T13:13:35Z")

</div>

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

Thank you

---

<div class="post-metadata">

**Author:** ![Julian](https://clarionhub.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@Julian](https://clarionhub.com/u/Julian)\
**Post date:** [February 23, 2023, 3:00pm UTC](https://clarionhub.com/t/classes-tutorial-to-create-a-class-from-scratch/5592/12 "2023-02-23T15:00:35Z")

</div>

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 ..

```auto
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:

```auto
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.

```auto
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.

---

<div class="post-metadata">

**Author:** ![sk2107](https://clarionhub.com/user_avatar/clarionhub.com/sk2107/32/3135_2.png) [@sk2107](https://clarionhub.com/u/sk2107)\
**Post date:** [February 23, 2023, 4:56pm UTC](https://clarionhub.com/t/classes-tutorial-to-create-a-class-from-scratch/5592/13 "2023-02-23T16:56:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jslarve](https://clarionhub.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@jslarve](https://clarionhub.com/u/jslarve)\
**Post date:** [February 23, 2023, 5:03pm UTC](https://clarionhub.com/t/classes-tutorial-to-create-a-class-from-scratch/5592/14 "2023-02-23T17:03:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sk2107](https://clarionhub.com/user_avatar/clarionhub.com/sk2107/32/3135_2.png) [@sk2107](https://clarionhub.com/u/sk2107)\
**Post date:** [February 23, 2023, 5:08pm UTC](https://clarionhub.com/t/classes-tutorial-to-create-a-class-from-scratch/5592/15 "2023-02-23T17:08:47Z")

</div>

Will do. Thank you for your guidance

regards

---

<div class="post-metadata">

**Author:** ![MarkGoldberg](https://clarionhub.com/user_avatar/clarionhub.com/markgoldberg/32/1511_2.png) [@MarkGoldberg](https://clarionhub.com/u/MarkGoldberg)\
**Post date:** [February 23, 2023, 11:42pm UTC](https://clarionhub.com/t/classes-tutorial-to-create-a-class-from-scratch/5592/16 "2023-02-23T23:42:54Z")

</div>

> [@sk2107](#):
>
> It seems very good from the exe supplied, but unfortunately I did not compile with clarion 6

Which example?  
And what where the error messages

---

<div class="post-metadata">

**Author:** ![sk2107](https://clarionhub.com/user_avatar/clarionhub.com/sk2107/32/3135_2.png) [@sk2107](https://clarionhub.com/u/sk2107)\
**Post date:** [February 24, 2023, 1:52am UTC](https://clarionhub.com/t/classes-tutorial-to-create-a-class-from-scratch/5592/17 "2023-02-24T01:52:57Z")

</div>

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

> **[GitHub - donridley1972/ClarionClassExample: Simple example app compiled with Clarion 8.](https://github.com/donridley1972/ClarionClassExample)**
>
> Simple example app compiled with Clarion 8.

Regards

---

<div class="post-metadata">

**Author:** ![Julian](https://clarionhub.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@Julian](https://clarionhub.com/u/Julian)\
**Post date:** [February 24, 2023, 9:48am UTC](https://clarionhub.com/t/classes-tutorial-to-create-a-class-from-scratch/5592/18 "2023-02-24T09:48:06Z")

</div>

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:

```auto
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](https://clarionhub.com/uploads/short-url/mRoam43bTgQbDLi0q1oqH2eyynI.zip) (88.2 KB)

---

<div class="post-metadata">

**Author:** ![Mark\_Sarson](https://clarionhub.com/user_avatar/clarionhub.com/mark_sarson/32/6132_2.png) [@Mark\_Sarson](https://clarionhub.com/u/Mark_Sarson)\
**Post date:** [February 24, 2023, 10:22am UTC](https://clarionhub.com/t/classes-tutorial-to-create-a-class-from-scratch/5592/19 "2023-02-24T10:22:40Z")

</div>

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)](https://github.com/msarson/ClarionClassExample)

I hope it helps you.

Mark

---

<div class="post-metadata">

**Author:** ![sk2107](https://clarionhub.com/user_avatar/clarionhub.com/sk2107/32/3135_2.png) [@sk2107](https://clarionhub.com/u/sk2107)\
**Post date:** [February 24, 2023, 11:00am UTC](https://clarionhub.com/t/classes-tutorial-to-create-a-class-from-scratch/5592/20 "2023-02-24T11:00:56Z")

</div>

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

Best Regards

[Next page](https://clarionhub.com/t/classes-tutorial-to-create-a-class-from-scratch/5592.md?page=2)
