Re: [fpc-pascal] Parse JSON
On Fri, 23 Jun 2023, Darius Blaszyk via fpc-pascal wrote: Hi all, I've hardly done anything with JSON in Freepascal before, so apologies for the trivial question. I want to traverse an array in JSON and retrieve the elements (which I don't know what they are in advance) one by one. An example of the JSON file is given below. "keywords": { "key": "value", "key1": "value1", "key2": "value2" }, Ideally, I'd like to be able to stick to the FPC out-of-the-box library. Any help would be appreciated. Something like: uses classes, fpjson; var J : TJSONObject; F : TFileStream; begin J:=nil; F:=TFileStream.Create('yourfile.json',fmOpenRead); try J:=GetJSON(F) as TJSONObject; For I:=0 to J.Count-1 do Writeln(J.Names[i],' : ',J.AsString); finally J.Free; F.Free; end; end. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Parse JSON
fpJson fully supports JSON: https://www.freepascal.org/docs-html/fcl/fpjson/index.html https://wiki.lazarus.freepascal.org/JSON There's also JSON support in the LGenerics package, but it's not a bundled package as far as I know. Thomas - Original Message - From: Darius Blaszyk via fpc-pascal To: FPC-Pascal users discussions Sent: Friday, June 23, 2023, 16:02:26 Subject: [fpc-pascal] Parse JSON Hi all, I've hardly done anything with JSON in Freepascal before, so apologies for the trivial question. I want to traverse an array in JSON and retrieve the elements (which I don't know what they are in advance) one by one. An example of the JSON file is given below. "keywords": { "key": "value", "key1": "value1", "key2": "value2" }, Ideally, I'd like to be able to stick to the FPC out-of-the-box library. Any help would be appreciated. Rgds, Darius ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Parse JSON
Hi all, I've hardly done anything with JSON in Freepascal before, so apologies for the trivial question. I want to traverse an array in JSON and retrieve the elements (which I don't know what they are in advance) one by one. An example of the JSON file is given below. "keywords": { "key": "value", "key1": "value1", "key2": "value2" }, Ideally, I'd like to be able to stick to the FPC out-of-the-box library. Any help would be appreciated. Rgds, Darius___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Microsoft SAPI on Freepascal
Hi James, I am not familiar with variants and Ole objects, sorry about that. I found some people using code with Ole objects and it that seems to work, can you chack if it applies to your case? https://stackoverflow.com/questions/17970573/using-word-ole-in-lazarus-freepascal Best, R On Sun, Jun 25, 2023 at 2:25 PM wrote: > Send fpc-pascal mailing list submissions to > fpc-pascal@lists.freepascal.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal > or, via email, send a message with subject or body 'help' to > fpc-pascal-requ...@lists.freepascal.org > > You can reach the person managing the list at > fpc-pascal-ow...@lists.freepascal.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of fpc-pascal digest..." > > > Today's Topics: > >1. Re: Microsoft SAPI on Freepascal (Rafael Pican?o) >2. Re: SDL2 Event Registration (and case statements) > (Rafael Pican?o) >3. Re: Microsoft SAPI on Freepascal (Rafael Pican?o) >4. Re: Microsoft SAPI on Freepascal (James Richters) > > > -- > > Message: 1 > Date: Sun, 25 Jun 2023 13:33:24 -0300 > From: Rafael Pican?o > To: fpc-pascal@lists.freepascal.org > Subject: Re: [fpc-pascal] Microsoft SAPI on Freepascal > Message-ID: > h9m...@mail.gmail.com> > Content-Type: text/plain; charset="utf-8" > > Hi James, > > > SpVoice : Variant; > > SpVoice := CreateOleObject('SAPI.SpVoice') > > The Free Pascal Variant type does not handle interfaces by default. Take a > look: > > https://wiki.freepascal.org/Variant > > Best, > R > -- next part -- > An HTML attachment was scrubbed... > URL: < > http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20230625/ae39a571/attachment-0001.htm > > > > -- > > Message: 2 > Date: Sun, 25 Jun 2023 13:42:00 -0300 > From: Rafael Pican?o > To: fpc-pascal@lists.freepascal.org > Subject: Re: [fpc-pascal] SDL2 Event Registration (and case > statements) > Message-ID: > hsjvo9...@mail.gmail.com> > Content-Type: text/plain; charset="utf-8" > > Thanks Guilhermo, > > Just to clarify, I do have a limited number of events. Lets say, 2 events. > So, using the SDL_RegisterEvents function, is it possible to define these > two new events as normal constants so they will be known at compile time > and will make Free Pascal case statements happy? > > Best, > R > -- next part -- > An HTML attachment was scrubbed... > URL: < > http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20230625/c9a4b1e9/attachment-0001.htm > > > > -- > > Message: 3 > Date: Sun, 25 Jun 2023 13:52:17 -0300 > From: Rafael Pican?o > To: fpc-pascal@lists.freepascal.org > Subject: Re: [fpc-pascal] Microsoft SAPI on Freepascal > Message-ID: > < > cagpuci4jaaqdqnrvjgonezaos61mvuf-okabx92bm9stjo2...@mail.gmail.com> > Content-Type: text/plain; charset="utf-8" > > Hi James, > > Sorry, I missed the following reference: > > "Remark Dispatch interface support for variants is currently broken in the > compiler." (https://www.freepascal.org/docs-html/ref/refsu20.html) > > Best, > R > > > > -- next part -- > An HTML attachment was scrubbed... > URL: < > http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20230625/08ee32d3/attachment-0001.htm > > > > -- > > Message: 4 > Date: Sun, 25 Jun 2023 13:24:46 -0400 > From: "James Richters" > To: , "'FPC-Pascal users discussions'" > > Subject: Re: [fpc-pascal] Microsoft SAPI on Freepascal > Message-ID: <015d01d9a789$f1097fb0$d31c7f10$@productionautomation.net> > Content-Type: text/plain; charset="utf-8" > > So it?s broken? It seems like the link you provided is trying to show a > workaround, but I don?t know how I could apply that. > > >"Remark Dispatch interface support for variants is currently broken in > the compiler." (https://www.freepascal.org/docs-html/ref/refsu20.html) > > > -- next part -- > An HTML attachment was scrubbed... > URL: < > http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20230625/c33bf375/attachment.htm > > > > -- > > Subject: Digest Footer > > ___ > fpc-pascal maillist - fpc-pascal@lists.freepascal.org > https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal > > > -- > > End of fpc-pascal Digest, Vol 228, Issue 30 > *** > ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Microsoft SAPI on Freepascal
So it’s broken? It seems like the link you provided is trying to show a workaround, but I don’t know how I could apply that. >"Remark Dispatch interface support for variants is currently broken in the >compiler." (https://www.freepascal.org/docs-html/ref/refsu20.html) ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Microsoft SAPI on Freepascal
Hi James, Sorry, I missed the following reference: "Remark Dispatch interface support for variants is currently broken in the compiler." (https://www.freepascal.org/docs-html/ref/refsu20.html) Best, R > ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] SDL2 Event Registration (and case statements)
Thanks Guilhermo, Just to clarify, I do have a limited number of events. Lets say, 2 events. So, using the SDL_RegisterEvents function, is it possible to define these two new events as normal constants so they will be known at compile time and will make Free Pascal case statements happy? Best, R ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Microsoft SAPI on Freepascal
Hi James, > SpVoice : Variant; > SpVoice := CreateOleObject('SAPI.SpVoice') The Free Pascal Variant type does not handle interfaces by default. Take a look: https://wiki.freepascal.org/Variant Best, R ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Microsoft SAPI on Freepascal
Ooops forgot the link: https://wiki.lazarus.freepascal.org/SAPI From: fpc-pascal On Behalf Of James Richters via fpc-pascal Sent: Sunday, June 25, 2023 8:52 AM To: 'FPC-Pascal users discussions' Cc: James Richters Subject: [fpc-pascal] Microsoft SAPI on Freepascal I am trying to get Microsoft speech synthesis to work with Freepascal. I am trying to follow the guide here: I don't know what I am doing wrong. SAPI is working on my system, because the TTSApp Demo that comes with the Microsoft Speech SDK works fine. Here is my test program: {$mode objfpc} uses CRT, Windows, SysUtils, ComObj, Variants, OLEServer, Classes, ActiveX, ShellApi; var SavedCW: Word; SpVoice: Variant; MyWideString: WideString; begin CoInitialize(nil); SpVoice := CreateOleObject('SAPI.SpVoice'); // Change FPU interrupt mask to avoid SIGFPE exceptions MyWideString := WideString('Hello, the time is ' + TimeToStr(Now)); Writeln(MyWideString); SavedCW := Get8087CW; try Set8087CW(SavedCW or $4); SpVoice.Speak(MyWideString, 0); finally // Restore FPU mask Set8087CW(SavedCW); end; Writeln('Press Any Key'); ReadKey; CoUninitialize; end. Whenever my program gets to: SpVoice.Speak(MyWideString, 0); Even if I hardcode something like: SpVoice.Speak('Hello', 0); I always get: Running "i:\programming\TTS.exe " Hello, the time is 8:41:27 An unhandled exception occurred at $0041FC90: EOleError: Variant does not reference an automation object $0041FC90 $00424DAD $0040BB31 $00401A8A main, line 21 of i:\programming\TTS.pas I don't really understand what this means, and I can't find a complete sample program that I can just compile and run. I feel I must be missing something but I don't know what it is. Any help is greatly appreciated! James ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Microsoft SAPI on Freepascal
I am trying to get Microsoft speech synthesis to work with Freepascal. I am trying to follow the guide here: I don't know what I am doing wrong. SAPI is working on my system, because the TTSApp Demo that comes with the Microsoft Speech SDK works fine. Here is my test program: {$mode objfpc} uses CRT, Windows, SysUtils, ComObj, Variants, OLEServer, Classes, ActiveX, ShellApi; var SavedCW: Word; SpVoice: Variant; MyWideString: WideString; begin CoInitialize(nil); SpVoice := CreateOleObject('SAPI.SpVoice'); // Change FPU interrupt mask to avoid SIGFPE exceptions MyWideString := WideString('Hello, the time is ' + TimeToStr(Now)); Writeln(MyWideString); SavedCW := Get8087CW; try Set8087CW(SavedCW or $4); SpVoice.Speak(MyWideString, 0); finally // Restore FPU mask Set8087CW(SavedCW); end; Writeln('Press Any Key'); ReadKey; CoUninitialize; end. Whenever my program gets to: SpVoice.Speak(MyWideString, 0); Even if I hardcode something like: SpVoice.Speak('Hello', 0); I always get: Running "i:\programming\TTS.exe " Hello, the time is 8:41:27 An unhandled exception occurred at $0041FC90: EOleError: Variant does not reference an automation object $0041FC90 $00424DAD $0040BB31 $00401A8A main, line 21 of i:\programming\TTS.pas I don't really understand what this means, and I can't find a complete sample program that I can just compile and run. I feel I must be missing something but I don't know what it is. Any help is greatly appreciated! James ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] SDL2 Event Registration (and case statements)
Hi. > The SDL2 documentation recommends you to register constants with: > > Uint32 SDL_RegisterEvents(int numevents); >numevents = the number of events to be allocated. >Returns the beginning event number, or (Uint32)-1 if there are not > enough user-defined events left. > > The SDL_RegisterEvents result is not known at compile time, so one > can't use them as case conditions. So, Is there a workaround for > building these constants at compile time? If you know how many events were registered, then you can create constants. Else, you can't. > > Best, > R Guillermo "Ñuño" Martínez ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] 3123 inherited not supported inside inline
On Sun, 25 Jun 2023, Hairy Pixels via fpc-pascal wrote: On Jun 24, 2023, at 10:27 PM, Michael Van Canneyt via fpc-pascal wrote: It seems to me no gain is to be had from e.g. inlining a routine of 500+ lines of code. What if the function was only called from 3 places in the program and each one of those was in something with very long loops, say 1 million iterations? If you inline you'd get only an extra 1000 lines of code size but save 3 million function calls which could be a big savings. I doubt there will be any gain: 500 lines of code will result in many thousands of assembler instructions being executed 3 million times. The few additional instructions generated by a function call are dwarfed by that. More importantly: Inline is an automatism to optimize where possible. You can always find exceptional cases which will not be handled by an automatism. They are irrelevant. It's the bulk of cases that needs to be solved by automatisms. Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal