SystemMenuClose etc

Public support forum for peer to peer support with related to the Visual Objects and Vulcan.NET products
Anonymous

SystemMenuClose etc

Post by Anonymous »

Probably a very simple problem, followed by an "interesting" note

Where do I put the following VO code in an X# app please?

METHOD ExitButton( ) CLASS MainMenu
Local oTb as TextBox
oTb := TextBox{self, cAppVersion, "Do you really want to quit?"}

oTb:TYPE := BOXICONQUESTIONMARK + BUTTONYESNO

IF (oTb:Show() = BOXREPLYYES)

self:Close()
App{}:Quit()
RETURN true // Quit application.

ELSE

RETURN FALSE

// Don't quit the application.

ENDIF

RETURN NIL

I can't seem to find it anywhere. I've tried in a few places and the app either crashes with a dialog box, or does nothing..

I'll also be looking to do a similar thing with closing windows, but I'm assuming that'll just be self:EndWindow() or similar.


NOTE: EVERY time I hit COMPILE, I get the following:
error XS2012: Cannot open 'C:XIDEProjectsTest ProjectBinDebugMdiApp1.exe' for writing -- 'The process cannot access the file 'C:XIDEProjectsTest ProjectBinDebugMdiApp1.exe' because it is being used by another process.'

Sometimes I need to hit the compile button 2 or 3 times before it will compile properly. I can read what the message says, but is it something I'm doing or a switch I need to set somewhere?
User avatar
lumberjack
Posts: 727
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

SystemMenuClose etc

Post by lumberjack »

BiggyRat wrote:Probably a very simple problem, followed by an "interesting" note
Where do I put the following VO code in an X# app please?
I can't seem to find it anywhere. I've tried in a few places and the app either crashes with a dialog box, or does nothing..
I'll also be looking to do a similar thing with closing windows, but I'm assuming that'll just be self:EndWindow() or similar.
Sometimes I need to hit the compile button 2 or 3 times before it will compile properly. I can read what the message says, but is it something I'm doing or a switch I need to set somewhere?
Hi Jeff, I assume this is a VO application and not a .NET compliant one. You should have it as per the MDI application template, sorry easiest way of saying it. Should be the same as in VO, but the MDI VO template should run as is.

.NET and WinForms have a bit of different way of doing things.

See this pseudo hand written example:

Code: Select all

FUNCTION Start() AS VOID
  VAR oForm := MyFirstXSharpForm()
  Application.Run(oForm)
RETURN

CLASS MyFirstXSharpForm INHERIT Form 
  CONSTRUCTOR()
    SUPER()
    Size := Size{100, 100} // Check if it is not dimension, out of top of my head
    Text := "My first XSharp Form"
    VAR btn := Button{}
    btn:Text := "Close"
    btn:Location := Point{5,5}
    btn:Click := MyButtonClick  // what the click event will fire
    SELF:Controls:Add(btn)
  RETURN
  METHOD MyButtonClick(o AS OBJECT, e AS EventArgs) AS VOID
    SELF:Close()
  RETURN
END CLASS
Regarding the "locking" issue. I reported it to Chris quite a while ago and in his environment cannot reproduce. It is almost as if the compiler is slow in releasing and exiting when you have an error. I found it to happen when I have the /ppo switch on while UnitTesting #command implementations.
HTH,
______________________
Johan Nel
Boshof, South Africa
User avatar
Chris
Posts: 4906
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

SystemMenuClose etc

Post by Chris »

As Johan says, it should work exactly the same way as in VO, if you find anything that behaves in a different way in X# than in an equivalent VO app, then this is a bug, please report it to us.

Can you please explain exactly what you want to do, when do you want to exit the app? The method is named "ExitButton", which suggests you want to respond to a button click, but you are using the menu class, so maybe you just want to exit from a menu option instead? I'd say do the same thing in VO, to avoid any complexities coming from a new environment to you, and when you have it working as you expect in VO, just do the same in the X# app as well.

About the message that the file is in use, this seems that the app hasn't closed yet, after you run it. Possibly it is not visible, but it is still running for some reason. When it finally shuts down, you can now compile the app again with no problem. Please go to Tools->Preferences in XIDE, Compiler page, check the "Check if running before compile" checkbox in the bottom right, this should make XIDE check for the app already running in advance, before calling the compiler.

Chris
Chris Pyrgas

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

SystemMenuClose etc

Post by wriedmann »

Hi Jeff,
if you would like to put that code in a VO GUI Classes application, the ShellWindow would be the main window class.
And to stop a window from closing, you can ovveride the QueryClose() event method:

Code: Select all

METHOD QueryClose(oEvent)
local oTB as TextBox

