on 06-12-2014 3:52 PM
I'm sure this question has been answered before and I could swear I've seen Bruce demonstrate something like this, but my Google skills have failed me.
I have a C# dll that Powerbuilder classic can get to as the dll has been made COM visible and regasm'ed to death as per Bruce and Yakov's excellent guides on how to talk to .NET from Powerbuilder. I know it's working fine as I have a bunch of test functions that do nothing more than return strings or numbers and they are all callable from PB.
I now want to retrieve some data in the .NET code and return it to PB, where PB will load it into a datawindow. I an pretty easily get the data into an array of the correct class and serialize it to XML and return that string to PB, but I assume that any code I'd have to write to grab the data out of the XML, convert it to the correct datatypes and shove it onto the datawindow will be pretty slow.
Does anyone have a recommended way of doing this? I tried returning the array of data from the call into a structure in PB, but I get a "Mismatched ANY datatypes error" and I know my structure matches my C# class exactly as I've spent hours staring at it today (I also wrote a tool to create both at the same time, so they should match!).
Thanks for any help
To add a bit extra, here's a much simplified version, I have a feeling I'm being really stupid
Here's some simple C# code:
public Client ArrayTest()
{
Client client = new Client();
client.string1 = "AAAA";
client.string2 = "BBBB";
return client;
}
Here's my call to it from PB:
lany = lole_object.ArrayTest()
lstr_test = lany
lstr_test is:
global type str_test from structure
string s_ref
string s_name
end type
Doesn't work gives "Cannot convert oleobject in Any variable to str_test". So that has me thinking, an OLEObject was returned, I assume an object of type Client. So I created a new OLEObject and gave it the result from ArrayTest(). I can now do String(client.String1) and String(client.String2) and see AAAA and BBBB. So I'm getting somewhere. Still doesn't look like I'll ever have a simple way of assigning this to a datawindow though, but perhaps a bit faster than with XML, possibly not as client.string1 is an Any variable as far as I can tell rather than a string and so still needs converting.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Cast your .Net stuff into a .Net array. Something like these examples:
// String arrays with 3 elements:
string[] arr1 = new string[] { "one", "two", "three" };
string[] arr2 = { "one", "two", "three" };
var arr3 = new string[] { "one", "two", "three" };
string[] arr4 = new string[3];
arr4[0] = "one";
arr4[1] = "two";
arr4[2] = "three";
Then try your code.
Sorry for the delay in replying.
ImportString seems like an excellent idea and I've got it working after creating my first Import Template on a datawindow. I've always wondered what the new XML thing that I remove from display when editing a datawindow is for
However, it seems pretty slow depending on how large the data is. Since I'm planning to use this in the future for everything our application does it's probably too slow.
So now I'm looking into getting back an array from the OLE call and setting a structure. Not having much luck in getting it working at the moment. I can get an array of any returned from the call and I can then assign each element of that array to an OLEObject and then I can get each field from the OLEObject and assign it to my structure. However I was hoping I could dump stuff into my structure at least a row at a time if not the whole thing in one go.
Anyone have any ideas?
Here's the code that works:
str_test lstr_test
oleObject lole_test
any lany[]
lole_test = CREATE OLEObject
lany = iuo_tcp.iole_utils.GetArray()
lole_test = lany[1]
lstr_test.s_str1 = lole_test.string1
lstr_test.s_str2 = lole_test.string2
DESTROY lole_test
Thanks.
User | Count |
---|---|
92 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.