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")