April 26, 2024, 03:14:42 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


How to compile?

Started by REDEBOLT, February 01, 2008, 11:50:59 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

REDEBOLT

Consider the following program (taken from the help file under "Object Oriented Programming," Index on "CLASS"):

' EMPLOYEE.EBA
'
$MAIN
$INCLUDE "EMPLOYEE.CLS"
$INCLUDE "EMPLOYEE.INC"

OPENCONSOLE
POINTER pEmp
SETTYPE pEmp,employee
pEmp = NEW(employee,1)
#pEmp.m_name = "John Doe"
#pEmp.SetEmployeeId(1111)
#pEmp.SetPayRate(7.25)
#pEmp.CalculatePay(40.5)
#pEmp.PrintPayCheck( )
DELETE pEmp
PRINT:PRINT "Press any key to end."
DO:UNTIL INKEY$<>""
CLOSECONSOLE


'EMPLOYEE.CLS

CLASS employee
    'methods
    DECLARE CalculatePay(hours as float),float
    DECLARE SetPayRate(amount as float)
    DECLARE SetEmployeeID(id as int)
    DECLARE PrintPaycheck( )
    'members
    int m_employeeID
    float m_payrate
    float m_lastpay
    string m_name
END CLASS


' EMPLOYEE.INC
'
SUB employee::CalculatePay(hours as float),float
    m_lastpay = m_payrate * hours
    RETURN m_lastpay
END SUB

SUB employee::SetPayRate(amount as float)
    m_payrate = amount
END SUB

SUB employee::SetEmployeeID(id as int)
    m_employeeID = id
END SUB

SUB employee::PrintPayCheck( )
    PRINT "Pay to the order of "+ m_name +" ***$"+USING("%f###.##",m_lastpay)
END SUB


When I compile the program "EMPLOYEE.EBA" as "Build Single," all is well.

Now, according to the help file,
QuoteWhen designing a class that will be used in multiple source files place the class definitions in an include file and the method implementations in a source file that is part of the project.  There is no need to use GLOBAL or EXTERN when referring to class methods as the compiler automatically handles this.  Just $include the file with the class definitions and add the methods source file to the project.

I have changed the "EMPLOYEE.EBA" as follows:

' EMPLOYEE.EBA
'
$MAIN
$INCLUDE "EMPLOYEE.CLS"
 
OPENCONSOLE
POINTER pEmp
SETTYPE pEmp,employee
pEmp = NEW(employee,1)
#pEmp.m_name = "John Doe"
#pEmp.SetEmployeeId(1111)
#pEmp.SetPayRate(7.25)
#pEmp.CalculatePay(40.5)
#pEmp.PrintPayCheck( )
DELETE pEmp
DO:UNTIL INKEY$<>""
CLOSECONSOLE


I created a new project and inserted the files "EMPLOYEE.EBA" and "EMPLOYEE.INC" into it.  Then when I compile, I get the following errors:

