Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hb_BeginObject #13

Open
rjopek opened this issue Dec 30, 2022 · 3 comments
Open

hb_BeginObject #13

rjopek opened this issue Dec 30, 2022 · 3 comments
Labels

Comments

@rjopek
Copy link

rjopek commented Dec 30, 2022

The hb_BeginObject function is a function in the Harbour language that is used to start the definition of an object class. It is typically used in conjunction with the hb_EndObject function, which is used to end the definition of an object class.

Here is an example of how these functions might be used in a class definition:

hb_BeginObject( "Person" )
   hb_ObjMethod( "Init", Person_Init )
   hb_ObjMethod( "Name", Person_Name )
   hb_ObjMethod( "Age", Person_Age )
hb_EndObject()

In this example, hb_BeginObject is used to start the definition of a class called "Person", and hb_EndObject is used to end the definition of the class. The class has three methods: Init, Name, and Age. These methods can be called on objects of the Person class to perform various actions, such as initializing the object, retrieving the name or age of the object, etc.

The hb_BeginObject function takes a single argument, which is a string containing the name of the class. This name is used to identify the class and distinguish it from other classes in the code.

The hb_BeginObject function is important because it signifies the start of the class definition and allows the compiler to generate the necessary code to create and manage objects of the class. Without it, the compiler would not be able to correctly process the class definition.

https://github.com/harbour/core/blob/master/src/rtl/perfuncs.prg#L59

@rjopek rjopek closed this as completed Dec 31, 2022
@Petewg Petewg added the memo! label Dec 31, 2022
@Petewg Petewg reopened this Dec 31, 2022
@rjopek
Copy link
Author

rjopek commented Dec 31, 2022

I tried to refer to the function hb_EndObject
The hb_BeginObject and hb_EndObject functions are not part of the standard Harbour language, but rather are part of the Harbour Extender library, which is a set of additional functions and features that can be used with Harbour.
It is not without reason that I chose the hb_EndObject solitary function to make a brief description of the function's purpose.

@Petewg
Copy link
Owner

Petewg commented Dec 31, 2022

As I pointed here --> #14 (comment) , if you think you could prepare some docs about OO implementation of Harbour,
you're very welcome to do it and post in a separate page in this wiki.

@rjopek
Copy link
Author

rjopek commented Dec 31, 2022

Here is an example of how the hb_BeginObject function might be implemented:

FUNCTION hb_BeginObject( cClassName )

   LOCAL oObject

   oObject := NIL

   IF t_aObjects == NIL
      t_aObjects := {}
   ENDIF

   oObject := NEWOBJECT( cClassName )
   oObject:cClassName := cClassName
   oObject:t_aProperties := {}

   AAdd( t_aObjects, oObject )

   RETURN oObject

This function takes a single argument, which is the name of the object class being defined. It creates a new object of the specified class and adds it to the t_aObjects array, which is used to track the objects that are currently being defined. The function then returns a reference to the new object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants