Recent

Author Topic: Ellipses Function?  (Read 774 times)

jamie

  • Hero Member
  • *****
  • Posts: 7902
Ellipses Function?
« on: July 22, 2026, 12:58:34 pm »
Without using drawText, is there a Ellipses function somewhere that can pad the string with "." when a given String and limited size given?

jamie

The only true wisdom is knowing you know nothing

cdbc

  • Hero Member
  • *****
  • Posts: 2931
    • http://www.cdbc.dk
Re: Ellipses Function?
« Reply #1 on: July 22, 2026, 01:43:33 pm »
Hi jamie
Do you mean like the 'microslut's 'shorten-fil/.../me-function/ or more like
'......sometext', '...sometext...' and 'sometext......'?!?
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

Handoko

  • Hero Member
  • *****
  • Posts: 5559
  • My goal: build my own game engine using Lazarus
Re: Ellipses Function?
« Reply #2 on: July 22, 2026, 02:15:46 pm »
I still keep the codes I wrote 20 years ago. Maybe this is what jamie wants:

Code: Pascal  [Select][+][-]
  1. function StrEllipsis(const Text: string; MaxLength: Byte): string;
  2. var
  3.   Dots: string;
  4.   B: Byte;
  5. begin
  6.   if Text.Length <= MaxLength then
  7.   begin
  8.     Result := Text;
  9.     Exit;
  10.   end;
  11.   B := 3;
  12.   if B > MaxLength then
  13.     B := MaxLength;
  14.   Dots   := StringOfChar('.', B);
  15.   B      := MaxLength - Dots.Length;
  16.   Result := LeftStr(Text, B) + Dots;
  17. end;

munair

  • Hero Member
  • *****
  • Posts: 902
  • software developer at SSGEOS
    • Solpage
Re: Ellipses Function?
« Reply #3 on: July 22, 2026, 06:38:14 pm »
Or if you prefer it very compact:

Code: Pascal  [Select][+][-]
  1. function EllipStr(const S: string; MaxLength: integer): string;
  2. begin
  3.   result := IfThen(Length(S) > MaxLength, Copy(S, 1, MaxLength - 3) + '...', S);
  4. end;

It's easy to tailor these kind of functions to your needs (truncate right or left, etc.)
It's only logical.

J-G

  • Hero Member
  • *****
  • Posts: 1216
Re: Ellipses Function?
« Reply #4 on: July 23, 2026, 01:39:21 am »
Am I missing something here?

Why would you use multiple 'full stop' Characters [Char(46)]  when there is an 'Ellipsis' already available at Char(133)  -  or [Alt]0133 which shows in the Lazarus Source Editor as a-grave (à)  but on here correctly as '…'  ?

I know my question doesn't advance the knowledge sought but it does seem very odd to me that no one has made reference to it.

FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

jamie

  • Hero Member
  • *****
  • Posts: 7902
Re: Ellipses Function?
« Reply #5 on: July 23, 2026, 02:09:50 am »
I missed spelled the word, its "Ellipsis" and it's a function of where you pad the string with ".." if it does not fit within a confined space.

I made a function to do this but, I found that in the end, it's cheaper to simply use the DrawText directly because of font size calculations and so forth.

doing it otherwise involves using a function that does not seem to be available in other targets other than windows, the "ABC" function to build an array of characters to calculate the complete overall requirement, etc.

 It appears the LCLIntF and LCLType supports the needed defines, so DRawText is cross platform.

Jamie



The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 7902
Re: Ellipses Function?
« Reply #6 on: July 23, 2026, 02:26:46 am »
If anyone is interested in their own interest:

Code: Pascal  [Select][+][-]
  1. procedure TListOfSQLiteCadFilesLibraryBox.ListBox1DrawItem(Control: TWinControl; Index: Integer;
  2.   ARect: TRect; State: TOwnerDrawState);
  3. var
  4.   S:String;
  5. begin
  6.   With (Control as TListBox) do
  7.    Begin
  8.      canvas.Brush.Style := bsSolid;
  9.      Canvas.Brush.Color := Parent.Color;
  10.      Canvas.FillRect(ARect);
  11.      canvas.Brush.Style := bsClear;
  12.      Canvas.font.color := clblack;
  13.      If Index <> -1 Then
  14.      begin
  15.      S := ChangeFileExt(ExtractFileName(Items[Index]),''); //Get File name only and remove EXT
  16.      DrawText(Canvas.Handle,Pchar(S),Length(S),ARect,DT_End_Ellipsis);
  17.      End;
  18.    end;
  19. end;
  20.  
  21.  

This is an ownerDraw ListBox.

Jamie

The only true wisdom is knowing you know nothing

J-G

  • Hero Member
  • *****
  • Posts: 1216
Re: Ellipses Function?
« Reply #7 on: July 23, 2026, 02:35:45 am »
I missed spelled the word, its "Ellipsis" and it's a function of where you pad the string with ".." if it does not fit within a confined space.
[…]

That confused me to start with @Jamie  -  but in fact you used the PLURAL - so not actually a mis-spelling, though technically incorrect  :D