QuoteCompiling...
EMPLOYEE.EBA
EMPLOYEE.INC
File: F:\Program Files\EBDev\projects\BOB\HIME\EMPLOYEE.INC (3) Unknown class - float
File: F:\Program Files\EBDev\projects\BOB\HIME\EMPLOYEE.INC (4) undefined variable - hours
File: F:\Program Files\EBDev\projects\BOB\HIME\EMPLOYEE.INC (4) undefined variable - m_payrate
File: F:\Program Files\EBDev\projects\BOB\HIME\EMPLOYEE.INC (4) illegal operand
File: F:\Program Files\EBDev\projects\BOB\HIME\EMPLOYEE.INC (4) undefined variable, unable to autodefine - m_lastpay
File: F:\Program Files\EBDev\projects\BOB\HIME\EMPLOYEE.INC (5) RETURN outside of subroutine
File: F:\Program Files\EBDev\projects\BOB\HIME\EMPLOYEE.INC (6) RETURN outside of subroutine - END SUB
File: F:\Program Files\EBDev\projects\BOB\HIME\EMPLOYEE.INC (8) Unknown class
File: F:\Program Files\EBDev\projects\BOB\HIME\EMPLOYEE.INC (9) undefined variable - amount
File: F:\Program Files\EBDev\projects\BOB\HIME\EMPLOYEE.INC (9) undefined variable, unable to autodefine - m_payrate
File: F:\Program Files\EBDev\projects\BOB\HIME\EMPLOYEE.INC (10) RETURN outside of subroutine - END SUB
File: F:\Program Files\EBDev\projects\BOB\HIME\EMPLOYEE.INC (12) Unknown class
File: F:\Program Files\EBDev\projects\BOB\HIME\EMPLOYEE.INC (13) undefined variable - id
File: F:\Program Files\EBDev\projects\BOB\HIME\EMPLOYEE.INC (13) undefined variable, unable to autodefine - m_employeeID
File: F:\Program Files\EBDev\projects\BOB\HIME\EMPLOYEE.INC (14) RETURN outside of subroutine - END SUB
File: F:\Program Files\EBDev\projects\BOB\HIME\EMPLOYEE.INC (16) Unknown class
File: F:\Program Files\EBDev\projects\BOB\HIME\EMPLOYEE.INC (17) undefined variable - m_lastpay
File: F:\Program Files\EBDev\projects\BOB\HIME\EMPLOYEE.INC (17) undefined variable - m_name
File: F:\Program Files\EBDev\projects\BOB\HIME\EMPLOYEE.INC (17) illegal operand
File: F:\Program Files\EBDev\projects\BOB\HIME\EMPLOYEE.INC (17) illegal operand
File: F:\Program Files\EBDev\projects\BOB\HIME\EMPLOYEE.INC (17) illegal operand
File: F:\Program Files\EBDev\projects\BOB\HIME\EMPLOYEE.INC (18) RETURN outside of subroutine - END SUB
Error(s) in compiling "F:\Program Files\EBDev\projects\BOB\HIME\EMPLOYEE.INC"

What am I doing wrong?

Regards,
Bob

sapero

You have to $INCLUDE "EMPLOYEE.CLS" in EMPLOYEE.INC, the methods needs to know the class definition too.

Remember this standard layout:
Class source file (implementation, one of project files):
$include "myclass defs" /*required*/

sub myclass::mymethod() /*part or all methods here*/
endsub


Any source file that uses myclass methods (one of project files):
$include "myclass defs" /*required*/

myclass var
var.method()


myclass defs:
class myclass
...
endclass

REDEBOLT

Thank you Sapero, for your reply.
I think I have corrected the source files like you said.
Here are the current listings:

' EMPLOYEE.EBA
'
$MAIN
$INCLUDE "EMPLOYEE.CLS"

OPENCONSOLE
POINTER pEmp
SETTYPE pEmp,employee
pEmp = NEW(employee,1)
#pEmp.m_name = "John Doe"
#pEmp.SetEmployeeId(1111)
#pEmp.SetPayRate(7.25)
#pEmp.CalculatePay(40.5)
#pEmp.PrintPayCheck( )
DELETE pEmp
PRINT:PRINT "Press any key to end."
DO:UNTIL INKEY$<>""
CLOSECONSOLE

' EMPLOYEE.INC
'
$INCLUDE "EMPLOYEE.CLS"
SUB employee::CalculatePay(hours as float),float
    m_lastpay = m_payrate * hours
    RETURN m_lastpay
END SUB

SUB employee::SetPayRate(amount as float)
    m_payrate = amount
END SUB

SUB employee::SetEmployeeID(id as int)
    m_employeeID = id
END SUB

SUB employee::PrintPayCheck( )
    PRINT "Pay to the order of "+ m_name +" ***$"+USING("%f###.##",m_lastpay)
END SUB

'EMPLOYEE.CLS
'
CLASS employee
    'methods
    DECLARE CalculatePay(hours as float),float
    DECLARE SetPayRate(amount as float)
    DECLARE SetEmployeeID(id as int)
    DECLARE PrintPaycheck( )
    'members
    int m_employeeID
    float m_payrate
    float m_lastpay
    string m_name
END CLASS


The results:
Compiling...
EMPLOYEE.EBA
EMPLOYEE.INC

Linking...
Emergence Linker v1.11 Copyright ÂÃ,© 2006 Ionic Wind Software
Unresolved external _ib_main
Error: Unresolved extern _ib_main
Error(s) in linking EMPLOYEE.exe


