Jump to content

CWBudde

Members
  • Content Count

    330
  • Joined

  • Last visited

Everything posted by CWBudde

  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.
  16. CWBudde

    FileWriter

    What have you done so far? What version of PhoneGap are you using? What platform?
  17. CWBudde

    How to work with JSON data?

    The JSON data can directly be used as an object. If, for instance, your data looks like this: { "Foo": "Bar" } you can write something like: uses ECMA.JSON, W3C.Console; [...] var Data := JSON.Parse(http.ResponseText); Console.Log(Data.Foo); which would write 'Bar' to the console. If you want to use type information, you can write something like this: uses ECMA.JSON, W3C.Console; type JFooBar = class external Foo: String; end; [...] var Data := JFooBar(JSON.Parse(http.ResponseText)); Console.Log(Data.Foo); The advantage of this approach is the fact that now code completion is aware of the 'Foo' member. However, keep in mind that the type cast is unsafe. If the JSON data is not the class JFooBar it will result in an unpredictable behaviour (depending on read or write access).
  18. CWBudde

    Snippets line indention

    There's not much I can do about that. While I have access to the SmartCL and could change it, I decided not to touch it as all changes are likely to get overwritten sooner or later by Lennart anyway (who keeps the development private outside the SVN). This is also the reason why I typically don't respond to questions around the SmartCL or other parts of the RTL here. What I could do is to create a bug report in our bug tracker, but since Lennart doesn't use that either it's just wasted time. He mentioned lately that he wants to get contacted by a PM. While this probably would work, I don't think that this is the desired way of communication in the long run. But this is just my personal view.
  19. CWBudde

    Snippets line indention

    I implemented this based on your code. It's slightly different as I optimized it based on my experience with SynEdit. Also I improved the initial indention detection so that it's also possible to cover cases like: if true then begin // some code end; where begin // some code end; is the code snippet. The proposed code would otherwise indent it like: if true then begin // some code end; This might be either available as hotfix or in the next version.
  20. CWBudde

    Snippets line indention

    No, but if you fill the above function with more sophisticated code (which you donate) we can copy-&-paste-implement it in the IDE easily.
  21. CWBudde

    Keyword confusion?

    Yes, it's closed source but you can still find it in the DWScript repository before this commit: https://bitbucket.org/egrange/dwscript/commits/5daed7cba1ca63becd9245738c25ba0b394dcdfc It hasn't changed that much in the meantime. The file you might want to look at is: Libraries\JSCodeGen\dwsJSRTL.pas or the Libraries\JSCodeGen\rtl subdirectory. It contains the intrinsics and some OOP related code.
  22. CWBudde

    toolbar icon-repeat & component name displayed

    You may not rename the component name as it is used to locate the component in your code. If you rename it, it can't find it and thus it might crash. This said, it should not actually crash but show as usable error message. I just fixed the crash so that it now reads 'Component could not be added' (with a more detailed reason depending on the error). At the same time I changed the code to show the glyph name instead of the component name. This gives you the freedom to change the text below the glyph independently. This will be available in the next version of the IDE. Regarding the same icon after 13 items, I could not reproduce this issue so far, but I just had a peek into this issue so far.
  23. I haven't seen this message in my console so far, but maybe this is because I have disabled the generation of a cache manifest. If you want to see if this is responsible for the warning, keep in mind that you might need to delete the already generated file manually.
  24. CWBudde

    Snippets line indention

    Adding this isn't as trivial as it seems. At the moment it just copies the entire snippet string to the caret position. If this should be implemented it first need to determine whether indention should apply at all and if so, check what the desired indention should be. Code for this is already present for the live templates, but it needs to be adapted, which takes time to do it right. As it's not high priority don't expect this anytime soon, but I'll put it on the list. To improve this now, feel free to implement this yourself. Currently the code looks like: procedure InsertSnippet(Editor: TSynEdit; Snippet: string); begin Editor.SelText := Snippet; end;
  25. CWBudde

    Keyword confusion?

    This is known. The procedure ShowMessage is implemented in the RTL of DWScript but not in the mini RTL of the JS CodeGen. So in order to use it you must have a line that reads: procedure ShowMessage(aText: String); external 'alert'; This said, it will only work for JS implementations that has the 'alert' function implemented. For the NodeJS, Espruino or PhantomJS target this is likely not the case (or at least different to what you would expect). For these you might want to write your own custom code, which is why this is not hard coded in the DWScript JS CodeGen's mini RTL.
×