Recent

Author Topic: Chart Title on 2 lines [SOLVED]  (Read 624 times)

AL

  • Full Member
  • ***
  • Posts: 170
Chart Title on 2 lines [SOLVED]
« on: November 26, 2019, 04:57:58 pm »
When I try to modify the chart title with an inputbox,  I always get a title on 2 lines when I only add some text in the input box.
If I erase the last character and then type more characters then the title is on one line as it should.
It seems like a line feed is in the original title and InputBox keeps it.

Any Hint?

 NewTitle:= (Inputbox (RsNewTitle ,RsEnterNewTitl , SpectrumChart.Title .Text .Text));
 SpectrumChart.Title.Text.Text := NewTitle ;                       

Thanks
« Last Edit: January 08, 2020, 04:19:22 am by AL »
Laz 2.1.0, fpc 3.3.1, Win10
Laz 2.1.0, fpc3.3.1, Mac OS Mojave running on VMWare

wp

  • Hero Member
  • *****
  • Posts: 7378
Re: Chart Title on 2 lines
« Reply #1 on: November 26, 2019, 05:36:30 pm »
TChart.Title.Text is a TStrings class. And every TStrings instance, when its items are stuffed into a single string, has a line feed at its end:
Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. uses
  4.   Classes;
  5.  
  6. var
  7.   L: TStrings;
  8. begin
  9.   L := TStringList.Create;
  10.   L.Add('ABC');
  11.   WriteLn('---------');
  12.   WriteLn(L.Text);
  13.   WriteLn('---------');
  14.   WriteLn(L[0]);
  15.   WriteLn('---------');
  16.  
  17.   ReadLn;
  18. end.  
See the empty line after the first 'ABC'? This is the same line break that you are talking abount.

As a workaround you could simply use the first element of the TStrings: Chart.Title.Text.Text[0] (but don't forget to check against an empty list: "if Chart.Title.Text.Count > 0 then...").

Or you could filter the ending linebreak from the input string before passing it to the input box:
Code: Pascal  [Select][+][-]
  1. function CleanString(AString: String): String;
  2. begin
  3.   Result := AString;
  4.   while (Result <> '') and (Result[Length(Result)] in [#13, #10]) do
  5.     Delete(Result, Length(Result), 1);
  6. end;
  7.  
  8. procedure TForm1.Button1Click(Sender: TObject);
  9. var
  10.   NewTitle: String;
  11. begin
  12.    NewTitle := Inputbox ('New Title', 'Text', CleanString(Chart1.Title.Text.Text));
  13.    Chart1.Title.Text.Text := NewTitle;
  14. end;
     
Or you could design a dedicated input form with a memo because TAChart does support multi-line titles, and there is no other way to input a multiline title at GUI level without a memo.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

lucamar

  • Hero Member
  • *****
  • Posts: 2973
Re: Chart Title on 2 lines
« Reply #2 on: November 26, 2019, 06:27:01 pm »
Alternatively, you can set the TStrings property SkipLastLineBreak to True to prevent that final line break.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

AL

  • Full Member
  • ***
  • Posts: 170
Re: Chart Title on 2 lines
« Reply #3 on: November 26, 2019, 08:00:48 pm »
Alternatively, you can set the TStrings property SkipLastLineBreak to True to prevent that final line break.

That did it.  Thank you very much
 
      SpectrumChart.Title .Text.SkipLastLineBreak:= true;
      NewTitle:= (Inputbox (RsNewTitle ,RsEnterNewTitl , SpectrumChart.Title .Text.Text));
      SpectrumChart.Title.Text.Text := NewTitle ;                                         
Laz 2.1.0, fpc 3.3.1, Win10
Laz 2.1.0, fpc3.3.1, Mac OS Mojave running on VMWare

 

TinyPortal © 2005-2018