SRL Archive - Lape

Weird access violation


riwu

2014-11-27 05:15:37


function ReplaceWrap(Text, FindStr, ReplaceStr: string; Flags: TReplaceFlags): string;
begin
Result := StringReplace(Text, FindStr, ReplaceStr, Flags);
end;

var
s: string;

begin
s:= chr(95);
writeln(s = chr(95));
try
ReplaceWrap('123', '', s, [rfReplaceAll]);
except
writeln('first call failed');
end;

try
ReplaceWrap('123', '', chr(95), [rfReplaceAll]);
except
writeln('second call failed');
end;
end.

How is chr(95) different from 's'? VarType and SizeOf actually returns different values for them.

slacky

2014-11-27 05:26:30

That is indeed a weird bug.

The sad workarounds:
- String(chr(94))
or
- [(chr(94)]

#Blame_Nielsie95
@nielsie95 lape needs you

riwu

2014-11-27 05:42:51

From: slacky
That is indeed a weird bug.

The sad workarounds:
- String(chr(94))
or
- [(chr(94)]

#Blame_Nielsie95
@nielsie95 lape needs you


Calling StringReplace() directly or Replace() would work, i'm just curious what's causing this strange error.

function ReplaceWrap(Text, FindStr, ReplaceStr: string; Flags: TReplaceFlags): string;
begin
Result := StringReplace(Text, FindStr, ReplaceStr, Flags);
end;

var
s: string;

begin
s:= chr(95);
writeln(s = chr(95));
try
ReplaceWrap('123', '', s, [rfReplaceAll]);
except
writeln('first call failed');
end;

try
ReplaceWrap('123', '', chr(95), [rfReplaceAll]);
except
writeln('second call failed');
end;

try
StringReplace('123', '', chr(95), [rfReplaceAll]);
except
writeln('third call failed');
end;
end.

slacky

2014-11-27 05:54:59

From: riwu
Calling StringReplace() directly or Replace() would work, i'm just curious what's causing this strange error.
…

If I knew I would tell you. But that requires me to look through lape sources to find the bug.
And it's pretty weird that it works with imported methods, but that gives a good clue about where the issue is :)
I'm sorry I can't be of more help.


maybe @nielsie95 wanna do some work on lape :P

We need to pressure nilsie95 to allocate more time for lape ;-)

nielsie95

2014-11-28 14:54:25

Interesting bug, thanks for reporting! I think I might have found the cause :)