Recent

Author Topic: Bug in Left() function  (Read 2202 times)

PsaCrypt

  • New Member
  • *
  • Posts: 21
Bug in Left() function
« on: May 19, 2018, 03:34:04 pm »
Hello, tracing a new error converting from my sourcecode I found this:

showmessage(left('-255R', 1));

It returns '2', but must return '-'.

:-(

bigeno

  • Sr. Member
  • ****
  • Posts: 266
Re: Bug in Left() function
« Reply #1 on: May 19, 2018, 03:39:03 pm »
Where is left function ? you should use LeftStr maybe ?

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: Bug in Left() function
« Reply #2 on: May 19, 2018, 03:54:31 pm »
I got compile time error (syntax) if I do this:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   showmessage(left('-255R', 1));
  4. end;

It happens because Left is a property of TControl.

Instead, I got correct result if I use LeftStr.

Thaddy

  • Hero Member
  • *****
  • Posts: 14213
  • Probably until I exterminate Putin.
Re: Bug in Left() function
« Reply #3 on: May 19, 2018, 04:32:44 pm »
Indeed.
As can be also demonstrated by pure FPC's:
Code: Pascal  [Select][+][-]
  1. {$ifdef windows}{$apptype console}{$endif}
  2. uses sysutils;
  3. begin
  4. writeln(leftstr('-255R', 1));
  5. end.

Programmer error.
Left is BASIC syntax. (Was a programming language at some point).
« Last Edit: May 19, 2018, 05:06:52 pm by Thaddy »
Specialize a type, not a var.

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: Bug in Left() function
« Reply #4 on: May 19, 2018, 05:43:58 pm »
I wonder how the TS didn't get the compile time error. Or if he used LeftStr, why he got the incorrect result ... maybe that Left function was written by himself.

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: Bug in Left() function
« Reply #5 on: May 19, 2018, 05:46:53 pm »
Or a function of that NAME was created with those parameters and it just isn't working.....?
The only true wisdom is knowing you know nothing

PsaCrypt

  • New Member
  • *
  • Posts: 21
Re: Bug in Left() function
« Reply #6 on: May 20, 2018, 07:41:59 am »
yes, Lazarus use LeftStr().  Sorry.

Left() is mine.
« Last Edit: May 20, 2018, 09:09:14 am by PsaCrypt »

 

TinyPortal © 2005-2018