Whats the size limitation for the StringGadget gadget?
Whats the size limitation for the StringGadget gadget?
Guess there is a size limitation for how big a text file can be when it is added to a StringGadget. When I try to add a 115 kb text file to the gadget my program crash.
Is there any way to get around this?
Is there any way to get around this?
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
64K is the limit.. Here is a thread that shows a way around it thanks to Mr. Fr34k 
viewtopic.php?t=9186&highlight=64k+stringgadget

viewtopic.php?t=9186&highlight=64k+stringgadget
I tried this but doesn't seem to have any effect. The program crashes when reading files bigger than 64 KB.
104857600 is just a test. Tried a lower number but had no effect.
Code: Select all
StringGadgetSize.l = 104857600
SendMessage_(GadgetID(#Editor_0), #EM_LIMITTEXT, StringGadgetSize.l, 0)
104857600 is just a test. Tried a lower number but had no effect.
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
For String Gadget:
SendMessage_(GadgetID(#String), #EM_LIMITTEXT, NewSize, 0)
For Editor Gadget:
SendMessage_(GadgetID(#Editor), #EM_EXLIMITTEXT, 0, NewSize)
You need to change your #EM_LIMITTEXT to #EM_EXLIMITTEXT and the last 2 parameters for the Editor Gadget are 0, Newsize not Newsize, 0
Hope this helps.
SendMessage_(GadgetID(#String), #EM_LIMITTEXT, NewSize, 0)
For Editor Gadget:
SendMessage_(GadgetID(#Editor), #EM_EXLIMITTEXT, 0, NewSize)
You need to change your #EM_LIMITTEXT to #EM_EXLIMITTEXT and the last 2 parameters for the Editor Gadget are 0, Newsize not Newsize, 0
Hope this helps.
Well, when I first made the window dialog, I made it with a EditorGadget, but then I tried changing it to a StringGadget which I'm using now. Just didn't change the enumeration name.
That's how the string gadget code looks like.
And it's still not working
Code: Select all
StringGadgetSize.l = 1048576
If CreateGadgetList(WindowID())
StringGadget(#Editor_0, 10, 30, 570, 430, "", #PB_String_MultiLine | #PB_String_ReadOnly)
SetGadgetFont(#Editor_0, FontID1)
SendMessage_(GadgetID(#Editor_0), #EM_LIMITTEXT, StringGadgetSize.l, 0)
EndIf
And it's still not working

I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
Do you read the file into on single string?
There is a limit of 64k for a PB string. So you'll have to either work with
a memory buffer, but that means you can't use PB commands to fill in the
Gadget, or your read the file line by line and fill the EditorGadget with
AddGadgetItem()
Timo
There is a limit of 64k for a PB string. So you'll have to either work with
a memory buffer, but that means you can't use PB commands to fill in the
Gadget, or your read the file line by line and fill the EditorGadget with
AddGadgetItem()
Timo
quidquid Latine dictum sit altum videtur
I've written a procedure that uses memory buffer to read the content of the text files.
I added RTrim because some files adds weird symbols to the StringGadget. Could that have something to do with the app crashing?
Code: Select all
Procedure GetText(File$)
Result = ReadFile(0, File$) : Debug "Result: "+Str(Result)
Length = Lof() : Debug "Length of file: "+Str(Length)
*MemoryBuffer = AllocateMemory(Length)
LengthRead = ReadData(*MemoryBuffer, Length) : Debug "Length read: "+Str(LengthRead)
Text.s = PeekS(*MemoryBuffer, LengthRead) : Debug "Text.s: "+Text
SetGadgetText(#Editor_0, RTrim(Text))
SetWindowTitle(#Window_0, AppName + " - " + GetFilePart(File$))
EndProcedure
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
I believe that PB's StringGadget is actually what Microsoft calls an Edit Control. According to Microsoft a single line Edit Control is limited to 32k and a multiline Edit Control is limited to 64K See this link:
http://msdn.microsoft.com/library/defau ... itctls.asp
However, I have been able to put a few megs of text in a PB EditorGadget after resetting the limit on it as shown above. The EditorGadget is actually a Microsoft Richedit Control I believe.
http://msdn.microsoft.com/library/defau ... itctls.asp
However, I have been able to put a few megs of text in a PB EditorGadget after resetting the limit on it as shown above. The EditorGadget is actually a Microsoft Richedit Control I believe.
GPI, are there any other way I can get this done then?
upnorth, Not sure if the link worked. Just saw a page with lots of lines of links on it.
I just tried added the gadget resize code right above the code that inserts the content into the gadget but it still crashes
This also doesn't work:
Now I tried changing the StringGadget to a EditGadgetand still it crashes 
upnorth, Not sure if the link worked. Just saw a page with lots of lines of links on it.
I just tried added the gadget resize code right above the code that inserts the content into the gadget but it still crashes
Code: Select all
Procedure GetText(File$) ; Procedure to read file content into buffer
Result = ReadFile(0, File$) ; because of PB's 64 K string limit.
Length = Lof() ; Get length of file for AllocateMemory.
*MemoryBuffer = AllocateMemory(Length) ; Set buffer size.
LengthRead = ReadData(*MemoryBuffer, Length) ; Read file to buffer.
Text.s = PeekS(*MemoryBuffer, LengthRead) ; Add content of buffer to string.
SendMessage_(GadgetID(#Editor_0), #EM_LIMITTEXT, StringGadgetSize.l, 0)
SetGadgetText(#Editor_0, RTrim(Text.s))
SetWindowTitle(#Window_0, AppName + " - " + GetFilePart(File$))
EndProcedure
Code: Select all
Procedure GetText(File$) ; Procedure to read file content into buffer
Result = ReadFile(0, File$) ; because of PB's 64 K string limit.
Length = Lof() ; Get length of file for AllocateMemory.
*MemoryBuffer = AllocateMemory(Length) ; Set buffer size.
LengthRead = ReadData(*MemoryBuffer, Length) ; Read file to buffer.
;Text.s = PeekS(*MemoryBuffer, LengthRead) ; Add content of buffer to string.
SendMessage_(GadgetID(#Editor_0), #EM_LIMITTEXT, StringGadgetSize.l, 0)
;SetGadgetText(#Editor_0, RTrim(Text.s))
SetGadgetText(#Editor_0, PeekS(*MemoryBuffer, LengthRead))
SetWindowTitle(#Window_0, AppName + " - " + GetFilePart(File$))
EndProcedure
Code: Select all
Procedure GetText(File$) ; Procedure to read file content into buffer
Result = ReadFile(0, File$) ; because of PB's 64 K string limit.
Length = Lof() ; Get length of file for AllocateMemory.
*MemoryBuffer = AllocateMemory(Length) ; Set buffer size.
LengthRead = ReadData(*MemoryBuffer, Length) ; Read file to buffer.
;Text.s = PeekS(*MemoryBuffer, LengthRead) ; Add content of buffer to string.
;SendMessage_(GadgetID(#Editor_0), #EM_LIMITTEXT, StringGadgetSize.l, 0)
SendMessage_(GadgetID(#Editor_0), #EM_EXLIMITTEXT, 0, StringGadgetSize)
;SetGadgetText(#Editor_0, RTrim(Text.s))
SetGadgetText(#Editor_0, PeekS(*MemoryBuffer, LengthRead))
SetWindowTitle(#Window_0, AppName + " - " + GetFilePart(File$))
EndProcedure

I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
I suggest you try ReadString() to read a line at a time from the file and AddGadgetItem() to add those lines to the EditorGadget one at a time. This should avoid the problem of trying to transfer the entire file at once.
I can confirm that the EditorGadget will hold a few megs at least as I have cut and pasted that much into one.
I can look into this more when I get home from work.
I can confirm that the EditorGadget will hold a few megs at least as I have cut and pasted that much into one.
I can look into this more when I get home from work.
Have a look at this ...
Code: Select all
Enumeration
#Window_0
#Editor_0
EndEnumeration
#MAX_STRING_LENGTH = $1000000
Structure StringBytes
Bytes.b[#MAX_STRING_LENGTH]
EndStructure
Global AppName.s
Procedure ManipulationBufferSize(Bytes)
PBStringBase.l = 0
PBMemoryBase.l = 0
!MOV Eax, dword [PB_StringBase]
!MOV [Esp+4],Eax
!MOV Eax, dword [PB_MemoryBase]
!MOV [Esp+8],Eax
HeapReAlloc_(PBMemoryBase, #GMEM_ZEROINIT, PBStringBase, Bytes)
!MOV dword [PB_StringBase],Eax
Debug "ManipulationBufferSize : max length of string set to : " + Str(Bytes)
ProcedureReturn Bytes
EndProcedure
Procedure GetText(File$) ; Procedure to read file content into buffer
If ReadFile(0, File$)
LengthOfFile = Lof()
Text.s = Space(LengthOfFile)
*Buffer.StringBytes = @Text
ReadData(*Buffer, LengthOfFile)
CloseFile(0)
EndIf
Debug Len(Text)
SetGadgetText(#Editor_0, Text)
SetWindowTitle(#Window_0, AppName + " - " + GetFilePart(File$))
EndProcedure
ManipulationBufferSize(#MAX_STRING_LENGTH)
AppName = "EditorGadget"
FileName.s = "C:\RECUP\Frw\Bible\BibleJNDdoc-Bible.txt"
If OpenWindow(#Window_0,0,0,322,150,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,AppName) And CreateGadgetList(WindowID(0))
EditorGadget (#Editor_0,8,8,306,133,#PB_Container_Raised)
GetText(FileName)
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIf
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
- NoahPhense
- Addict
- Posts: 1999
- Joined: Thu Oct 16, 2003 8:30 pm
- Location: North Florida
..
omg.. all this code.. someone finalize this thing and I'll make a library out
of it. So we don't have to have this conversation (again)..
- np
of it. So we don't have to have this conversation (again)..
- np