Miscellaneous questions about converting VO code to X#

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

Re: Miscellaneous questions about converting VO code to X#

Post by Chris »

Hi Kees,

OK, great, glad it works now!
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
Kees Bouw
Posts: 118
Joined: Wed Nov 06, 2019 11:35 am
Location: Netherlands

Re: Miscellaneous questions about converting VO code to X#

Post by Kees Bouw »

Hi all,

This may be a silly question, but I can't find any way to get a single control from a dialogwindow in X#. I know of the method GetAllChildren(), but I just want a single child, not all of them. I could supply a ControlID, a HyperLabel or the Name of the control. Something like oControl := oWindow:GetControl(Name). Traversing the array you get from GetAllChildren() every time and until you find the right one is too slow and a lot of code. Does anyone have a solution for this?

Kees.
User avatar
wriedmann
Posts: 3739
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Re: Miscellaneous questions about converting VO code to X#

Post by wriedmann »

Hi Kees,
I would do a subclass for this window, add a protected Dictionary<string,Control>, and use code like this:

Code: Select all

method GetControl( cName as string ) as control
local oReturn as Control
if _oControls == null .or. _oControls:Count == 0
  _oControls := Dictionary<string,Control>{}
  local aControls as array
  local nLen as dword
  local nI as dword
  aControls := self:GetControls()
  nLen := ALen( aControls )
  for nI := 1 upto  nLen
    _oControls:Add( aControls[nI]:Name:ToLower, aControls[nI] )
  next
endif
if _oControls:ContainsKey( cName:ToLower() )
  oReturn := _oControls[cName:ToLower()]
else
  oReturn := null
endif
return oReturn
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
Kees Bouw
Posts: 118
Joined: Wed Nov 06, 2019 11:35 am
Location: Netherlands

Re: Miscellaneous questions about converting VO code to X#

Post by Kees Bouw »

Wolfgang,

Thank you for this workaround, it looks very nice.

Kees.
User avatar
Kees Bouw
Posts: 118
Joined: Wed Nov 06, 2019 11:35 am
Location: Netherlands

Re: Miscellaneous questions about converting VO code to X#

Post by Kees Bouw »

Hi All,

The function GetThemeAppProperties() from VOGUIClasses "Retrieves the property flags that control how visual styles are applied in the current application", see https://learn.microsoft.com/en-us/windo ... properties.

This function returns 7 in VO. It also returns 7 in my X# VO MDI test application. However, in my X# Winforms application it returns 0.

Also, the function SetThemeAppProperties(STAP_ALLOW_CONTROLS) does not make GetThemeAppProperties() return 2 in X# Winforms as it does in VO and X# VO MDI.

I noticed that in the Winforms application are these (generated) lines in FUNCTION Start():

Code: Select all

Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(FALSE)
But removing one of these or both or setting the argument to TRUE does not make any difference.

Question 1: How can I make GetThemeAppProperties() and SetThemeAppProperties() work in a X# Winforms application?

Question 2: Almost all code and windows in the X# Winforms application are actually VO Forms. Is there a way to remove the Winforms code and effectively change the application to a X# VO MDI application?

Kees.
User avatar
Kees Bouw
Posts: 118
Joined: Wed Nov 06, 2019 11:35 am
Location: Netherlands

Re: Miscellaneous questions about converting VO code to X#

Post by Kees Bouw »

Another small question, there are a few places in my code where a DWORD or LONGINT is somehow converted into a structure like in this code (I have left out the irrelevant lines):

Code: Select all

METHOD Dispatch(oEvt, hDlg)

LOCAL pNMHDR				AS _winNMHDR

LOCAL lParam				AS DWORD

lParam := oEvt:lParam

pNMHDR := PTR(_CAST, lParam)

RETURN SUPER:Dispatch(oEvt)
On the line with the _CAST I get "Error XS0266 Cannot implicitly convert type 'ptr' to 'VO._winNMHDR*'. An explicit conversion exists (are you missing a cast?)"

I have read the chapter on casting in the X# book on https://docs.xsharp.it/doku.php?id=casting, at the bottom there is a link to a forum thread which does not work anymore. I must confess that I still do not understand how this is supposed to work, how can a number (a DWORD in this case) become a structure? Yet the code above worked in VO. What would be the safest way to make it work in X#?

Kees.
User avatar
Chris
Posts: 4811
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: Miscellaneous questions about converting VO code to X#

Post by Chris »

Hi Kees,

In that particular case the event object (I assume you have left out some code that checks which event is intercepted exactly) contains a pointer to the structure in the lParam numeric variable. Numerics can be converted to a pointer in a 32 bit application, since they both have the same length (4 bytes). The way to do it in X# is

pNMHDR := (_winNMHDR PTR) lParam

where "(_winNMHDR PTR)" is the "explicit conversion" (cast) that the error message mentions.

Sorry we did not get back to you yet about your previous question about themes, will look into it and will get back to you.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
robert
Posts: 4445
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: Miscellaneous questions about converting VO code to X#

Post by robert »

Kees,
Kees Bouw wrote: Thu Apr 11, 2024 8:43 am I must confess that I still do not understand how this is supposed to work, how can a number (a DWORD in this case) become a structure? Yet the code above worked in VO. What would be the safest way to make it work in X#?
A structure in VO (when declared with AS) is a pointer to a memory location. In a 32 bits application, a pointer occupies 32 bits.
Many Windows API functions pass a pointer in the LPARAM (LONG) or WPARAM (DWORD) fields of an event.
This fits perfectly.
That is also the reason why you cannot simply recompile the VO GUI classes in x64 bit mode, because pointers in 64 bits app occupy not 32 bits but 64 bits.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
Kees Bouw
Posts: 118
Joined: Wed Nov 06, 2019 11:35 am
Location: Netherlands

Re: Miscellaneous questions about converting VO code to X#

Post by Kees Bouw »

Chris and Robert,

Thank you very much for your answers! It works now.

(And yes, I am still interested in a solution for the Themes functions.)

Kees.
User avatar
Kees Bouw
Posts: 118
Joined: Wed Nov 06, 2019 11:35 am
Location: Netherlands

Re: Miscellaneous questions about converting VO code to X#

Post by Kees Bouw »

In the VO version of the app I am working on, I encountered a strange expression that is used a few times. It is the left side of this line:

Code: Select all

SELF:[PKey, #AUTNO] := nAUT
SELF inherits from DataDialog and nAUT is an integer. PKey is an (Exported) array and #AUTNO is just a symbol, other symbols are also used in the same expression.

This line does work in the VO version. The VOXPorter translates it into this:

Code: Select all

SELF:PKey[#AUTNO] := nAUT
But that gives the compiler error XS9059 "Cannot convert Array Index from 'symbol' to 'int'".

So I am curious what the VO version exactly means, if it is "valid" code (never seen it before) and how I can achieve the same in X#.

Kees.
Post Reply