Toolbox help
Pages: 1 2
Steve Drain (222) 1620 posts |
It did, rather. Anything for a bit of excitement. ;-) If I have just knocked up a test app in Basalt and written this working function: DEFFNSaveText LOCAL size%,buff% SYS"Toolbox_ObjectMiscOp",0,Main,&401B,0,,0 TO ,,,,,size% DIM buff% LOCAL size%-1 SYS"Toolbox_ObjectMiscOp",0,Main,&401B,0,buff%,size% SYS"OS_File",10,"TextArea:Documents.Text",&FFF,,buff%,buff%+size% =FALSE Not quite the format you want, but it should be good to to check against. Using Basalt in its OOP format I could just do: SAVE ('Main#0.Text),"TextArea:Documents.Text" OF &FFF ;-) |
Steve Drain (222) 1620 posts |
Even in Basalt that would not be a very good idea. Basalt has dynamic memory handling in app space.
Do that inside procedures and you are liable to run into “No room”. Not recommended as an example of “the way to do it” to a beginner. |
Graham (1584) 30 posts |
I am struggling with the documentation, its just so confusing. I want to know when a text file is loaded into the textarea, I found a message “TextArea_DataLoaded” Ox140180 What is Ox140180 ? |
Stuart Swales (8827) 1357 posts |
For BASIC, just replace the hex prefix 0x with & |
Graham (1584) 30 posts |
Thank you Stuart |
Rick Murray (539) 13850 posts |
That’s why DIM LOCAL, if you’re not using a global block. Wimp poll blocks are a useful source if 256 bytes in a pinch – just so long as all the Wimpy stuff has been done.
Plenty of good examples around as to why teaching programming is hard. Habits and language ambiguity lead to…
Just to clarify as nobody has said, 0x (zero x) is how C denotes hex numbers, when it’s not using You may also stumble across (though not around here) an “h” suffix, like Other places with better typography might use a subscript “H” suffix, like Yet others use a dollar prefix, like And, of course, there’s always a prefix or suffix that just says “16”. Hex numbers are like brace placement. Everybody has their preferred way to do it, and everything else is simply wrong. ;) |
Simon Willcocks (1499) 520 posts |
OS_ReadUnsigned accepts any base from 2 to 36, so 17_g is 10_16 (aka &10), or 2_10000, or 4_10. Just to be confusing! |
Graham (1584) 30 posts |
This was the finished code just in case it helps anybody else. file$ = File name and path to save to.
|
Stuart Swales (8827) 1357 posts |
Remember that you can’t supply type$ to OS_File, use: type%=&FFF |
Graham (1584) 30 posts |
Thanks for the heads up Stuart, I accidentally posted an old one. It is corrected now. |
Fred Graute (114) 645 posts |
0×140180 is the code of the toolbox event that is raised when text is imported into a textarea gadget, eg by dropping a textfile on it. Not much use though as it’s not implemented in the RO5 toolbox, it’s only available on the other branch of RISC OS, alas.
That’s a potentially dangerous bit of code. If your buffer is 10k and your text 20k then the toolbox will happily attempt to copy those 20k into your 10k buffer. You should pass the size of the buffer (rather than size of text) to TextArea_GetText method to avoid the risk of the buffer being overrun. For a fixed size buffer I’d suggest using something like this:
HTH |
Graham (1584) 30 posts |
Thanks Fred, things have changed a lot since getting my head around the toolbox and its strange and painful documentation. I now claim lumps of memory from the heap as needed and return them when finished with so the DIM is gone. The code will eventually run on RO4.39 RiscPC so the Ox140180 call works fine. |
Pages: 1 2