Recent

Author Topic: [SOLVED] Length Not Working Like It Should  (Read 4122 times)

pixelink

  • Hero Member
  • *****
  • Posts: 1269
[SOLVED] Length Not Working Like It Should
« on: April 09, 2019, 10:18:20 pm »
This is what I am trying....

Code: Pascal  [Select][+][-]
  1. if Length(txtTime.text) < 8 then
  2.  
  3. And this one...
  4.  
  5. if UTF8Length(txtTime.text) < 8 then
  6.  

Neither of them returns a proper number. I only get 0
I read that is was a bug... is this still the case or has it been fixed?
OR
Am i doing something wrong again.
« Last Edit: April 11, 2019, 01:29:28 pm by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 4.2.0 •  VSSTUDIO(.Net) 2022 • Win11 • 32G RAM • Nvida RTX 4070 Ti Super

bigeno

  • Sr. Member
  • ****
  • Posts: 266
Re: Length Not Working Like It Should
« Reply #1 on: April 09, 2019, 10:20:29 pm »
What is txtTime.text ?

bytebites

  • Hero Member
  • *****
  • Posts: 778
Re: Length Not Working Like It Should
« Reply #2 on: April 09, 2019, 10:31:14 pm »
I have similar problem
Code: Pascal  [Select][+][-]
  1. writeln(i);
Outputs 5, but  expected is 3.

wp

  • Hero Member
  • *****
  • Posts: 13398
Re: Length Not Working Like It Should
« Reply #3 on: April 09, 2019, 11:50:10 pm »
Are you saying that when i is 3 writeln(i) prints 5? This joke is too late for April Fools Day!

lucamar

  • Hero Member
  • *****
  • Posts: 4217
Re: Length Not Working Like It Should
« Reply #4 on: April 09, 2019, 11:56:22 pm »
I have similar problem
Code: Pascal  [Select][+][-]
  1. writeln(i);
Outputs 5, but  expected is 3.

As it should be obvious, something else is at fault here: writeln(i) just writes whatever value i has. If it's 5 but should be 3, look wherever i is set.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

pixelink

  • Hero Member
  • *****
  • Posts: 1269
Re: Length Not Working Like It Should
« Reply #5 on: April 10, 2019, 12:31:50 am »
What is txtTime.text ?

A text control field of course.
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 4.2.0 •  VSSTUDIO(.Net) 2022 • Win11 • 32G RAM • Nvida RTX 4070 Ti Super

lucamar

  • Hero Member
  • *****
  • Posts: 4217
Re: Length Not Working Like It Should
« Reply #6 on: April 10, 2019, 01:01:48 am »
What is txtTime.text ?

A text control field of course.

What kind of "text control field". Give us the class name, at least!

Also, you may try to insert a line with:
    ShowMesageFmt('"%s"', [txtTime.text]);
to ascertain whether it really contains something.

Finally, where did you read about this "bug"? We can't know if there really was a bug and, if so, whether it has been quashed without knowing what you're talking about.

I ask because I've been using various TCustomEdit descendants and other controls with Text properties for years (including using Length and LengthUTF8) and I've never seen anything remotely related to what you're supposedly seeing.
« Last Edit: April 10, 2019, 01:09:23 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

pixelink

  • Hero Member
  • *****
  • Posts: 1269
Re: Length Not Working Like It Should
« Reply #7 on: April 10, 2019, 01:04:08 am »
What is txtTime.text ?

A text control field of course.

What kind of "text control field". Give us the class name, at least!

it is a plain old text field.
I need to evaluate the time that is entered into the field.
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 4.2.0 •  VSSTUDIO(.Net) 2022 • Win11 • 32G RAM • Nvida RTX 4070 Ti Super

ASerge

  • Hero Member
  • *****
  • Posts: 2477
Re: Length Not Working Like It Should
« Reply #8 on: April 10, 2019, 07:02:34 am »
it is a plain old text field.
I need to evaluate the time that is entered into the field.
Did you notice that at first your question was taken as a joke? It is clear that "if Length(txtTime.text) < 8 then " is true when the length of string is less than eight (for example zero, as you mentioned). So without a detailed explanation of what exactly "bug" it will look like a joke.

wp

  • Hero Member
  • *****
  • Posts: 13398
Re: Length Not Working Like It Should
« Reply #9 on: April 10, 2019, 09:40:52 am »
it is a plain old text field.
"Text field" could also be a "field" of a database. But TField has no ".Text" property - or has it? So I have to look into the sources whether there is such a property. Yes. it has.

Hmmm... Or do you mean: TEdit?

Why do keep us guessing what you mean? If you'd say "TEdit" everything would be clear.
« Last Edit: April 10, 2019, 10:36:32 am by wp »

lucamar

  • Hero Member
  • *****
  • Posts: 4217
Re: Length Not Working Like It Should
« Reply #10 on: April 10, 2019, 11:35:54 am »
it is a plain old text field.
I need to evaluate the time that is entered into the field.

OK, since you don't care to say what class it's I'll assume is a TEdit or sibling. Find attached a small test and the results, showing that it does in fact work.

We can't help you adequately unless you give us more (detailed) info.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

BeniBela

  • Hero Member
  • *****
  • Posts: 958
    • homepage
Re: Length Not Working Like It Should
« Reply #11 on: April 10, 2019, 11:46:36 am »
I have similar problem
Code: Pascal  [Select][+][-]
  1. writeln(i);
Outputs 5, but  expected is 3.

Expected is  √-1

lucamar

  • Hero Member
  • *****
  • Posts: 4217
Re: Length Not Working Like It Should
« Reply #12 on: April 10, 2019, 11:50:18 am »
I have similar problem
Code: Pascal  [Select][+][-]
  1. writeln(i);
Outputs 5, but  expected is 3.
Expected is  √-1
+1 :D ;D
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

pixelink

  • Hero Member
  • *****
  • Posts: 1269
Re: Length Not Working Like It Should
« Reply #13 on: April 11, 2019, 01:00:05 am »
it is a plain old text field.
I need to evaluate the time that is entered into the field.

OK, since you don't care to say what class it's I'll assume is a TEdit or sibling. Find attached a small test and the results, showing that it does in fact work.

We can't help you adequately unless you give us more (detailed) info.

1) It is a TEdit text box.  And the property is Text not Caption
2) The length is returning the value of 0
3) I don't remember where I saw that it was a bug, but it was on this forum somewhere

If the text string in the TEdit.Text is "3:00 PM"
Length should be returning 7 characters, not 0

Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 4.2.0 •  VSSTUDIO(.Net) 2022 • Win11 • 32G RAM • Nvida RTX 4070 Ti Super

VTwin

  • Hero Member
  • *****
  • Posts: 1227
  • Former Turbo Pascal 3 user
Re: Length Not Working Like It Should
« Reply #14 on: April 11, 2019, 01:09:31 am »
What is txtTime.text ?

A text control field of course.

Of course. We can all read your mind.
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 15.3.2: Lazarus 3.8 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 3.8 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 3.8 (64 bit on VBox)

 

TinyPortal © 2005-2018