* * *

Author Topic: Proper way to check SynEdit emptiness?  (Read 958 times)

Sniper

  • New member
  • *
  • Posts: 23
Proper way to check SynEdit emptiness?
« on: April 17, 2018, 10:30:04 am »
if (SynEdit1.SelEnd = 0)

if (SynEdit1.Text = "")

What else?
« Last Edit: April 17, 2018, 10:34:18 am by Sniper »

taazz

  • Hero Member
  • *****
  • Posts: 5336
Re: Proper way to check SynEdit emptiness?
« Reply #1 on: April 17, 2018, 11:11:05 am »
define emptiness please. if you mean no characters then synedit.lines.count = 0 would be the fastest check which might not be 100% you might still have a huge number of empty lines are you consider it empty or not empty then? you could make a bit more involved and do something along the lines of (synedit1.Lines.Count <= 1) and (trim(SynEdit1.Lines.Text) = '') well sky is the limit the only test that will tell if it is empty is the text property though although it will become slower as the file gets larger.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 4781
    • wiki
Re: Proper way to check SynEdit emptiness?
« Reply #2 on: April 17, 2018, 11:16:04 am »
"SelEnd" doesn't look like a correct way. Definitely not guaranteed.

Text = "" should be fine. Though I do not know how that works if space trimming is enabled. Maybe there could be uncommitted trailing spaces.

Lines.Count can be 1, once you edited it, and undone all edits, or otherwise removed all text.

Sniper

  • New member
  • *
  • Posts: 23
Re: Proper way to check SynEdit emptiness?
« Reply #3 on: April 17, 2018, 12:17:01 pm »
if you mean no characters
Yes. No characters at all.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus