The best thing to do is to check every time you run the app to see if the database file has already been copied from the app bundle (or folder) into a target folder that doesn’t have an access problem when it is time to use the database. They are many reasons you shouldn’t do that, notably because the database would be open in read/write mode and if you write to that database file inside an application bundle, then you’d be modifying a resource and that would invalidate any certificate signature on your app. You may think that adding a Build Step is all you need to do, because if the database file is already copied to a well known path then you only need to provide that path as the DatabaseFile property on a new SQLiteDatabase instance. Copying the Database File to a “Working” Folder The WebCanvascontrol is used for drawing graphics in web apps.2. It takes advantage of the HTML5 Canvas making it fast and powerful. Sometimes is can be useful to be able to save the graphics drawn in the WebCanvas to an image file, but unfortunately there is no built-in Xojo method to do this. However, by using a little JavaScript you can easily add this capability to Xojo. In order to follow this tutorial, create a new Webproject and add a new WebCanvascontrol from the Library to the default Web Page added to the project: Web. Use the following code to draw a black colored rectangle: g.FillRect 0, 0, g.Width, g.Height With the WebCanvas selected in the Navigator, change its name to cCanvasusing the Inspector and add the PaintEvent Handler to it using the Insert > Event Handleroption from the menu. For example, we can draw a picture added to our project (with the filename “landscape”), using this line of code in the Paint event of our cCanvasinstance: g.DrawPicture landscape, 0, 0, g.Width, g.Height Retrieving the WebCanvas image data Obviously, you can draw anything you want in the WebCanvas or even painta picture on it. The first interesting step is retrieving the underlying image represented by the WebCanvas and that is something we can get using a fragment of JavaScriptcode executed from the Xojo side. This is the process we will execute from the ActionEvent Handler of a WebButtonadded to the Webfrom the Library. Js.Append "var img = canvas.toDataURL(""image/png base64 "") " // We access to the image data, encoded as a base64 string Js.Append "var canvas = document.getElementById('" + cCanvas.ControlID + "_canvas') " // We get the item reference based on its ID Once the WebButton has been added to the WebPage from the Library, put the following code in its ActionEvent Handler: Dim js() As String In fact, this will be the button in charge of calling the process to save the image as a picture file on the user disk. Js.Append "=img" // We assign that data to the document Hash property, so we can retrieve it from the Xojo sideĮxecuteJavaScript execute // Finally, we execute the JavaScript codeĪs you can see, the first line of the JavaScript code is in charge of retrieving the cCanvasreference from the DOM (document object model) of the Web Page. For that, we use the ControlIDproperty on our WebCanvas instance, adding the “canvas” appended by Xojo to all these kind of objects when generating the source code for the page. Once we get the reference to our Canvas instance, the following line of code retrieves the picture content itself and assigns it to the imgvariable. The trickhere is that we retrieve that information in its URL format and, thus, encoded as Base64data that we can assign to other document properties without losing its original meaning. Then, we assign the data to the document Hashproperty. This is the property that allows us to jump to other page sections previously tagged.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |