[fpc-pascal] Some RTL functions cry big tears when mixing Pchar and Ansistring/String

Antonio Fortuny a.fortuny at sitasoftware.lu
Tue Jun 11 17:03:36 CEST 2013


Hi Folks.

I don't know how Jeppe is playing around but because I want to make sure 
FPC works preoperly I decided to take some time to see what happens
Yhis is the code snippet I use in Win32 and Linux x86_64
All are Lazaur 1.0.8

Put the code under a TButton and send results to a TMemo:

procedure TFrmMain.BtnTestClick(Sender: TObject);
var
   P: Integer;
   str: String;
   pc: PChar;
   len: Integer;
begin
   str := 'http://bcms.webdev.tralala.com/testudf.php?action=goodanswer';
   len := Length(str);
   P := PosEx('bcms', str, 3);
   Memo1.Lines.Add(Format('search "bcms" in %s: position %d', [str, P]));
   pc := nil;
   ReAllocMem(pc, len + 1);
   Move(PChar(str)^, pc^, len);
   pc[len] := #0;
   P := PosEx('bcms', pc, 3);
   Memo1.Lines.Add(Format('search "bcms" in %s: position %d', [str, P]));
end;

I've made the test with a PChar too

TMemo.Lines shows:
search "bcms" in 
http://bcms.webdev.tralala.com/testudf.php?action=goodanswer: position 8
search "bcms" in 
http://bcms.webdev.tralala.com/testudf.php?action=goodanswer: position 8

which, obviously looks correct. That's what I expect since more than 15 
years (beginning with Delphi and Pos function)

Enjoy,

Antonio.
-- 
Sita Software
*Antonio Fortuny*
Senior Software engineer

220, avenue de la Liberté
L-4602 Niederkorn
Tel.: +352 58 00 93 - 93
www.sitasoftware.lu <http://www.sitasoftware.lu>
Your IT Partner

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20130611/768b15bd/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: efbgabga.jpg
Type: image/jpeg
Size: 2306 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20130611/768b15bd/attachment.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dhigabab.jpg
Type: image/jpeg
Size: 921 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20130611/768b15bd/attachment-0001.jpg>


More information about the fpc-pascal mailing list