Recent

Author Topic: Split Name Quiz (Pascal Skill Challenge)  (Read 1283 times)

x2nie

  • Hero Member
  • *****
  • Posts: 515
  • Impossible=I don't know the way
    • impossible is nothing - www.x2nie.com
Re: Split Name Quiz (Pascal Skill Challenge)
« Reply #15 on: September 15, 2022, 03:51:16 am »
... your provided demo code and saw that you like to play with "UnicodeString"


oops,  :-[  sorry for that dirty code. it was my mistake.
Actually our functions seem as will be used for component name only (not for general string usage),
so perhaps it will never be Unicode.


The reason I did that was because I want to create one function that once component name reconstructed, it will be ready to draw.
My idea was to imitate how "soft hypenation" works in HTML world, sadly current Lazarus/FreePascal can't encode that char (­ in html or U+00AD as official unicode)
Code: Pascal  [Select][+][-]
  1. //sep := utf8encode(#$00AD); //shoft hypenation <-------------- return empty string
IF it was success, we don't need the "another function to join space" (as known as "toLines").
and because it was failed, I though that I need to change the variable type into unicodestring;
but it was actually useless too. The returned value of "utf8encode(#$AD)" is always empty string.


Finally I ended up with using a space (chr(32) / #$20, #32) as separator for string splitting. (see my 3rd picture)
So, reaching that progress, I though "Okay, the count of lines is auto generated by canvas.textrect(), we only need to give parameter for word-wrap width".
But we soon realized that we need to remove space for each line, and voila! there where the "toLines" function was born.


in other hand, your "PrepareStringA" function (together with "toLines()" ) will be called extensively during design time for rendering of every iconic component's name.
I mean we need an extremely efficient code to reduce of painting cost.
Sure I don't want the assembler, but the "inline" use here are appreciated. :-X
(ps: there is no things like inline in python nor javascript :p )


Good Job KodeZwerg we will use your code.


Anyway, is there any special benefit of SUCC and PRED, intead of "i -1" and "i + 1" ?

When you were logged in, you can see attachments.
Lazarus Github @ UbuntuCinnamon-v22.04.1 + LinuxMintDebianEdition5

KodeZwerg

  • Sr. Member
  • ****
  • Posts: 484
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Split Name Quiz (Pascal Skill Challenge)
« Reply #16 on: September 15, 2022, 03:37:36 pm »
Anyway, is there any special benefit of SUCC and PRED, intead of "i -1" and "i + 1" ?
Ugh, for that a Compiler master should answer if +-1 or Pred/Succ have any technical differences inside final compiled binary or during runtime inside memory/heap/stack....
I personal do hate +-1  >:D
« Last Edit: Tomorrow at 31:76:97 by KodeZwerg »

KodeZwerg

  • Sr. Member
  • ****
  • Posts: 484
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Split Name Quiz (Pascal Skill Challenge)
« Reply #17 on: September 16, 2022, 07:10:27 am »
The returned value of "utf8encode(#$AD)" is always empty string.
You should use constant "sLineBreak" to add CRLF.
« Last Edit: Tomorrow at 31:76:97 by KodeZwerg »

y.ivanov

  • Hero Member
  • *****
  • Posts: 554
Re: Split Name Quiz (Pascal Skill Challenge)
« Reply #18 on: September 16, 2022, 08:41:21 am »
The returned value of "utf8encode(#$AD)" is always empty string.
You should use constant "sLineBreak" to add CRLF.
Isn't it LineEnding more appropriate?
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

KodeZwerg

  • Sr. Member
  • ****
  • Posts: 484
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Split Name Quiz (Pascal Skill Challenge)
« Reply #19 on: September 16, 2022, 12:59:38 pm »
You should use constant "sLineBreak" to add CRLF.
Isn't it LineEnding more appropriate?
Isn't it the same? (i am used to that from my formerly IDE)
Why appended a screenshot of my profile with a red box around my signature friend?
« Last Edit: Tomorrow at 31:76:97 by KodeZwerg »

y.ivanov

  • Hero Member
  • *****
  • Posts: 554
Re: Split Name Quiz (Pascal Skill Challenge)
« Reply #20 on: September 16, 2022, 03:14:52 pm »
You should use constant "sLineBreak" to add CRLF.
Isn't it LineEnding more appropriate?
Isn't it the same? (i am used to that from my formerly IDE)
Why appended a screenshot of my profile with a red box around my signature friend?

Not quite sure why. May be because of:
Quote
sLineBreak is an alias for LineEnding and is supplied for Delphi compatibility.

The box contains the spell for your journey into the future.
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

KodeZwerg

  • Sr. Member
  • ****
  • Posts: 484
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Split Name Quiz (Pascal Skill Challenge)
« Reply #21 on: September 16, 2022, 03:32:21 pm »
The box contains the spell for your journey into the future.
I know, obviously i set it there :-*
« Last Edit: Tomorrow at 31:76:97 by KodeZwerg »

 

TinyPortal © 2005-2018