I still fail to understand.
Regards,
Bob

LarryMc

I change your last file names to look like this:$MAIN
$INCLUDE "EMPLOYEE.inc"

OPENCONSOLE
POINTER pEmp
SETTYPE pEmp,employee
pEmp = NEW(employee,1)
#pEmp.m_name = "John Doe"
#pEmp.SetEmployeeId(1111)
#pEmp.SetPayRate(7.25)
#pEmp.CalculatePay(40.5)
#pEmp.PrintPayCheck( )
DELETE pEmp
PRINT:PRINT "Press any key to end."
DO:UNTIL INKEY$<>""
CLOSECONSOLE

' EMPLOYEECLS.EBA
'
$INCLUDE "EMPLOYEE.inc"
SUB employee::CalculatePay(hours as float),float
    m_lastpay = m_payrate * hours
    RETURN m_lastpay
END SUB

SUB employee::SetPayRate(amount as float)
    m_payrate = amount
END SUB

SUB employee::SetEmployeeID(id as int)
    m_employeeID = id
END SUB

SUB employee::PrintPayCheck( )
    PRINT "Pay to the order of "+ m_name +" ***$"+USING("%f###.##",m_lastpay)
END SUB

'EMPLOYEE.inc
'
CLASS employee
    'methods
    DECLARE CalculatePay(hours as float),float
    DECLARE SetPayRate(amount as float)
    DECLARE SetEmployeeID(id as int)
    DECLARE PrintPayCheck( )
    'members
    int m_employeeID
    float m_payrate
    float m_lastpay
    string m_name
END CLASS

I did it to match more like I do it.
I then created a New project  named emp and told it to make a console application.
I then added employee.eba and employeecls.eba to the project.
When I compiled with my setup I got a compile error saying it couldn't find employee@PrintPayCheck

That was because in the class definitions you spelled it PrintPaycheck instead of PrintPayCheck.
Evidently it is case sensitive.  I corrected that and it compiled fine.
Attached are the files that worked for me and a picture of the "project files" window.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

So more info, but it might be too much info right now.

With your 3 files I compiled above I would have done this.

1) Created a new project called emplib and select "Static Lib" from the compile option.(where it has the emplib.exe for the name change the "exe" to "lib".)
2)Add employeecls to the project.
3)compile the lib.
4) copy emplib.lib to the EBasic lib directory
5) copy the employee.inc file to the EBasic include directory.
6) close the emplib project
Now you can load your original(my version) employee.eba as a stand alone or in a new project
Before the line that has $include "employee.inc" enter $use "emplib.lib"
In a stand alone that's all you have to do.
In a project just make sure you DONT add employeecls.eba to the project.

Hope that helps.

Larry

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

REDEBOLT

Thanks, Larry.

No matter what I do, I keep getting this error:
Compiling...
EMPLOYEE.EBA
EMPLOYEE.INC

Linking...
Emergence Linker v1.11 Copyright ÂÃ,© 2006 Ionic Wind Software
Unresolved external _ib_main
Error: Unresolved extern _ib_main
Error(s) in linking EMPLOYEE.exe


Yes, I have "$MAIN" in the "EMPLOYEE.EBA" file.
Regards,
Bob

Ionic Wind Support Team

The .inc file should be included, not compiled.  Remove it from the project

Paul.
Ionic Wind Support Team

LarryMc

Quote from: REDEBOLT on February 04, 2008, 02:18:12 PM
No matter what I do, I keep getting this error:
Download my zip file above and follow the directions and it will compile fine.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

REDEBOLT

February 04, 2008, 06:07:01 PM #8 Last Edit: February 04, 2008, 06:22:05 PM by REDEBOLT
Thank you Paul, for the tip.
I followed your advice and it compiled perfectly.

Thanks for your help Larry.
I did as you said, but it still didn't work.

Here are the working files:
'CEMPLOYEE.INC
'
CLASS employee
    'methods
    DECLARE CalculatePay(hours as float),float
    DECLARE SetPayRate(amount as float)
    DECLARE SetEmployeeID(id as int)
    DECLARE PrintPaycheck( )
    'members
    int m_employeeID
    float m_payrate
    float m_lastpay
    string m_name
