How to query the WindowState of a form?

Posted by arjenmeijer on 25-Oct-2011 01:35

When i try to query the WindowState of a .NET form i have trouble getting the correct answer (in the resize event of the form).

The following example allways ends in the otherwise.

case WindowState:
 when System.Windows.Forms.FormWindowState:Maximized then 
  ..
 when System.Windows.Forms.FormWindowState:Minimized then
  ..
 when System.Windows.Forms.FormWindowState:Normal then
  ..
 otherwise
  ..
end case.

WindowState:ToString() gives the same results.

Why? What do i miss in here?

All Replies

Posted by Admin on 25-Oct-2011 01:52

case WindowState:

when System.Windows.Forms.FormWindowState:Maximized then

>  ..

By doing so you will always be comparing the reference (handle value), not the referenced object (enum value). And in this case there are two different references. The proper way to compare Enum values if the Progress.Util.EnumHelper (check the GUI for .NET Programming handbook for details).

So it's not possible to use Enums in a CASE statement properly. Well, some folks might suggest an ugly

CASE TRUE:

WHEN EnumHelper:AreEqual (WindowState, System.Windows.Forms.FormWindowState:Maximized)

But I'd rather go for an IF THEN ELSE structure.

If you want to influence the future of the ABL, don't miss the "OpenEdge Development Language and Tools Info Exchange" at the EMEA PUG Challenge in Amsterdam, next week.

http://www.pugchallenge.eu/index.php?option=com_content&view=category&layout=blog&id=18&Itemid=96

Posted by arjenmeijer on 25-Oct-2011 04:56

Thank you for your help. My problem is solved.

It is a pity you need a helper class for this, unlike in C#. This makes converting good C# examples on MSDN more difficult (and we don't do too much with .NET). Unfortunately i can't be at the EMEA PUG challenge this year because i have a hospital appointment for one of my daughters that day.

Posted by Admin on 25-Oct-2011 06:27

This makes converting good C# examples on MSDN more difficult (and we don't do too much with .NET

C# uses operator overloading with Enum's which the ABL does not support.

Good thing is, there are not that many things and once you've got your bloody nose form the Enums, you'll remember next time. (The other thing is not to always rely on automatic boxing and unboxing, especially on numeric types).

Posted by rbf on 25-Oct-2011 07:20

Mike,

Just to get this straight:

Are these things that PSC could fix for us in the ABL if they wanted do:

- remove the need for using Progress.Util.EnumHelper for comparing Enum values

- remove the need for BOXing en UNBOXing in the ABL?

Just trying to decide on my votes together for the he "OpenEdge Development Language and Tools Info Exchange" at the EMEA PUG Challenge in Amsterdam, next week.

-peter

Posted by Admin on 25-Oct-2011 07:42

Are these things that PSC could fix for us in the ABL if they wanted do:

I don't know the internals, but definitively yes on the first and probably on the second. Issue with boxing is, that ABL primitives are definitively something different than .NET primitives that can seamlessly be turned into their object-equivalent.

But who am I to answer this?

Posted by Shelley Chase on 25-Oct-2011 08:52

I can confirm Mike's suspicions. Enums are something we would like to introduce into the language and is certainly possible. Always getting automatic boxing is not possible (well anything is possible but the complexity and performance overhead to accomplish this makes it very unattractive IMO).

-Shelley

This thread is closed