xsharp.eu • Porting VO Code - Page 4
Page 4 of 4

Porting VO Code

Posted: Sat Jul 22, 2017 11:42 am
by Chris
Hi Karl,

> if one copies a path into the sourcefile sle and then hits the [...] the dialog starts with current dir, i.e. ignores the path input, which is a pita...
>

Thanks, will fix this.


> some option to "generally" set the path for Catoxxx files would be nice

Do you mean in XIDE? Good idea to add a menu option to automatically copy CATO* dlls to the bin folder...


> for folks like Wolfgang, who plan to sync Vo and X# side for longer time, it would be great, if xporter could be called e.g. from Xide, _remembering settings_, so the sync could be a one click experience ;)
>

Ah, forgot to add an entry in XIDE! For now you can do it by creating a file Toys.cfg in XIDEConfig folder with those contents:

MENUENTRY=VOExporter
EXECUTE=C:Program Files (x86)XSharpVOXPorterVOXporter.exe

Also agreed it would be nice to save and remember settings, will look into it. I just hate it that you can't save the current options in a cfg file in the same folder with the .exe in program files, but need to do it via registry or a cfg file in outer space..

Chris

Porting VO Code

Posted: Sat Jul 22, 2017 12:51 pm
by wriedmann
Hi Chris,

the current xPorter version cannot be called from XIDE because the start directory is not set correctly and then xPorter does not find his configuration.

I could add such an option to my plugin, will do it when I return home.

And IMHO it would be enough to pass a configuration file on the command line, so XIDE (or a plugin) could write settings there and call them xPorter.

Currently, I'm using my plugin to copy the applications path to the clipboard and pasting it into xPorter.

Wolfgang

Porting VO Code

Posted: Sun Jul 23, 2017 11:04 am
by markus.lorenzi@dvbern.ch
Hi Robert

thanks a lot for your commentes on my paper. I just built them into the paper and did also some cosmetic changes. Here is the most recent Version.
I just realized that the Excel Export in this sample does not work as expected (the app crashes).
Perheps you can see whats wrong. Just right click on the files list and choose: Liste nach Excel übertrgen.

TIA Markus
Documentation:
Project FeserExplorer.zip
(472.07 KiB) Downloaded 69 times
Project:
MyExplorer.zip
(627.84 KiB) Downloaded 66 times

Porting VO Code

Posted: Sun Jul 23, 2017 1:01 pm
by Chris
Hi Wolfgang,

Ah right, I haven't fixed that problem yet, thanks for reminding!

Actually I think it's a very good idea to provide also simple command line parameters to the VOXporter for the input and output, so you can call it easily externally, will do that, too.

Chris

Porting VO Code

Posted: Sun Jul 23, 2017 1:55 pm
by Chris
Hi Markus,

Thanks for the updated document, getting better and better! Although I am afraid you will need to make some changes related to COM, see below. Also it would be nice to give some info why the compiler in X# requires some of the changes, but this is probably a task for the devteam :) In the next days/weeks I will collect the most common compiler errors reported in ported code and list them together with a small explanation and resolution, so it can be used as a reference.

Also a small comment regarding return values of ASSIGNs, those are completely ignored, because by definition in .Net an ASSIGN (Property setter) does not return a value, so you might want to change the code (remove return type from definition and return value from RETURN statement) so it reflects that.

Regarding the runtime problem with Excel, I see 2 COM-related issues:

1. The message of the runtime exception is "Types extending from COM objects should override all methods of an interface implemented by the base COM class". I searched for this error and according to

https://www.codeproject.com/Articles/99 ... ty-With-NE

indeed you cannot simply inherit from a COM object. If you do that, then you need to provide all the members that implement the corresponding COM interface. For a very large class like Excel.ApplicationClass I think this is not feasible, so I suggest to change your IMSExcel class so it does not inherit from that class, but it uses it as a member. Of course you can do it a different way, but my solution was to change

CLASS IMSExcel INHERIT MSExcel

