CTD 4.1 - How to get typed data from C# library

Discussion forum about all things Gupta, OpenText and the community.
ThomasTIP
Austria
Posts: 1
Joined: 07 Dec 2020, 15:41
Location: Austria

CTD 4.1 - How to get typed data from C# library

Post by ThomasTIP » 14 Dec 2020, 10:00

Hi,

Let's say I have the following class definitions in a C# library:

public class Order
{
public Customer Customer { get; set; }
public DateTime OrderDate { get; set; }
public OrderPos[] OrderPosArray { get; set; }
}

public class OrderPos
{
public string ItemName { get; set; }
public decimal Price { get; set; }
}

public class Customer
{
public string FirstName { get; set; }
public string LastName { get; set; }
}

public class MyExternalFunctions
{
public Order[] GetAllOrders()
{
// return an array of all orders
}
}

I can import the .tlb file for that C# dll in CTD, and it will generate the classes with PropSet/PropGet for all properties plus the function in MyExternalFunctions. Good.
Now, how can I get Order type objects by calling GetAllOrders in CTD?

Call fcMyExternalFunctions.Create( )
Call fcMyExternalFunctions.GetAllOrders( myVariant )

From the help, I need to convert this myVariant to a SafeArray, then use GetObject to retrieve an element. However, I do not understand how to get an element of type Order on this side. I am not aware of any cast-ability in CTD to convert that object element to an Order element. Is this possible somehow?

If not, what is the alternative of transferring nested object data from C# to CTD?

thomas.uttendorfer
Site Admin
Site Admin
Germany
Posts: 243
Joined: 05 Mar 2017, 17:19
Location: Munich Germany

Re: CTD 4.1 - How to get typed data from C# library

Post by thomas.uttendorfer » 15 Dec 2020, 08:46

Hi Thomas,

as far as I know, arrays of classes as parameter won't work with TD.
Instead I write:

Code: Select all

public class Order
{
public Customer Customer { get; set; }
public DateTime OrderDate { get; set; }
private OrderPos[] OrderPosArray;

public int GetCountOrderPos()
{
    return OrderPosArray.Length();
}
public OrderPos GetPosByIdx(int idx)
{
    if(idx>=0 && idx<OrderPosArray.Length())
    { return OrderPos[idx]; }
    else { return null; }
}
}
Regards Thomas
Thomas Uttendorfer
[ frevel & fey ] Software-System GmbH
https://thomasuttendorfer.wordpress.com/

User avatar
Steve Leighton
Site Admin
Site Admin
New Zealand
Posts: 274
Joined: 05 Mar 2017, 20:57
Location: Tauranga, New Zealand <--> Stroud, England

Re: CTD 4.1 - How to get typed data from C# library

Post by Steve Leighton » 16 Dec 2020, 03:50

.
C# means nothing to me, so I probably missed the point completely, but here's how I would do something similar in GTD, by using an array of nested Pos functional Class within an array of nested Order functional Class..
Declare the top level class cOrders as a variable locally or globally e.g. cOrders: allOrders, so you can pass the whole struc around, e.g. Call GetAllOrders( allOrders ) or refer to each Order or each Order.Pos individually, or deconstruct the entire struct into individual arrays.
.
The main point being that cPos is an instance of cPoss which is an instance of cOrder which is an instance of cOrders. I think.
.
.
Here's the definition:
OrderPosClass.JPG
.
Here's a declaration of the top level Orders, so you can refer to the entire struct.
AllOrders.JPG
.
Here's an e.g. of passing your entire Orders struct to a global function:
Calling a Global function passing cOrders class .JPG
.
Here's an e.g. of adding a Pos to an existing Order. ( See cPoss.Add() above )
Adding a Pos to an Order.JPG
.
Here's referring to an individual Order.Pos, or all Pos or all Orders, say from within global func gGetAllOrders( allOrders )
Get each Pos from an Order or get each Order.JPG
You do not have the required permissions to view the files attached to this post.
Greetings from New Zealand
Steve Leighton

Bankside Systems Ltd.
UK ♦ Australia ♦ New Zealand

www.banksidesystems.co.uk

Image

thomas.uttendorfer
Site Admin
Site Admin
Germany
Posts: 243
Joined: 05 Mar 2017, 17:19
Location: Munich Germany

Re: CTD 4.1 - How to get typed data from C# library

Post by thomas.uttendorfer » 16 Dec 2020, 15:05

Hi Steve,

the point here is to import a COM-class in gupta (it does not matter if it's written in c# or c++ or anything else).
And there it is not possible to pass an array of complex datatype like the positions of the order in the example here.
But you can pass single complex datatypes. So the workaround is not to pass an array but accessing the items of the array individually.

Regards Thomas
Thomas Uttendorfer
[ frevel & fey ] Software-System GmbH
https://thomasuttendorfer.wordpress.com/

User avatar
Steve Leighton
Site Admin
Site Admin
New Zealand
Posts: 274
Joined: 05 Mar 2017, 20:57
Location: Tauranga, New Zealand <--> Stroud, England

Re: CTD 4.1 - How to get typed data from C# library

Post by Steve Leighton » 16 Dec 2020, 22:03

.
oh well, the e.g.'s might be useful to someone wanting ideas on arrays of functional classes.
Greetings from New Zealand
Steve Leighton

Bankside Systems Ltd.
UK ♦ Australia ♦ New Zealand

www.banksidesystems.co.uk

Image

Return to “General Discussion”

Who is online

Users browsing this forum: [Ccbot] and 0 guests