Home General

IW + RichText + Template.LoadFormDatabase = Invalid Window Handle

edited March 2009 in General
D7, IW 8.0.22, RB 10.09

I am getting an the following error:
System Error. Code: 1400.
Invalid window handle.

This error arises after while calling Report.Template.LoadFromDatabase when
a report containing a RichText component has previously been loaded into the
report template. It appears that this exception is being raised when the
RichText component is being freed. This is just a standard IW app form with
a TppReport component placed on the form at design time. I can get the
error to happen when the first report template is loaded if I add a RichText
component to the report at design time.

Here is the call stack information:

Call Stack Information:
---------------------------------------------------------------------------------------
|Address |Module |Unit |Class |Procedure/Method
|Line |
---------------------------------------------------------------------------------------
|Running Thread: ID=4400; Priority=0; Class=TInThreadWithTask
|
|-------------------------------------------------------------------------------------|
|00686E51|eFormsWeb.exe|ppRichTx.pas |TppCustomRichText|Destroy
|582[4] |
|00686E40|eFormsWeb.exe|ppRichTx.pas |TppCustomRichText|Destroy
|578[0] |
|006881FD|eFormsWeb.exe|ppRichTx.pas |TppRichText |Destroy
|1533[5] |
|006EA50E|eFormsWeb.exe|ppClass.pas |TppBand |Destroy
|5731[13] |
|006EA4CC|eFormsWeb.exe|ppClass.pas |TppBand |Destroy
|5718[0] |
|00674932|eFormsWeb.exe|ppBands.pas |TppCustomBand |Destroy
|3166[8] |
|006748F8|eFormsWeb.exe|ppBands.pas |TppCustomBand |Destroy
|3158[0] |
|00672337|eFormsWeb.exe|ppBands.pas |TppBasicBand |Destroy
|924[6] |
|00672314|eFormsWeb.exe|ppBands.pas |TppBasicBand |Destroy
|918[0] |
|00672F90|eFormsWeb.exe|ppBands.pas |TppDetailBand |Destroy
|1638[6] |
|006E816E|eFormsWeb.exe|ppClass.pas |TppCustomReport |FreeBandsAndGroups
|3797[10] |
|006E8124|eFormsWeb.exe|ppClass.pas |TppCustomReport |FreeBandsAndGroups
|3787[0] |
|006E658D|eFormsWeb.exe|ppClass.pas |TppCustomReport |Destroy
|2429[27] |
|006E652C|eFormsWeb.exe|ppClass.pas |TppCustomReport |Destroy
|2402[0] |
|006B5876|eFormsWeb.exe|ppReport.pas |TppReport |Destroy
|906[21] |
|006A9B8A|eFormsWeb.exe|ppTmplat.pas |TppReportTemplate|LoadEnd
|2179[18] |
|006A8966|eFormsWeb.exe|ppTmplat.pas |TppTemplate |LoadFromStream
|1210[84] |
|006A86B5|eFormsWeb.exe|ppTmplat.pas |TppTemplate |LoadFromSource
|1103[63] |
|006A8444|eFormsWeb.exe|ppTmplat.pas |TppTemplate |LoadFromSource
|1040[0] |
|006A841A|eFormsWeb.exe|ppTmplat.pas |TppTemplate |LoadFromDatabase
|988[1] |
---------------------------------------------------------------------------------------

Thanks All,
Branden

Comments

  • edited April 2009

    RB Server Edition supports the use of RichText components. We are not aware
    of any issues.

    One possiblity is that you have a multi-threaded application and a different
    thread is destroying the window handle than the thread that created it.
    Windows requires that the same thread create and destroy the handle.


    --
    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited April 2009
    I can replicate this behavior by starting a new IW project, adding a
    TppReport component to the UserSession datamodule, add a RichText component
    to the report and add text to the RichText component, add a procedure to the
    public section called FreeRep and within the procedure simply call
    ppRichText1.Free or ppReport1.Free (they both produce the same result), next
    add a button to the main form (which is automatically created by IW when you
    start the new project) and add UserSession.FreeRep to the OnClick of the
    button. This takes my coding out of the mix and places the RB components in
    an environment that is proven thread-safe by IW. When you run the app,
    launch a web session, and click the button you get the "Invalid Window
    Handle" error.

    I did notice something peculiar in setting this test up though. Freeing the
    report/rich text only generates this error if you add text to the rich text
    component at design time. If you remove the text and recompile or simply
    delete the original and place a new one on the report, it frees without
    error.

    Any additional thought with this info???

    Thank you,
    Branden Johnson

  • edited April 2009
    Any ideas about my last post? I can't see how every other component on a
    report would be freed just fine if this were a thread issue. And even more,
    that it only happens when there is text in the RichText component.

    Thank you,
    Branden

  • edited April 2009

    RB Server Edition supports the use of RichText components. We are not aware
    of any issues. RB Server Edition is built using RB Enterprise - it uses the
    same report engine.

    We have customers using RB in other multi-threaded environments and no one
    has reported any issues.

    As a test try placing a Report a Delphi Web Broker app it should work fine.

    When testing, make sure that you do not have any RB add-ons in the mix.

    RichText is a different 'animal' from the others. Internally it relies upon
    Delphi's TRichEdit which is a wrapper around on the Windows RichEd.dll. Both
    TRichEdit and Windows RichEd.dll are designed to be "windowed conrols".

    TeeChart is also designed to be a wincontrol.

    I have not worked with IW any. However, I wrote most of RB Server and have
    quite a bit of multi-threaded experience. I know for a fact that if one
    thread creates a window handle and another thread free's the window handle,
    then you will get an error. This is docoumented by MS somewhere.

    You say the error only occurs when you have content in the RichText control,
    my guess is that when the RichText is empty, no window handle is created. It
    is created upon demand.


    --
    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
This discussion has been closed.