oTB := TextBox{SELF, "Quit", "Do you really want to quit?"}
oTB:TYPE := BOXICONQUESTIONMARK + BUTTONYESNO
IF (oTB:Show() = BOXREPLYYES)
  RETURN TRUE // Quit application.
ELSE
  RETURN FALSE
  // Don't quit the application.
ENDIF
Wolfgang

P.S. this code comes from the VO GUI classes help:
QueryClose.png
QueryClose.png (115.29 KiB) Viewed 647 times
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
BiggyRat

SystemMenuClose etc

Post by BiggyRat »

Thanks Johan, Chris and Wolfgang. That code I ripped right out of the VO manual years ago, and currently use it for the EXIT button on the main menu of one of my apps. I also have a similar one that pops up with an "Are you sure" when closing other windows (Data, Shell etc)

What I wanted to know was WHERE in the X# code do I put my "Are you sure?" code? In VO it was in the QueryClose() method of the window. I cannot find such a Method in X#. Do I need to write one? I can see Closed() and Closing() but no Closed or QueryClosed.
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

SystemMenuClose etc

Post by wriedmann »

Hi Jeff,
with X# you can use the VO GUI classes, then you need the QueryClose() method.
Or you can use the WinForms classes - I need to check it out.
Or you can use the WPF classes, with another method.
What GUI classes do you are using? The X# sample "Standard VO MDI X# runtime" uses the VO compatible GUI classes, therefore you need the QueryClose() method.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
BiggyRat

SystemMenuClose etc

Post by BiggyRat »

Ok, thanks Wolfgang. :) I'm trying to break the VO paradigm really. I'd like to use the "new and improved VO" - X# methods instead. I'd like to ask a user do they really want to "close this window" or "close the app" etc using X# coding.

Another thing that I can't really get my head around - PARTIAL Classes - what are they? Surely you have a Class, or you don't?
User avatar
robert
Posts: 4520
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

SystemMenuClose etc

Post by robert »

Jeff,
BiggyRat wrote:Probably a very simple problem, followed by an "interesting" note

NOTE: EVERY time I hit COMPILE, I get the following:
error XS2012: Cannot open 'C:XIDEProjectsTest ProjectBinDebugMdiApp1.exe' for writing -- 'The process cannot access the file 'C:XIDEProjectsTest ProjectBinDebugMdiApp1.exe' because it is being used by another process.'

Sometimes I need to hit the compile button 2 or 3 times before it will compile properly. I can read what the message says, but is it something I'm doing or a switch I need to set somewhere?
This usually means that the app has not closed properly and is still running. Considering that you are working on code that needs to quit the application that would make sense.
There is not much that we can do about this. I would use taskmanager or process explorer to kill the running app.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
robert
Posts: 4520
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

SystemMenuClose etc

Post by robert »

Jeff,
PARTIAL classes allow you to spread the contents of a class over multiple source files.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
lumberjack
Posts: 727
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

SystemMenuClose etc

Post by lumberjack »

Hi Jeff,
BiggyRat wrote:Ok, thanks Wolfgang. :) I'm trying to break the VO paradigm really. I'd like to use the "new and improved VO" - X# methods instead. I'd like to ask a user do they really want to "close this window" or "close the app" etc using X# coding.
Another thing that I can't really get my head around - PARTIAL Classes - what are they? Surely you have a Class, or you don't?
First paradigm shift, you need to clearly specify your "Environment". I am trying to make this VO code work on a WinForm:

Code: Select all

My VO code that I want to do on a WinForm(DOTNET)
I for one did not know why you don't get that code running, just copy it onto the VOForm you need it.... ;) Ok a joke I assumed you wanted to have a similar behaviour on a SystemWindows.Forms.Form object.

Code: Select all

using System.Windows.Forms
FUNCTION Start() AS VOID
  LOCAL oForm AS Form
  oForm := MyForm{}
  Application.Run(oForm)
RETURN
CLASS MyForm INHERIT Form
  CONSTRUCTOR()
    SUPER()
    SELF:InitializeForm()
  RETURN
  METHOD InitializeForm() AS VOID
    // Inside here you might probably have a Close button, menu with with Close option.
    // Both work the same they have a click event.
    LOCAL oCtrl AS Control
    oCtrl := Button{}
    oCtrl:Click := CloseClickEvent
    oCtrl := ToolStripMenuItem{}
    oCtrl:Click := CloseClickEvent
  RETURN
  METHOD CloseClickEvent(o AS OBJECT, e AS EventArgs) AS VOID
    IF MessageBox.Show(;
         "Are you really wanting to close the form?", "Question", ;
         MessageBoxButtons.YesNo, MessageBoxIcon.Question;
    ) == DialogResult.Yes
      SELF:Close()
    ENDIF
  RETURN
END CLASS
HTH,
______________________
Johan Nel
Boshof, South Africa
Post Reply