Jump to content

CWBudde

Members
  • Content Count

    330
  • Joined

  • Last visited

2 Followers

About CWBudde

  • Rank

  • Birthday 01/17/1980

Contact Methods

  • Website URL
    http://www.pcjv.de

Profile Information

  • Gender
    Male
  • Location
    Germany

Business

  • Sector
    Government

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. CWBudde

    Search result (files) in it's own panel

    This has already been implemented, but maybe not included in the last release.
  2. CWBudde

    PhoneGap / Cordova: How to use PlugIns?

    Not for PhoneGap. However, I can send you a file for Cordova though (I have no permissions to attach it to this post). Also you might want to read more here.
  3. CWBudde

    PhoneGap / Cordova: How to use PlugIns?

    That's what I meant. The Cordova.js file is nothing you have to take care for (hence the need to remove the {$R ..} line). You only need to have a link in your HTML file or script that link in with the snippet I posted earlier. In my case I have added this somewhere in the .spr file.
  4. CWBudde

    PhoneGap / Cordova: How to use PlugIns?

    Sorry, I didn't want to confuse you with my suggestions. Typically it's either to us PhoneGap (which is based on Cordova, but made simple) or Cordova directly. The latter is a bit more down to the metal as opposed to PhoneGap. One advantage of Cordova over the PhoneGap build service is the fact that you can run it locally on your machine (PhoneGap itself will run locally as well, but still might access to the cloud). This makes working with Cordova potentially faster and more independent. This said, both are more or less controlled by the same config.xml, which should reside in the same directory of the .sproj file (after you have enabled to generate that file, if missing). Judging from the error, it seems that either Cordova or Node.js might not be available in the latest version or might have not setup properly, so maybe the PhoneGap build service is a better alternative here. It's just that I'm not experienced with it, so I might not help further in this regards. Either way, I would recommend to remove the {$R cordova.js} and the library from the www folder. It will be added by Cordova / PhoneGap at the build stage. What needs to remain however is the link to the file (even if it's not present). The above (async) snippet might cause a warning if the loading fails, but should also work fine in the browser. If the file is present however, it will load the library and fire the 'deviceready' event.
  5. CWBudde

    PhoneGap / Cordova: How to use PlugIns?

    It is possible to target the browser as platform. However it can not go beyond the security limits of a browser. So it might be of limited use. In order to use Cordova you have to indeed link to the Cordova API. However, the cordova libraries are typically copied by Cordova itself. The code below should be satisfying to link the Cordova library (if present): uses W3C.HTML5; // load Cordova library asynchronous var CordovaScript := JHTMLScriptElement(Document.createElement('script')); CordovaScript.&type := 'text/javascript'; CordovaScript.async := true; CordovaScript.src := 'cordova.js'; Document.body.appendChild(CordovaScript); After you have checked the 'Generate Cordova config.xml' option in the Linker Options of your project you can already easily use Cordova directly. The following commands are needed. Run them in a console in the root directory of your project: npm i -g cordovato install Cordova globally. cordova add platform androidto add the Android platform cordova buildto build your Cordova app. Eventually you also need to add plugins to the project like this: cordova plugins add cordova-plugin-file
  6. CWBudde

    FileWriter

    If you only open the file (e.g. by drag & drop the file 'index.html' onto the browser) the file protocol will be used (i.E. 'file:///'). If you serve a file the browser uses the http / https protocol. Regarding PhoneGap / Cordova: It is possible to target the browser as platform. However it can not go beyond the security limits of a browser. So it might be of limited use. In order to use Cordova you have to indeed link to the Cordova API. However, the cordova libraries are typically copied by Cordova itself. The code below should be satisfying to link the Cordova library (if present): uses W3C.HTML5; // load Cordova library asynchronous var CordovaScript := JHTMLScriptElement(Document.createElement('script')); CordovaScript.&type := 'text/javascript'; CordovaScript.async := true; CordovaScript.src := 'cordova.js'; Document.body.appendChild(CordovaScript); After you have checked the 'Generate Cordova config.xml' option in the Linker Options of your project you can already easily use Cordova directly. The following commands are needed. Run them in a console in the root directory of your project: npm i -g cordova to install Cordova globally. cordova add platform android to add the Android platform cordova build to build your Cordova app. Eventually you also need to add plugins to the project like this: cordova plugins add cordova-plugin-file
  7. CWBudde

    FileWriter

    It's fine for me.
  8. CWBudde

    FileWriter

    Here are some reasons why it might work with some browsers and not with others: The internal browser has the least security restrictions. So if things work there it doesn't mean much. At the same time the internal browser is a bit outdated as the Chromium binaries equals to Chrome 39. This means some deprecated APIs might still be supported there while others (newer) might not be on board yet. When you use open in browser it runs your web-app in your default browser, but still serves the website from within Smart Mobile Studio. This makes a difference as the file access is still handled by Smart Mobile Studio. As opposed to this if you only open the html file in the browser directly (without serving the file) the highest security restrictions apply and thus it might not work at all. The same goes for IE or Safari if the file is not served. If you don't want to (or can't) serve the file with Smart Mobile Studio you can use any other serving tool. My personal favorite for this task is Browsersync. For PhoneGap / Cordova you should consider to install the console plugin. With this you can debug your Cordova application which runs on a different device. Just connect your device via USB, enable USB debugging, eventually start ADB (if not already running) and open the Chrome browser with chrome://inspect.
  9. CWBudde

    FileWriter

    Eventually, you must cast the class to the right type to make it work. Something like: var DataBlob := new JBlob(['some text'], JBlobPropertyBag(class &type = 'text/plain' end)); But I have to admit that it looks a bit ugly. The cast means something like: I take care that the code is formaly correct. However a type-safe alternative would be better. Something like: var BlobProperties: JBlobPropertyBag; BlobProperties.&type := 'text/plain'; var DataBlob := new JBlob(['some text'], BlobProperties); But it bloats the code and does not represent the nullable character of JavaScript (where you only need to specify the fields you want). Luckily in this case the latter has no effect because it's just one field here. Regarding the hex string to byte data conversion: There are many ways to achieve what you want. There's nothing bad in using the Delphi'ish approach. I didn't mean to rewrite the code based on the JUint8Array, but I wanted to mention that storing and handling blobs is better (in terms of memory usage) in this representation. It can also be useful if you want to mangle the data later... Better alternatives (leaving out the storage here) would be something like: function HexStrToByteArray(Text: String): array of Integer; begin while Length(Text) >= 2 do begin Result.Add(HexToInt(Text.Copy(1, 2))); Delete(Text, 1, 2); end; end; The result can then be converted to a JUInt8Array for further storage or processing.
  10. CWBudde

    FileWriter

    The reported error comes from the fact that 'type' is a keyword in Pascal. It has to be escaped. So the correct code would be: var DataBlob := new JBlob(['some text'], class &type = 'text/plain' end); You can create a JBlob directly from a JArrayBuffer, which is defined in W3C.TypedArray. Assuming that TByteArray = array of Byte this would probably translate to uses W3C.TypedArray, W3C.File; var UInt8Array := JUint8Array.Create(YourByteArray); var DataBlob := JBlob.Create([UInt8Array]); where the latter can be used directly by the write procedure. Btw. I would use the following overload instead: uses W3C.File; [...] procedure write(Text: String); overload; procedure write(Blob: JBlob); overload; [...] The reason: If you want to benefit from the static typing of Object Pascal you should avoid using Variant as much as possible as it does not contain type information. Without these the code suggestions won't work. If you use the JBlob type (from unit W3C.File) you can get access to the fields and methods from this class. Likewise it would make sense to use the JUint8Array to store your binary data as it stores the data in a packed way. In the underlying DWScript (and after compilation in JavaScript) the 'Byte' is otherwise not a Byte but an Integer / Number (stored internally with 64bits). So the size of the byte array will be 8 times bigger than needed. Just saying...
  11. CWBudde

    FileWriter

    First thing I noticed: You can get rid of the asm code section by writing something like the following: aOptions := class create = false; exclusive = false; end; But that's not a big deal, just might improve the legibility. If the file doesn't exist already you might need to set create to true, though. Next you may consider to remove the surrounding exception handler to defer the exception handling to the underlying browser / cordova. It might have a different (better) hint about the type mismatch. Typically this comes with the position of the error (of the JavaScript code). While it's different to read it might reveal the precise cause of the mismatch. Other than that the code looks OK. At least except for the fact that (at least for Cordova) it would expect binary data instead of a simple text. The Cordova specifications would expect something like: var DataBlob := new JBlob(['some text']); writer.write(DataBlob);It might be worth trying this.If this doesn't work you could try adding the mime type as well. Something like: var DataBlob := new JBlob(['some text'], class type = 'text/plain' end); writer.write(DataBlob);Otherwise you might end with a binary file instead of a pure text file.
  12. CWBudde

    FileWriter

    I just read it in detail right now. It's not correct how you call it. With: BrowserAPI.window.requestFileSystem(0,0,FileSystem.MyCreateFile(NIL),FileSystem.FileError(NIL)); you execute the function FileSystem.MyCreateFile(NIL) before doing anything else. It is passed with the parameter 'nil', so it's clear why the filesystem is not assigned. If you leave the parameter out it should work. Eventually you might need to add an '@' before the name. So something like: BrowserAPI.window.requestFileSystem(0, 0, @FileSystem.MyCreateFile, @FileSystem.FileError); might already do the trick.
  13. CWBudde

    FileWriter

    The unit W3C.File is a header for the File API (see https://www.w3.org/TR/FileAPI/) which only specifies a writer. In addition to this there is the deprecated unit W3C.FileSystem for the File-System API (https://www.w3.org/TR/file-system-api/). The latter is discontinued and thus deprecated. However you can find previous versions such as this: https://www.w3.org/TR/2012/WD-file-system-api-20120417/. As you can see it doesn't contain a writer either, but this does: https://www.w3.org/TR/2012/WD-file-writer-api-20120417/ This said, you can only use this in theory as the API has not been widely implemented so far (and won't ever, based on the working group notes). So it's likely that you need to use Cordova / Phonegap in case you need to write files. If the data you need to store is really little you can also consider to use web storage. I used this solely for all my needs so far. However, for binary data you might need to convert the data to base64 first. Not a big deal, but it might blow the amount of data to a size which is not supported anymore. Also you can't access the data (as files) from outside if needed.
  14. CWBudde

    FileWriter

    Have you tried setting the size parameter to any other value than zero? Something like: [...]window.requestFileSystem(0,1024*1024, ... It might also be worth to compare the PhoneGap header unit (which is already quite old) to the (also quite old and deprecated) unit W3C.FileSystem. The latter is a little bit more verbose and the base for the PhoneGap/Cordova code.
  15. CWBudde

    FileWriter

    I not an expert for PhoneGap, but I'm pretty experienced with Cordova (the underlying open source project) and there you need to add the file plugin first. Eventually this could be needed for PhoneGap as well.
×