to

CLASS IMSExcel

and also add

PROPERTY ExcelObject AS Microsoft.Office.Interop.Excel.ApplicationClass AUTO

then added this to the constructor of the class:

SELF:ExcelObject := Microsoft.Office.Interop.Excel.ApplicationClass{}

and changed also the following:

ACCESS ExcelOK
RETURN SELF:lVisible = SELF:Visible
....
cExcelPath := SELF:Path + "excel.exe"
...
ASSIGN Visible(lV AS LOGIC)
lVisible := lV
RETURN SELF:Visible := lV

to (just use the properties of the Excel class):

ACCESS ExcelOK
RETURN SELF:lVisible = SELF:ExcelObject:Visible
....
cExcelPath := SELF:ExcelObject:Path + "excel.exe"
...
ASSIGN Visible(lV AS LOGIC)
lVisible := lV
RETURN SELF:ExcelObject:Visible := lV

that fixes that problem, but there's also:

2. In the _ToExcel() method, in a couple places you are assigning a VO style ARRAY to a Range object, but unfortunately the ARRAY type is X#/vulcan specific, so the COM object does not know how to translate it. Fortunately the solution is easy, you can write a function that converts a VO ARRAY to a .Net Array:

FUNCTION VOToNetArray(aVO AS ARRAY) AS System.Array
// hard coded for 2-dimension ARRAY
LOCAL aNet AS OBJECT[,]
aNet := OBJECT[,]{ALen(aVO) , ALen(aVO[1])}
FOR LOCAL i := 1 AS INT UPTO ALen(aVO)
FOR LOCAL j := 1 AS INT UPTO ALen(aVO)
anet[i,j] := aVO[i,j]
NEXT
NEXT
RETURN aNet

and then simply change

oRange:Value := aColumns
...
oRange:Value := aListe

to

oRange:Value := VOToNetArray( aColumns )
...
oRange:Value := VOToNetArray( aListe )

Now output to Excel works nicely!

Chris

Porting VO Code

Posted: Sun Jul 23, 2017 3:11 pm
by markus.lorenzi@dvbern.ch
Hi Chris

thank you very much for your detailed answer. This will help a lot.
There was just one typo in your VOToNetArray() function. In the inner Loop you Need the Count from the 2nd Dimension of the Array.

FUNCTION VOToNetArray(aVO AS ARRAY) AS System.Array
// hard coded for 2-dimension ARRAY
LOCAL aNet AS OBJECT[,]
aNet := OBJECT[,]{ALen(aVO) , ALen(aVO[1])}
FOR LOCAL i := 1 AS INT UPTO ALen(aVO)
FOR LOCAL j := 1 AS INT UPTO ALen(aVO[1])
anet[i,j] := aVO[i,j]
NEXT
NEXT
RETURN aNet

Here is the new documentation and the final Project file.
Thaks and have a nice rest of the Weekend.
Markus
Solution:
MyExplorer.zip
(401.66 KiB) Downloaded 68 times
Documentation:
Project FeserExplorer.zip
(474.64 KiB) Downloaded 71 times

Porting VO Code

Posted: Sun Jul 23, 2017 4:59 pm
by Chris
Hi Markus,

Thank you very much, all looking very good! It feels very nice and rewarding seeing more and more VO apps now running well in X#...

And thanks for the correction on the typo in my code, although this is very strange, because in the real code I had written it like that:

FOR LOCAL j := 1 AS INT UPTO ALen(aVO)

but it does not appear correctly in my previous message. Maybe a forum copy/paste issue, as an experiment let's see if it appears correctly in this post.

Chris

Porting VO Code

Posted: Sun Jul 23, 2017 5:06 pm
by Chris
Heh, the code again doesn't appear correctly in my message! It was supposed to read:

aVO<left bracket>i<right bracket>

but I guess the forum software translates this as a control character, actually looks like it treats is as an italics control character and the rest of my message appeared in italic! That was a fun thing to debug :)

Chris