Inserting Text to Data Aware Component

  • We're having trouble inserting text and pictures into your data aware component. We're using C++Builder6 and your latest download.

    If we type into the component, the text appears and it can be saved to the database with a post and retrieved with a refresh.

    If we insert text or pictures with code, the items appear and we can use the SaveToFile to write an rtf file that shows the new information. However, if we attempt to post to the database, when we retrieve the information it is lost.

    It would appear that the same things are not written to files as are posted to the database. Something must be out of synch between the canvas and the rtf or who knows what.

    Can you reproduce this error? Is this something that will be fixed in an update soon?

    In the meantime, can you suggest some kind of work around such as making an assignment before posting? If so, please provide code for C++Builder.

  • Zitat von wpsupport

    Hi,

    If you need to create text programatically do not use the DB control. Use the STD control and assign the creates text using property AsString.

    Before changing the text in the DB control call function 'Changing()'.

    Julian Ziersch

    so there is something broken in the DB control. okay. can you be more specific about how to use the STD control. I take it you are suggesting we would create the text in an unbound control and then before posting simply assign some text property from the control to the field in the table. could you provide a C++ code fragment so we will know exactly what to assign to what.

    if an assignment will fix it, could we not use the DB control and put the same assignment into the before post event? since we can use the saveFile method of the DB control effectively, the text must be inserted into some property of the control. our theory is that the saveFile is saving something different from the post().

    • Offizieller Beitrag

    Hi,

    >>so there is something broken in the DB control. okay. <<

    I think it is more the concept of the datasensitiveness: The first time a change is announced (function changing()) the database will be reset, the memo will be reloaded. That is not optimal if you have a large blob, maybe with images.

    >> can you be more specific about how to use the STD control. I take it you are suggesting we would create the text in an unbound control and then before posting simply assign some text property from the control to the field in the table. could you provide a C++ code fragment so we will know exactly what to assign to what.<<

    I do not have a C** fragment but I guess it is the the same in Delphi:

    in OnScroll (event of the DataSet) do this:

    WP.AsString = Field.AsString;

    in BeforePost do this:

    Field.AsString = WP.AsString;

    Kind Regards,

    Julian Ziersch

  • We've discovered part of the problem. It turns out that you can insert even when the dataset is not in edit or insert mode without the component throwing an exception and stopping you. The material gets inserted into the displayed rtf and the problem doesn't appear until you post and discover that your inserted material wasn't saved. Shouldn't changing() put the dataset into the proper mode?

    We're going to make a test project to simplify the problem and see if we can get text and an image inserted and saved into the same blob field. We sure could in version 3 but it's beginning to look like we may have pulled some tricks to get it to work and the tricks are confusing things with version 5. For example, we found a post() statement in a strange place in the code. It really doesn't logically belong where we found it but the code sure works better with it there. We'll start from scratch in the text project and see if we can get things working without all the bells and whistles that our real project requires.

    We'll report back. In the meantime, you might check to see if we are right about the dataset not being put into edit mode or perhaps more importantly that you can insert in browse mode without getting an exception.

  • Even the simplest test project with a data aware component will not save and retrieve a rtf after text and/or pictures are inserted. this worked in version 3 but simply doesn't work in 5.

    We then tried an unbound component which loaded and saved from a file. That works perfectly.

    We then tried to assign the text.asString to the field.asString per your suggestion and while the "text" portion works fine everything from the picture on is lost. Clearly an assignment using the asString version will not work when the rtf contains an image. If you can suggest a different way to make the assignment to the field, we'll try it.

    Otherwise, we're inclined to dump the database entirely and simply store the rtf files individually. Storing the rtfs as blobs in fields of a dBase file had some adverse side affects anyway as we have learned the database is very fragile. repeated changing of the fields eventually corrupt the database.

    • Offizieller Beitrag

    Hi,

    >>Even the simplest test project with a data aware component will not save and retrieve a rtf after text and/or pictures are inserted. this worked in version 3 but simply doesn't work in 5. <<

    I asume a problem with binary data. Please change property TextSaveFormat to 'RTF-nobinary'. (in Form.OnCreate for example)
    Also see FAQ: http://wpcubed.com/forum/viewtopic.php?t=1217

    This is not with all database, just those which do not allow binary data in strings.

    Julian Ziersch

  • Zitat von wpsupport


    >>so there is something broken in the DB control. okay. <<

    I think it is more the concept of the datasensitiveness: The first time a change is announced (function changing()) the database will be reset, the memo will be reloaded. That is not optimal if you have a large blob, maybe with images.

    How can the problem be in the database when it worked for us with your version 3? In any event, we've spent all the time we can afford and more trying to make this work. We're pretty sure the problem has something to do with the database staying in browse mode and the component not throwing an exception when you insert data. Perhaps the problem is in the autoedit code. If you come up with an update that you'd like us to test, drop us an email and we'll be happy to try it. However, we don't see the point in using a non-dataaware control and trying to keep it manually synched with a database. If we have to use an unbound control to insert properly, we're just going to abandon the database and store the rtfs in individual flat files. that works.

    • Offizieller Beitrag

    Hi,

    I noted that it often is required to set the property
    TextSaveFormat to 'RTF-nobinary';
    Also possible is 'AUTO-nobinary' - which will be the default setting in next release.

    If you use TextObject.Insert you will need a DBWPRichText.Changing; before that. This is called by InsertGRpahicDialog automatically.

    With that it works in my tests. The DB control uses quite the same logic as V3.

    Julian

  • Does your test include saving the changes to the database and getting them back? That's what isn't working for us.

    We made a very simple test project with a table, a navigator (with edit, save, refresh), a wp component, and buttons with events that did changing(), insert text, and insert picture. We tried it with autoedit on and off. We tried clicking the buttons in different orders. We could get the text and picture into the control. We could not save and retrieve it from the database. We can save and retrieve the changes from an rtf file. I recognize that it is quite possible we are making a mistake, but the material does save properly to a file.

    As I said before, we think the problem has something to do with the edit/browse state. If we just type into the component, we can save and recall the information correctly. However, material inserted via code does not save in version 5 and it saved in version 3. It's like the inserted code is going into something that appears on the screen and is saved to file but is not the same something that is written to the database. The debugger shows us that the table is in the browse state during insert.

    Maybe it's a C++ problem that doesn't appear in your Delphi test. It's a holiday here so we can't test anything until tomorrow. I'm sure we've already done the changing() and the no-binary but we'll take a quick look again tomorrow.

    If you can't reproduce the problem, we could probably email you something.

  • Hi all,
    I´ve followed your discussion and I would add my own expirience with this problem:
    We ´ve encountered the same problem on Delphi and using an Oracle 9 DB behind, it´s not a C++ stuff only. We are using the unbound component and assign it manually by AsString to the dbfield.

    we have to confirmed also what Frank is saying: on Version 3 and even 4 the same code which was worked well, now discards every image you ´re putting on the text. Saving on file works instead.

    There must be really some bug inside the V5.
    regards

    Andy
    Replica Development Srl

    • Offizieller Beitrag

    Hi,

    in a non trivial application do NOT use the data senstive control, use the TWPRichText instead. You only need to assign two events, OnScroll and BeforePost

    If an image does not get posted it is usually the binary format which is not saved by the database. Switch to Ansi only using the property WriteObjectMode = wobRTFNoBinary.

    Julian