Re: [fpc-pascal] Why does nested function get corrupted?

2022-09-09 Thread Hairy Pixels via fpc-pascal
> On Sep 9, 2022, at 4:48 PM, Sven Barth wrote: > > How about you simply report such corruptions as bugs? I can always close them > as "not a bug" or duplicate if necessary. > Well I thought the data may have been saved on the stack and thus lost when the function exits. What is the expec

Re: [fpc-pascal] Access Violation When SetLength(DynArray, Value)

2022-09-09 Thread James Richters via fpc-pascal
>With FPC 3.2.0 and newer you can do "Concat(MyArray, [TheNewElement])" or (if >modeswitch ArrayOperators is active) "MyArray := MyArray + [TheNewElement]". I have a lot of arrays of records, but I just build the record into the array elements, like this:

Re: [fpc-pascal] Access Violation When SetLength(DynArray, Value)

2022-09-09 Thread Sven Barth via fpc-pascal
Luca Olivetti via fpc-pascal schrieb am Fr., 9. Sep. 2022, 15:29: > I don't know if it is more or less efficient than using a dynamic array > but I think it's nicer. > It internally uses a dynamic array as well, but duplicates the size with each growth and keeps track of a separate count of elem

Re: [fpc-pascal] Access Violation When SetLength(DynArray, Value)

2022-09-09 Thread Sven Barth via fpc-pascal
James Richters via fpc-pascal schrieb am Fr., 9. Sep. 2022, 14:58: > I still end up with a lot of > SetLength(MyArray,Length(MyArray)+1); > Every time I want to add one more thing to the array. > With FPC 3.2.0 and newer you can do "Concat(MyArray, [TheNewElement])" or (if modeswitch ArrayOperat

Re: [fpc-pascal] Why does nested function get corrupted?

2022-09-09 Thread Sven Barth via fpc-pascal
Hairy Pixels via fpc-pascal schrieb am Fr., 9. Sep. 2022, 00:52: > Curious more than anything, if is nested captures state in a record and > passes it as an hidden self param, why does returning the variable and > calling from outside the calling stack frame corrupt the data? It seems > like it t

[fpc-pascal] Getting Shift key with PTCCRT

2022-09-09 Thread James Richters via fpc-pascal
I have some key sequences with PTCCRT.READKEY where I use a lower case letter to do one thing and an uppercase to do another, but if the Capslock is on, they do the wrong things. Is there a way I can check the condition of the shift key to see if shift was actually pressed instead of just going b

[fpc-pascal] Internal error 2019022201 from function reference

2022-09-09 Thread Hairy Pixels via fpc-pascal
This program gives internal compiler error 2019022201 (Free Pascal Compiler version 3.3.1 [2022/05/27] for aarch64). Something is wrong with the PPU. This is a very basic program using function references so it seems unlikely it could not be known. Any ideas? {$mo

Re: [fpc-pascal] TJSONRPCModule: access the request from an handler.

2022-09-09 Thread Michael Van Canneyt via fpc-pascal
On Fri, 9 Sep 2022, Luca Olivetti via fpc-pascal wrote: El 9/9/22 a les 15:50, Michael Van Canneyt ha escrit: The solution is much more simple. Override HandleRequest() in the module. Save the request in a variable and call inherited. Much simpler indeed! Thank you. In my case I just sav

Re: [fpc-pascal] TJSONRPCModule: access the request from an handler.

2022-09-09 Thread Luca Olivetti via fpc-pascal
El 9/9/22 a les 15:50, Michael Van Canneyt ha escrit: The solution is much more simple. Override HandleRequest() in the module. Save the request in a variable and call inherited. Much simpler indeed! Thank you. In my case I just save the remote address, but in your example below I suppose yo

Re: [fpc-pascal] TJSONRPCModule: access the request from an handler.

2022-09-09 Thread Michael Van Canneyt via fpc-pascal
On Fri, 9 Sep 2022, Luca Olivetti via fpc-pascal wrote: Hello, I added a "Web JSON-RPC Module" to my project, I dropped on it a TJSONPCHandler. I find no way to access the request (I want to check the RemoteAddress): 1) the module has a "Request" field but it is always nil (either in Da

Re: [fpc-pascal] Access Violation When SetLength(DynArray, Value)

2022-09-09 Thread Luca Olivetti via fpc-pascal
El 9/9/22 a les 14:58, James Richters via fpc-pascal ha escrit: Is there some nifty way to increase a dynamic array by 1 that is more elegant? Inc(MyArray); would sure be nice If I know that I have to regularly add a single element to an array, instead of using a dynamic array I just use a T

[fpc-pascal] TJSONRPCModule: access the request from an handler.

2022-09-09 Thread Luca Olivetti via fpc-pascal
Hello, I added a "Web JSON-RPC Module" to my project, I dropped on it a TJSONPCHandler. I find no way to access the request (I want to check the RemoteAddress): 1) the module has a "Request" field but it is always nil (either in DataModuleCreate, which isn't called with every request so it's

Re: [fpc-pascal] Access Violation When SetLength(DynArray, Value)

2022-09-09 Thread James Richters via fpc-pascal
I only recently learned about using Low() and High() and it is so much nicer than For I:= 0 to Length(MyArray)-1 Do That I actually went though all my code replacing the Length() - 1's with High() I still end up with a lot of SetLength(MyArray,Length(MyArray)+1); Every time I want to add one m

Re: [fpc-pascal] Access Violation When SetLength(DynArray, Value)

2022-09-09 Thread Luca Olivetti via fpc-pascal
El 8/9/22 a les 16:53, Anthony Walter via fpc-pascal ha escrit: > curious minds want to know: what was the fix? In a separate part of the pool table initialization, I was precalculating the midpoints and normals for bumper rails. I had carelessly written this code:   for I := 0 to Length(R

Re: [fpc-pascal] Access Violation When SetLength(DynArray, Value)

2022-09-09 Thread Adriaan van Os via fpc-pascal
Peter B via fpc-pascal wrote: I suggest trying without optimisations and/or using cmem, to see if that changes the outcome. I would rather use a system memory debugger to find the cause of the corruption. Regards, Adriaan van Os