Display "Hello world" using class?

seenunandagiri

New Member
HI Friends,

I am very new to the class oriented procedures. My intention is to print "Hello world". As read from materials I used following code, it is running fine but not displaying anything.

CLASS sample.

METHOD PUBLIC VOID mess() .
DISPLAY "Hello world!" .
END METHOD .

END CLASS .

suggest me how to display "hello world"....
 

DevTeam

Member
Hi,

In order to display the message, your method "mess" needs to be called.
When you run your class, the constructor is called. In your example, there's no declared constructor, so your class is just instanciated and destroyed.

You need to :
- either define a constructor which will call the method :

Code:
CLASS sample.
  CONSTRUCTOR PUBLIC sample() :
    mess().
  END CONSTRUCTOR.

  METHOD PUBLIC VOID mess() .
    DISPLAY "Hello world!" .
  END METHOD .
END CLASS .

- or create a .p program to instanciate your "sample" class, and then call the method :

Code:
DEF VAR myClass AS CLASS sample NO-UNDO.

/* Call myClass' constructor */
myClass = NEW myClass().

/* Call the method "mess" on your object */
myClass:mess().

/* Call myClass' destructor */
IF VALID-OBJECT(myClass)
THEN DELETE OBJECT myClass.
 

seenunandagiri

New Member
Hi,

Thanx for ur valuable solution...It helped me a lot. first code working fine, but when i try to run the second code it has given following error.

Can't find class or interface myClass() at line 4.
 

rrubio

New Member
Hi Guys,

One step further from "Hellow world".

I would like to call a class from a procedure editor. The class would contain for example "for each customer etc.." how would i then display this records on my procedure editor?

Cheers
 

Casper

ProgressTalk.com Moderator
Staff member
Well, this is easy, although I dont think data access should happen directly in a class, here is a quick example:

ttcust.i
Code:
DEFINE TEMP-TABLE ttcust NO-UNDO {&REF-ONLY} LIKE customer.

examplecust.cls:
Code:
CLASS examplecust:
{ ttcust.i &REF-ONLY=REFERENCE-ONLY}
METHOD PUBLIC VOID getcustomers(INPUT TABLE ttcust):
      DEFINE BUFFER customer FOR customer.
      FOR EACH customer NO-LOCK:
          BUFFER-COPY customer TO ttcust.
          RELEASE ttcust.
      END.
END METHOD.
END CLASS.

getcustomers.p:
Code:
{ ttcust.i }
DEFINE VARIABLE myCustomers AS examplecust NO-UNDO.
myCustomers = NEW examplecust().
myCustomers:getcustomers(INPUT TABLE ttcust BY-REFERENCE).
FOR EACH ttcust:
    DISPLAY ttcust.
END.

If you run getcustomers.p then you will get all the customers in from the cusomer table.

This is just an idea for how to work with classes. Among others it is considered bad practice to define temp-table with a like statement.

HTH,

Casper.
 

tamhas

ProgressTalk.com Sponsor
I dont think data access should happen directly in a class,

Sure it should .... just not the same class as the UI! :)
 

rrubio

New Member
Gentlemen,

Thank you for your assistance, much appreciated. I can now continue my journey in progress classes :)

P.S. Thought it might be worth while mentioning, i'm starting to apply classes "where applicable" to a webspeed app I am currently writing. So far so good for classes, like it!

P.S.2. Casper... do i have your permission to publish your example under my blog? i think it would be of great help to other progress developers.

Rodrigo
 

Casper

ProgressTalk.com Moderator
Staff member
P.S.2. Casper... do i have your permission to publish your example under my blog? i think it would be of great help to other progress developers.

All code is free :)

casper.
 

Casper

ProgressTalk.com Moderator
Staff member
Code:
Sure it should .... just not the same class as the UI! :)

Ok, ok you are right (what's new :D), I meant not in a class containing BL.
And good point not UI, I forgot it is also possible to have a Progress front end ;)

Casper.
 

rcgomez11

Member
Platform: Windows 7 Ultimate
Progress Version: Openedge 10.1C

tried your sample Casper but I can't make it done, it says "Could not find class or interface"...what am I missing in my configuration?
all 3 files are in the same directory, just so you know...
thanks in advance and hope to hear from you soon...

sincerely,
romel gomez
 
Top