END CLASS
'
'++++++++++ End of include file CEMPLOYEE.INC +++++++++++++++++++++++

' EMPLOYEE.INC
'
SUB employee::CalculatePay(hours as float),float
    m_lastpay = m_payrate * hours
    RETURN m_lastpay
END SUB

SUB employee::SetPayRate(amount as float)
    m_payrate = amount
END SUB

SUB employee::SetEmployeeID(id as int)
    m_employeeID = id
END SUB

SUB employee::PrintPayCheck( )
    PRINT "Pay to the order of "+ m_name +" ***$"+USING("%f###.##",m_lastpay)
END SUB
'
'++++++++++ End of include file EMPLOYEE.INC +++++++++++++++++++++++

' EMPLOYEE.EBA
'
$MAIN
$INCLUDE "CEMPLOYEE.INC"
$INCLUDE "EMPLOYEE.INC"
'
OPENCONSOLE
POINTER pEmp
SETTYPE pEmp,employee
pEmp = NEW(employee,1)
#pEmp.m_name = "John Doe"
#pEmp.SetEmployeeId(1111)
#pEmp.SetPayRate(7.25)
#pEmp.CalculatePay(40.5)
#pEmp.PrintPayCheck( )
DELETE pEmp
PRINT:PRINT "Press any key to end."
DO:UNTIL INKEY$<>""
CLOSECONSOLE
'
'++++++++++ End of program file EMPLOYEE.EBA +++++++++++++++++++++++


Project - EMPLOYEE
-----------------------------------------------------------
EMPLOYEE.EBA
Regards,
Bob

LarryMc

Glad it works for you.

I guess it's just my preference but I NEVER put any subroutines in a ".inc" file.
I use ".inc" files only for const, types, and declarations.

That's why I said, basically(from what you have working right now), was to change the "employee.inc" file to an ".eba" file and ADD it to your project.

Too each his own,  just glad you got over the hump.

BTW, what I suggested you do compiled fine for me and is the procedure I used to create my CWyswygLM, CXmlLM2 and
LinkList classes.


Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

REDEBOLT

February 05, 2008, 03:04:29 PM #10 Last Edit: February 05, 2008, 03:07:11 PM by REDEBOLT
Larry,

I re-examined your project and discovered that a made another rookie error. :'( :-[  I included EMPLOYEE.INC into the project instead of EMPLOYEE.EBA and now all is well.

Your approach has merit and is very logical.  This is what I learned from this project:

1)  The $MAIN module is a member of the project and $INCLUDEs the .INC file for the class definitions.

2)  The class implementation (SUBs) is also a member of the project and $INCLUDEs the .INC file for the class definitions.  This is an .EBA file and not an .INC file.

3)  The class definition file (.INC) is not a member of the project but is included in all .EBA modules that use the class.

I thank you, Larry, for your tutelage.  I apologize for my confusion and hope you'll forgive my clumsiness.

:)
Regards,
Bob

pistol350

Hi Larry!

Quote from: Larry McCaughn on February 04, 2008, 06:39:58 PM
...

Too each his own,  just glad you got over the hump.
...

Larry

"Too each his own, ..."
I'm curious to know the meaning of that phrase  :)
Regards,

Peter B.

LarryMc

Correcting the misspelling it should be: "To each his own"

It basically means each person selects their own way of doing things and that they are comfortable with that.
People who use the phrase usually mean "that isn't the way I would do it but if it works for you then by all means do it that way"

"got over the hump" with hump being any obstacle was saying I was glad he got it to work for him.

Nothing derogatory at all.

I've heard the phrase used all my life.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

Quote from: REDEBOLT on February 05, 2008, 03:04:29 PM

I thank you, Larry, for your tutelage.  I apologize for my confusion and hope you'll forgive my clumsiness.

You're more than welcome and I look forward to, hopefully, being able to help in the future.

It appears from your list of things learn that this episode was a success; however I suggest you add one more item to you list.

It's something that Paul has pointed out to ME more than once, "follow directions" ;D

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

pistol350

Thank you Larry!

You' ve just added one more relevant phrase to my knowledge.
I've never heard or read this one before. 8)
Regards,

Peter B.