Page 1 of 1
ReplaceString() inside a macro : Bug or not ?
Posted: Mon Jan 15, 2024 3:16 am
by boddhi
In your opinion, is the behavior of ReplaceString() placed inside a macro normal or a bug?
I've got some exe (codes too long to post them for test) where the function, into the same macro code, returns a correct result and others where it doesn't.
Code: Select all
Macro Mc_FormatMsg(ArgChaine)
ReplaceString(ArgChaine,"e","a")
EndMacro
a.s="Text text text"
Debug a
Debug Mc_FormatMsg(a)
Debug a
Debug "------"
b.s="Text text text"
Mc_FormatMsg(b)
Debug b
Debug Mc_FormatMsg(b)
Debug b
ReplaceString() inside a macro : Bug or not ?
Posted: Mon Jan 15, 2024 3:47 am
by boddhi
To illustrate my first post, here are 2 examples with two exe created with exactly the same code (the first under PB6.03, the second under PB610b2) running under exactly the same conditions.
Example 1:
Example 2:
Note that the message in the 2nd example is not at all the same as in the 1st (it corresponds to the content of a global variable used in other procedures

).
The source of the macro and procedure (the ';ResultMSG' lines correspond to tests to understand the source of the problem):
Code: Select all
Macro Mc_FormatageMsg(ArgChaine)
ReplaceString(ArgChaine,Chr(32),Chr(160),#PB_String_InPlace)
EndMacro
Procedure Pc_Traitement_BtFPArreter()
Debug #PB_Compiler_Procedure+"()",5
Protected.a ResultatMSG
Protected.s TitreMsg,TexteMsg
If IsThread(*DonneesThread\IDThread)
Pc_Thread_Pause(*DonneesThread)
Select *DonneesThread\TypeTraitement
Case 1:TitreMsg="Analyse de dossiers":TexteMsg="Confirmer l'arrêt de l'analyse du dossier ?"
Case 2:TitreMsg="Création des galeries":TexteMsg="Confirmer l'arrêt de la création des galeries ?"
EndSelect
;ResultatMSG=MessageRequester(TitreMsg+" 1",TexteMsg,#PB_MessageRequester_YesNo|#MB_ICONQUESTION)
;ResultatMSG=MessageRequester(TitreMsg+" 2",UnescapeString(TexteMsg),#PB_MessageRequester_YesNo|#MB_ICONQUESTION)
ResultatMSG=MessageRequester(TitreMsg+" 3",Mc_FormatageMsg(UnescapeString(TexteMsg)),#PB_MessageRequester_YesNo|#MB_ICONQUESTION)
;ResultatMSG=MessageRequester(TitreMsg+" 4",ReplaceString(TexteMsg,Chr(32),Chr(160),#PB_String_InPlace),#PB_MessageRequester_YesNo|#MB_ICONQUESTION)
Pc_Thread_Reprise(*DonneesThread)
If ResultatMSG=#PB_MessageRequester_Yes
Pc_Thread_Arret(*DonneesThread)
EndIf
EndIf
EndProcedure
Re: ReplaceString() inside a macro : Bug or not ?
Posted: Mon Jan 15, 2024 6:08 am
by breeze4me
There seems to be a bug in the UnescapeString function.
See:
https://www.purebasic.fr/english/viewtopic.php?t=83341
Re: ReplaceString() inside a macro : Bug or not ?
Posted: Mon Jan 15, 2024 7:30 am
by infratec
Read the help for ReplaceString() with the option #PB_String_InPlace
In this case the return value has to be ignored and it is not valid.
At least in the german help this is documented.
For a test: remove the option #PB_String_InPlace
Re: ReplaceString() inside a macro : Bug or not ?
Posted: Mon Jan 15, 2024 10:29 am
by boddhi
infratec wrote: Mon Jan 15, 2024 7:30 am
Read the help for ReplaceString() with the option #PB_String_InPlace
I know that the #PB_String_InPlace option causes ReplaceString() to replace one string with another of exactly the same length, and that it doesn't return any result, which is directly assigned to the variable used.
However, I still don't understand why there are two different behaviors between versions 6.03 (which is ok, but bug ?) and 6.10bX.
I'm going to do it differently to avoid this problem.
Re: ReplaceString() inside a macro : Bug or not ?
Posted: Mon Jan 15, 2024 11:16 am
by jacdelad
The code in the first post works as expected for me, Windows 10 x64, 6.10 Beta 2. However, I don't understand the question and the problem of the second post...
Re: ReplaceString() inside a macro : Bug or not ?
Posted: Mon Jan 15, 2024 12:08 pm
by boddhi
jacdelad wrote:
However, I don't understand the question and the problem of the second post...
boddhi wrote:
here are 2 examples with two exe created with exactly the same code (the first under PB6.03, the second under PB610b2) running under exactly the same conditions.
Note that the message in the 2nd example is not at all the same as in the 1st (it corresponds to the content of a global variable used in other procedures 
).
I should have the same message in example 2 as in example 1, but no...