Porting VO Code

This forum is meant for questions and discussions about the X# language and tools
User avatar
Chris
Posts: 4832
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Porting VO Code

Post 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
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
wriedmann
Posts: 3743
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Porting VO Code

Post 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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
markus.lorenzi@dvbern.ch
Posts: 113
Joined: Mon May 02, 2016 9:10 am
Location: Schweiz

Porting VO Code

Post 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 56 times
Project:
MyExplorer.zip
(627.84 KiB) Downloaded 52 times
User avatar
Chris
Posts: 4832
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Porting VO Code

Post 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
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
Chris
Posts: 4832
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Porting VO Code

Post 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
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
markus.lorenzi@dvbern.ch
Posts: 113
Joined: Mon May 02, 2016 9:10 am
Location: Schweiz

Porting VO Code

Post 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 55 times
Documentation:
Project FeserExplorer.zip
(474.64 KiB) Downloaded 59 times
User avatar
Chris
Posts: 4832
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Porting VO Code

Post 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
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
Chris
Posts: 4832
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Porting VO Code

Post 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
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
Post Reply