property ExPrint.AutoRelease as Boolean
Specifies whether the print object is released automatically.

 TypeDescription 
   Boolean A Boolean expression that specifies whether the Print object is released automatically when it is not required anymore.  
By default, the AutoRelease property is True. If the AutoRelease property is True, the print object is released as soon as the control to be printed is not available anymore, of the user closes the Preview's frame. The AutoRelease on False, indicates that the print object is released as soon as the user closes the Preview's mainframe. Setting the AutoRelease property on False, has effect only if called before Preview method. 

The AutoRelease property on False, is useful, if you create the Print object locally at runtime. If created locally, the Print object is released when it is out of scope, or when the procedure ends. 

For instance, in the following VB6 sample the user creates a Print object as a local variable, and so the object is released as soon as the Form_Load ends. In other words, you will notice that the Preview window is opened and closed quickly, as it is closed because the Exontrol.Print object is released as soon as the Form_Load function ends. 

Private Sub Form_Load()
    With CreateObject("Exontrol.Print")
        .PrintExt = G2antt1.Object
        .Preview
    End With
End Sub

This problem can be solved in 2 ways:

as shown in the following samples:

Let's use the AutoRelease property, so the code is like follows. This time, if running the sample, the Preview window will be shown, and the Exontrol.Print object is released as soon as the user closes the Preview's mainframe.

Private Sub Form_Load()
    With CreateObject("Exontrol.Print")
        .AutoRelease = False
        .PrintExt = G2antt1.Object
        .Preview
    End With
End Sub

And another solution is declaring a public member of Exontrol.Print type, so it will be available, as form lives as described bellow. This time, if running the sample, the Preview window will be shown, not closed, as the object p is released ONLY when closing the form.

Dim p As Object
Private Sub Form_Load()
    Set p = CreateObject("Exontrol.Print")
    With p
        .PrintExt = G2antt1.Object
        .Preview
    End With
End Sub

 


Send comments on this topic.
1999-2017 Exontrol.COM, Software. All rights reserved.