Recent

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

VTwin

  • Hero Member
  • *****
  • Posts: 1227
  • Former Turbo Pascal 3 user
Re: Length Not Working Like It Should
« Reply #15 on: April 11, 2019, 01:21:31 am »
“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)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12202
  • Debugger - SynEdit - and more
    • wiki
Re: Length Not Working Like It Should
« Reply #16 on: April 11, 2019, 02:06:13 am »
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

3) I am not aware of any such issue in recent days. But maybe (and that could be misleading) you did read, that TEdit.Text does not return a value in the debugger. If so, that only refers to what the debugger sees. The application itself would still see the value.

Anyway, in order to help you it would be good if someone could reproduce the issue.

a) Can you try and see if it works in a new simple app
- Put a TEdit on a form
- Put a button on it
- in the button OnClick handler do: Caption := length(Edit1.Text);

Does the form's caption update according to the length of the text?

b) In your app:
- The text is entered by the user (rather than being set by the app)?
  You do NOT have code like: Edit1.Text := '...'; ?
- In what procedure do you do "length(Edit.Text)" ? Triggered by what event? Some button click, some other event?


c)
Your footer says: Lazarus 2.0 w/FPC-3.0.4 • Windows 7
That does apply to the app on which you experience the issue?

Any 3rd party packages installed / used in your app  (even if you think they are unrelated)?

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12715
  • FPC developer.
Re: Length Not Working Like It Should
« Reply #17 on: April 11, 2019, 11:35:30 am »
I have similar problem
Code: Pascal  [Select][+][-]
  1. writeln(i);
Outputs 5, but  expected is 3.

Expected is  √-1

Is it still the case that in physics "j" is used instead of "i" ?

wp

  • Hero Member
  • *****
  • Posts: 13418
Re: Length Not Working Like It Should
« Reply #18 on: April 11, 2019, 11:48:11 am »
"j" has been used in electrical engineering to avoid confusion with the symbol for current (I), physics always has used "i".

lucamar

  • Hero Member
  • *****
  • Posts: 4217
Re: Length Not Working Like It Should
« Reply #19 on: April 11, 2019, 01:18:36 pm »
1) It is a TEdit text box.  And the property is Text not Caption

My example uses Edit1.Text everywhere. The only Caption you'll see is that of the label used for the results

Quote
2) The length is returning the value of 0

Which is not the case for my example/test. That's why we need to see more of your code.

Quote
3) I don't remember where I saw that it was a bug, but it was on this forum somewhere

I'm unable to find anything related. Maybe it was some (very) old bug ... <shrugs>

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

Yes, but that is what it does here! There must be something else going on in your code if you're really seeing that.

I've modified my example/test a little so that it shows full(er) results. Note that I didn't program this because I like to brag about my skills but to show that it works here and to have a base program for you to test and see if it behaves differently in your system. Please, use it!.
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 #20 on: April 11, 2019, 01:28:35 pm »
That is how I have it setup, but, I didn't use DateTime const to evaluate.

Your example works perfectly THANK YOU!!!
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 #21 on: April 11, 2019, 01:46:15 pm »
That is how I have it setup, but, I didn't use DateTime const to evaluate.
Let me guess: you were converting the string "by hand" (so to say)? ;)
Note that apart TryStrToDateTime() you have also TryStrToDate() and TryStrToTime(), if you need to make sure there is only a date or a time, respectively. The nice thing about them is that with just one call you can both: ascertain whether the string can be converted and, if so, convert it.

BTW, I'm not using any "const" (other than the resource string): just a TDateTime var.

Quote
Your example works perfectly THANK YOU!!!
Not at all; I love programing and building these little tests is always funny :)
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 #22 on: April 11, 2019, 02:05:30 pm »
That is how I have it setup, but, I didn't use DateTime const to evaluate.
Let me guess: you were converting the string "by hand" (so to say)? ;)
Note that apart TryStrToDateTime() you have also TryStrToDate() and TryStrToTime(), if you need to make sure there is only a date or a time, respectively. The nice thing about them is that with just one call you can both: ascertain whether the string can be converted and, if so, convert it.

BTW, I'm not using any "const" (other than the resource string): just a TDateTime var.

Quote
Your example works perfectly THANK YOU!!!
Not at all; I love programing and building these little tests is always funny :)

Cool... that was my next step is to validate that the date is , well, valid.

Thanks for the tips!!!
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

 

TinyPortal © 2005-2018