Best way to convert a method of Class Control

This forum is meant for questions and discussions about the X# language and tools
Post Reply
ic2
Posts: 1856
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

Best way to convert a method of Class Control

Post by ic2 »

Last week I supervised the first steps to convert a large project from VO to X# which is maintained on site by one of my employees. They often use methods like this:

method ShowControl(lShow) CLASS Control
if lShow
self:Show()
else
self:Hide()
endif

return true

This makes it easy to quickly hide/show all controls in a screen.

In VOPorter this generates CLASS control_external_class INHERIT control which of course is not a solution to the problem.

Is there another way to solve this without creating subclasses for every type of control and changing 1000's of controls in 100's of windows to the inherited classes?

Dick
User avatar
wriedmann
Posts: 3748
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Best way to convert a method of Class Control

Post by wriedmann »

Hi Dick,
since this method is only using public methods of the class, you can use an extension method:

Code: Select all

static class ControlExtensions
static method ShowControl( self oControl as control, lShow as logic ) as logic
if lShow
  oControl:Show()
else
  oControl:Hide()
endif
return true
end class
HTH

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
ic2
Posts: 1856
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

Best way to convert a method of Class Control

Post by ic2 »

Thank you Wolfgang!

I've added your solution in my conversion documentation and my employee will apply it.

Dick
Post Reply