Home End User
New Blog Posts: Merging Reports - Part 1 and Part 2

Mechanism to cancel a query

edited June 2003 in End User

Hi,

I am using RB 6.03 with a custom ODBC TDataset and DBPipeline.

With the end user query designer the user can easily create a query that
is very time consuming, which ends up calling TDataset.Open.

With ODBC it is possible cancel a query request. Is there a mechanism in
RB for such a cancel? The problem I am having is that the report
designer can hang in preview mode for minutes (even hours) and the user
interface is unresponsive. Would someone have any suggestions on how to
handle this?

Thanks,

Michel

Comments

  • edited June 2003
    You can use the OnCancel event of the report to detect when the user presses
    the cancel button in the preview.

    If that doesn't work, then you can create a custom preview plugin that can
    provide the ability to do this in the OnClick of the cancel/close button in
    your TppPreview descendent. Here is an example of a custom preview to add a
    new button. All you want to do in your descendent is to override the Cancel
    method though to make a call to access you ODBC connection to cancel the
    query.

    http://www.digital-metaphors.com/tips/AddControlsToPreview.zip

    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited June 2003

    Thanks! That is plenty of information to get going.

    Michel

  • edited June 2003

    Hi Jim,

    I have advanced quite a bit now...

    I am running my query in another thread to that it maybe cancelled.
    Although I am fighting with some ODBC drivers which don't want to cancel
    a query, this is working rather well.

    So will the query is executing in another thread in
    TDataset.InternalOpen I call Application.ProcessMessages in a loop and
    the report designer is responding. I confirmed that the report designer
    is responding because I can display the about box while the query is
    executing in another thread.

    The only problem is I can press the Cancel button (visually I see it
    depressed), but the Report.OnCancel event is not triggered. For testing
    I have been using a timeout in the ProcessMessages loop and it cancels fine.

    Would you have any idea why the OnCancel event does not trigger in this
    situation.

    Best regards,

    Michel





  • edited June 2003

    Hi,

    Maybe this will help find the problem.

    When the Cancel button is pressed on the Preview here is the sequence of
    calls:

    TppPreview.ToolButtonClickEvent
    TppCustomPreview.PerformPreviewAction
    TppCustomPreview.Cancel
    TppViewer.Cancel
    TppScreenDevice.Cancel
    TppReport.Cancel

    but in TppReport.Cancel

    if (FActiveReport <> nil) and (FActiveReport <> Self) then
    FActiveReport.Cancel;

    FActiveReport is nil, so the processing stops.

    I was not able to find out where FActiveReport is supposed to be set. It
    seems that it is set to nil in the constructor, and then never assigned.

    I did a global search in the code an the only place where ActiveReport
    is assigned seems to be in ppSubRpt.Pas, so I am not sure where to go
    from here.

    Thanks again,

    Michel




  • edited June 2003
    Ok, create a preview plugin that sends a notification in the cancel click.
    This way you don't have to rely on Report.OnCancel being triggered. Here is
    one simple example of a custom preview replacement.

    http://www.digital-metaphors.com/tips/CustomPrintFromPreview.zip

    Modify this example to only have one routine which is to override the Cancel
    method and send a message to perform the cancel from that method.

    Look in RBuilder\Source\ppPreview.pas for the ancestor interface in the
    TppCustomPreview class for more info.


    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited June 2003

    Hi Jim,

    I understand this is a workaround, but all I want is to have the
    OnCancel event work. I don't need to create a custom preview.

    All I added in TppReport.Cancel is,

    if Assigned(TNotifyEvent(OnCancel)) then
    OnCancel(Self);

    which seems quite logical and seems to work fine.

    But I don't like patching third party libraries because it will cause
    problems when the library is updated.

    Any chance of having this fixed, rather than having to create a custom
    preview to get the OnCancel event working.

    Thanks,

    Michel


  • edited June 2003
    Sorry, I looked at the code and I suggested using the OnCancel when I
    shouldn't have, based on the current context for the OnCancel event which is
    for printing only. There is a cancel dialog when printing to the printer
    which is responsible for the OnCancel event being triggered. The cancel
    button in the preview doesn't trigger the OnCancel as I thought it should.
    Since the context of the cancel is different and the device is different, we
    can't trigger the OnCancel in the preview cancel button's click event, as
    this may break code out in the field where other customers are relying on
    this assumption in their OnCancel event handlers. The solution is to use a
    preview plugin replacement or for you to continue using the modified source
    to trigger the OnCancel event.

    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited June 2003

    Ok, thanks.

    I'm just trying to make my life simpler as my todo list is growing
    faster than the work being done.

    Michel

This discussion has been closed.