Dynamic ReadPreferenceString String Length...
Posted: Wed Apr 26, 2017 6:00 pm
				
				Is there a max string length for ReadPreferenceString? Is it possible to work out the string length before ReadPreferenceString, without having to manually count string length ahead, so that I can dynamically allocate required string size/space?
I can opt to either use a predefined size, though it isn't very dynamic if the text is longer then the constant value. The advantage is if ReadPreferenceString is longer than the constant value there isn't a memory overflow...
Second option is to allocate memory and hope ReadPreferenceString does not return a string that is greater than the allocated memory and cause an overflow...
Ted.
			I can opt to either use a predefined size, though it isn't very dynamic if the text is longer then the constant value. The advantage is if ReadPreferenceString is longer than the constant value there isn't a memory overflow...
Code: Select all
Procedure.s StringTest1(nKey.s, nText.s)
  
  text.s{5} = ReadPreferenceString(nKey.s, nText.s)
  
  ProcedureReturn text.s
EndProcedure
Debug StringTest1("TestKey", "1234567890")Code: Select all
Procedure.s StringTest2(nKey.s, nText.s)
  
  *StringMem = AllocateMemory(StringByteLength(nText.s) + SizeOf(Character))
  
  If *StringMem
    PokeS(*StringMem, ReadPreferenceString(nKey.s, nText.s))
    ;Debug MemoryStringLength(*StringMem)
    text.s = PeekS(*StringMem)
  EndIf
  
  FreeMemory(*StringMem)
  
  ProcedureReturn text.s
EndProcedure
Debug StringTest2("TestKey", "1234567890")