[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Kjærsgaard

10/4/2005 8:37:00 AM

Hi,

I have two classes and I want to implement the traditional associacion
between instances of the classes. One customer can buy many products. I do
not have much X++ experience - as I come from a Java world :-). I have tried
and tried, and now I realise I have to have some help :-)

Cust(name, address)
Product(name, price)

The methods of the Cust class:
public class Cust
{
str name;
str address;
Product product;
List LIproducts;
}

public void new(str pName, str pAddress)
{
;
name = pName;
address = pAddress;
LIproducts = new List(types::AnyType);
}

public void addProduct(Product p)
{
LIproducts.addEnd(p);
}

public void printCustBuyProduct()
{
ListIterator it = new ListIterator(LIproducts);

While (it.more()){
// syntaks error
// I dont know, should I typecast or not - or how do I do it in X++?
Product product = (Product)it.next();
product.print();
}
}

Methods i Product class:
public class Product
{
str name;
str price;
Cust cust;
}

void new(str pName="Empty", str pPrice="Empty")
{
;
name = pName;
price = pPrice;
}

void print()
{
Print "Name: "+this.name;
Print "";
}


--
Best regards
Lars
7 Answers

hghrp

10/4/2005 12:41:00 PM

0

Hi Lars,

you have to define all variables first:

ListIterator it = new ListIterator(LIproducts);
Product product;
;
While (it.more())
{
product = (Product)it.next();
product.print();
}

and sometimes you need a single ; after the variables declaration

Hth,
harald

hghrp

10/4/2005 12:44:00 PM

0

sorry, incorrect, should read:
product = it.next();

there is no such typecasting in X++

regards,
harald

Kjærsgaard

10/4/2005 9:13:00 PM

0

Hi again,

and thank you for your former reply. I have discovered(debugger) that no
product-objects are added to the product-list List at all - due to the fact
that the testprogram cannot at all find the product-class. The debugger comes
with the following description:

"Error: Symbol "product" was not found
"Error: Symbol "LIproducts" was not found

...when I declare the handles with (only part of my testprogram):
static void CustBuyProd(Args _args)
{
Cust k1, k2, k3;
Product p1, p2, p3;
;
......

I have inserted a breakpoint just after these lines, and the errormessages
from the compiler does already appear.

It is not that I should import classes in X++?

--
Best regards
Lars


"hghrp" wrote:

> sorry, incorrect, should read:
> product = it.next();
>
> there is no such typecasting in X++
>
> regards,
> harald
>

hghrp

10/5/2005 7:13:00 AM

0

Hi,

nothing wrong with your approach, but in Axapta it is common to use the
parent class within the child - like in SalesLine:

InventTable inventTable(ItemId itemId = this.itemId,
boolean _forUpdate = false)
{
return InventTable::find(itemId, _forUpdate);
}

one item can be used in many sales lines, but one sales line can only have
one item, so the item object is defined within the sales line, not the other
way.

you can then use
SalesLine thisSalesLine;
;
info(thisSalesLine.inventTable().ItemName);

In X++ it is necessary to compile the objects in correct order, maybe your
problem is because the parent class is not compiled when used within the
child class.

Hth,
harald

Kjærsgaard

10/5/2005 9:43:00 AM

0

Thank you very much for your reply. I can tell you - you do make a difference
:-)

I think you are possibly right about Parent/Child objects, the terminology
is new to me but it sounds likely.
Anyway, I think the classes are compiled in the right order - with the
parent/unique side first, Cust-class, or am I wrong?

static void CustBuyProd(Args _args)
{
Cust k1, k2, k3;
Product p1, p2, p3;
;
window 60,50;
k1 = new Cust("Lars Kjærsgaard", "Banegårdsvej 9, 2. th.");
k2 = new Cust("Marianne Grubak", "Kielgastvej 24");
k3 = new Cust("Helle Holteman", "Hemmersvej 51");

p1 = new Product("Axapta Development I", 9000);
p2 = new Product("Axapta Development II", 16000);
p3 = new Product("Axapta Development III", 9000);

--
Best regards
Lars


"hghrp" wrote:

> Hi,
>
> nothing wrong with your approach, but in Axapta it is common to use the
> parent class within the child - like in SalesLine:
>
> InventTable inventTable(ItemId itemId = this.itemId,
> boolean _forUpdate = false)
> {
> return InventTable::find(itemId, _forUpdate);
> }
>
> one item can be used in many sales lines, but one sales line can only have
> one item, so the item object is defined within the sales line, not the other
> way.
>
> you can then use
> SalesLine thisSalesLine;
> ;
> info(thisSalesLine.inventTable().ItemName);
>
> In X++ it is necessary to compile the objects in correct order, maybe your
> problem is because the parent class is not compiled when used within the
> child class.
>
> Hth,
> harald

hghrp

10/5/2005 12:01:00 PM

0

Hi,

the Product class need to be compiled first, because it is used within Cust
(and X++ does not compile included object first - you have to do that
manually).

Let me know what happens then.

Ciao,
harald

Kjærsgaard

10/5/2005 8:46:00 PM

0

Hi Harald,

together with your advice, it was when I instantiated my product list:
LIproducts = new List(types::AnyType);

....it should be:
LIproducts = new List(types::Class);

It seems as AnyType regards only the simple datatypes. Suddenly it seems
logic :-)
Now, it is working just fine.

Again, thank you very much Harald for following my thread.


--
Best regards
Lars


"hghrp" wrote:

> Hi,
>
> the Product class need to be compiled first, because it is used within Cust
> (and X++ does not compile included object first - you have to do that
> manually).
>
> Let me know what happens then.
>
> Ciao,
> harald