An Ellipsis is in fact a charcter with THREE dots not 2 (or 4) and often enclosed between square brackets  -  […]  to indicate the "there is more to this statement, but no room to show it"   

I often use it when replying to posts when I've deleted some text which has no bearing upon my answer (as you'll see above).
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

H₂SO₄

  • Sr. Member
  • ****
  • Posts: 485
Re: Ellipses Function?
« Reply #8 on: July 23, 2026, 06:48:41 am »
Why would you use multiple 'full stop' Characters [Char(46)]  when there is an 'Ellipsis' already available at Char(133)  -  or [Alt]0133 which shows in the Lazarus Source Editor as a-grave (à)  but on here correctly as '…'  ?

Char(133)  represents an ellipsis in the old Windows-1252 character set, but in the year of our lord 2026 everyone should really be using Unicode. Funnily enough, the corresponding character is called U+2026  :D  (and can be written as an UTF-8  AnsiString  literal like so:  #$E2#80#$A6)

Thaddy

  • Hero Member
  • *****
  • Posts: 19625
  • Glad to be alive.
Re: Ellipses Function?
« Reply #9 on: July 23, 2026, 08:28:15 am »
(and can be written as an UTF-8  AnsiString  literal like so:  #$E2#80#$A6)
Or for literals set {$codepage UTF8} in your sourcecode. This makes it immediate.
You are right to warn about cp1252, other high ascii codepages may (will) not work.
Code: Pascal  [Select][+][-]
  1. {$codepage utf8}
  2. const
  3.    ellipsis = '…';// handy to define as const
  4. begin
  5.   writeln(ellipsis);
  6. end.
  7.  
Requires Console or terminal to work with UTF8 (65001) to display correctly.
In Lazarus GUI apps it is not a problem: alt-0133 maps to U-2026
« Last Edit: July 23, 2026, 09:07:19 am by Thaddy »
Any "programmer" that knows only one programming language is not a programmer

LeP

  • Guest
Re: Ellipses Function?
« Reply #10 on: July 23, 2026, 10:38:46 am »
Why would you use multiple 'full stop' Characters [Char(46)]  when there is an 'Ellipsis' already available at Char(133)  -  or [Alt]0133 which shows in the Lazarus Source Editor as a-grave (à)  but on here correctly as '…'  ?

Char(133)  represents an ellipsis in the old Windows-1252 character set, but in the year of our lord 2026 everyone should really be using Unicode. Funnily enough, the corresponding character is called U+2026  :D  (and can be written as an UTF-8  AnsiString  literal like so:  #$E2#80#$A6)

@Thaddy

This is mine ... and others atc the same ... like you said ... the characters mapped between 128 to 255 should be used in UNICODE ...

Quote
C:\Windows\System32>chcp
Active code page: 1252

C:\Windows\System32>à     <- this is ALT 133

Thaddy

  • Hero Member
  • *****
  • Posts: 19625
  • Glad to be alive.
Re: Ellipses Function?
« Reply #11 on: July 23, 2026, 10:54:46 am »
@LeP
Not alt-133, but alt-0133 maps to ellipsis on utf8.  O:-) … … à: the latter is alt-133 (on my machine) The others are alt-0133...   :D Fun with the alt key.
« Last Edit: July 23, 2026, 11:06:33 am by Thaddy »
Any "programmer" that knows only one programming language is not a programmer

LeP

  • Guest
Re: Ellipses Function?
« Reply #12 on: July 23, 2026, 11:43:28 am »
@LeP
Not alt-133, but alt-0133 maps to ellipsis on utf8.  O:-) … … à: the latter is alt-133 (on my machine) The others are alt-0133...   :D Fun with the alt key.

 :D

@Thaddy, you are right .... never known about that ... thanks

J-G

  • Hero Member
  • *****
  • Posts: 1216
Re: Ellipses Function?
« Reply #13 on: July 23, 2026, 12:53:00 pm »
I did not anticipate such rebuttle - but every day is a school day  :D

You'll appresiate that I have a deal of inertia to overcome as far as keeping up to date with the latest offerings  -  so I have never investigated UNICODE, and have to assume that I am using CP1252 - which 'works' for my needs.

The issue about alt-0133 or alt-133 is peculiar - - -  I did make the specific point of saying that alt-0133 returned à in the Lazarus source editor. In CorelDRAW! (and Excell) it returns the Ellipsis (as I would expect).

Again - in the Lazarus source editor -  alt-133 returns O acute  (Ó)  (in CD à).

As yet I haven't looked at what is output to a document created via a Lazarus compiled program when the string contains the character that appears in the source by typing alt-0133 - I would hope that it is an Ellipsis  -  I do know that the centre dot, '·', does appear where the source editor shows 'À', and the Degree sign, '°', shows as a grey patch

I would be very interested to know what I should do to make the source editor show what is really going to appear in output.


FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

Thaddy

  • Hero Member
  • *****
  • Posts: 19625
  • Glad to be alive.
Re: Ellipses Function?
« Reply #14 on: July 23, 2026, 06:07:38 pm »
The lazarus editor uses the alt-0133 correct:ellipsis  What is your problem? Make your long story short plz.
Any "programmer" that knows only one programming language is not a programmer

 

TinyPortal © 2005-2018