Recent

Author Topic: Listview how to custom or show subtitle  (Read 1022 times)

jenson

  • New Member
  • *
  • Posts: 12
Listview how to custom or show subtitle
« on: September 11, 2024, 06:10:31 pm »
Hello boy and girl
Im new pascal user about 2 month level. but speed more time to find few new idea.

How to custom listview, i just want show listview from socket not need sort table. here is my full example code.

----
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ComCtrls;
type
  { TForm1 }
  TForm1 = class(TForm)
    Button1: TButton;
    ImageList: TImageList;
    Label1: TLabel;
    ListView1: TListView;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
  public
  end;
var
  Form1: TForm1;
implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
begin
  if ListView1.Columns.count < 3 then begin
     ListView1.Columns.Add.Caption := '';  {--hide--Columns-header--}
     ListView1.Columns.Add.Caption := '';  {--hide--Columns-header--}
     ListView1.Columns.Add.Caption := '';  {--hide--Columns-header--}
     ListView1.Columns.Add.Caption := '';  {--hide--Columns-header--}
     ListView1.Columns[0].Width:=120;
     ListView1.Columns[1].Width:=80;
     ListView1.Columns[2].Width:=80;
     ListView1.Columns[3].Width:=50;
 end;
end;

{---maybe-need-custom-listview--why-not-find-more-documents-for-many-year-ago-}

procedure TForm1.Button1Click(Sender: TObject);
var
  Item: TListItem;
begin
    ListView1.AddItem('Long title need to full display',Tobject(1));
    ListView1.Caption :=  'how to display subtitle here is option';
   // ListView1.AddControl;
    Item := ListView1.Items.Add;
    Item.Caption :=  'Tags short name';
    Item.SubItems.Add('10868');
    Item.SubItems.add('981260');
    Item.SubItems.add('');
    Item.SubItemImages[0]:=0;
    Item.SubItemImages[1]:=1;
    Item.SubItemImages[2]:=2;
    //here need add line or any distance
end;

end.
----------------------------------------
my question:
how to show the --> ListView1.AddItem('Long title need to full display',Tobject(1));
and how to custom new listview and want add subtitle.
and how disable the Caption space when not set Item.Caption vaule. (why must keep the caption space gap?)
--------------------------------------
Of course,

I suggest official team add new component used for internet news view, wasn than classical table to sort. today is 2024 year we need new ideas.
thanks your, if you can pointing me how custom listview or advice.
« Last Edit: September 11, 2024, 06:15:26 pm by jenson »

VisualLab

  • Sr. Member
  • ****
  • Posts: 445
Re: Listview how to custom or show subtitle
« Reply #1 on: September 12, 2024, 04:59:00 pm »
my question:
how to show the --> ListView1.AddItem('Long title need to full display',Tobject(1));
and how to custom new listview and want add subtitle.
and how disable the Caption space when not set Item.Caption vaule. (why must keep the caption space gap?)

The TListView control is a system control (widget). Its behavior is closely related to what the designers of the OS (Windows) or the windowing subsystem (Linux) intended. You can change the display mode by setting the IconOptions, ToolTips and ViewStyle properties. When the ToolTips property is enabled (True), and the captions are too long, the item name is displayed in the tooltip.

To display content (data) in a tabular view, you can use TStringGrid (or TDrawGrid) instead of TListView. But its operation is completely different from TListView.


I suggest official team add new component used for internet news view, wasn than classical table to sort. today is 2024 year we need new ideas.
thanks your, if you can pointing me how custom listview or advice.

I suggest the person suggesting to write such a control themselves :)

Seriously - writing a new control with a different action than the previous one is not that easy (and requires a lot of free time). It requires knowledge and experience about building control classes, how LCL works, how events are handled, etc. This is not a trivial task. Unless the control is only supposed to display data in a form similar to a table, then you can write code using for example the TPaintBox class.

Maybe the TListView control can be adapted to your needs? The screenshot you attached doesn't really explain what you want from TListView. I think a good starting point would be to describe what you want to achieve. Additionally, you can draw (e.g. in LibreOffice Draw) some simple mockup (as a PNG or JPG) of what you want to display.
« Last Edit: September 12, 2024, 05:01:06 pm by VisualLab »

jenson

  • New Member
  • *
  • Posts: 12
Re: Listview how to custom or show subtitle
« Reply #2 on: September 13, 2024, 07:32:51 am »
VisualLab, Thank you

I see, But i find more user post more about "how to do this, do that" on forum, user want know more. however, official web just use toothpaste examples to describe that how to create one new component.
btw, the google, github still not find more one simple examples. (for example: define text, display text. only use one line code or sentence that can let new user how to do it?)

About the screenshot, i want use listview display stream text like news title + tts voice download. listview need timely update base on dynamic queue, remove old listview and append new title. user (client) just only read like title or down tts voice.

I choose lazarus reasonis that lazarus support utf8. but find more user (from forum) just want change few color, few boardstyle... I just need time or fast way get few pointing.

Bty, the cloudflare is world very bad dns provider. they block sf.net,sourceforge website,stackoverflow.com etc, so learning lazarus so hard.

cloudflare not block forum.lazarus.freepascal.org, yes they can get my email and id that so happly. i get you. lol.
« Last Edit: September 13, 2024, 12:55:35 pm by jenson »

jenson

  • New Member
  • *
  • Posts: 12
Re: Listview how to custom or show subtitle
« Reply #3 on: September 13, 2024, 10:55:18 am »
Share about listview group subtitle example with delphi.

--------------------part code with delphi------

procedure TForm1.FormCreate(Sender: TObject);
begin
  if ListView1.Columns.count < 3 then begin
     ListView1.Columns.Add.Caption := '';  {--hide--Columns-header--}
     ListView1.Columns.Add.Caption := '';  {--hide--Columns-header--}
     ListView1.Columns.Add.Caption := '';  {--hide--Columns-header--}
     ListView1.Columns.Add.Caption := '';  {--hide--Columns-header--}
     ListView1.Columns[0].Width:=95;
     ListView1.Columns[1].Width:=80;
     ListView1.Columns[2].Width:=80;
     ListView1.Columns[3].Width:=24;
 end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  Group: TListGroup;
  Item: TListItem;
  image: tbitmap;
begin
  ListView1.items.beginupdate;
  Group := ListView1.Groups.Add;
  Group.GroupID := ListView1.Groups.NextGroupID;
  Group.TitleImage := 8;
  Group.Header := 'Here is long title need full display ';
  Group.HeaderAlign:= taLeftjustify;
  Group.Subtitle := 'Here is subtitle about intro ...';
  Item := ListView1.Items.Add;
  Item.GroupID := Group.GroupID; //need using stream data id
  Item.Caption := inttostr(Item.GroupID) + 'Tags short name';
  Item.imageindex:=-1;
  Item.SubItems.Add('10868');
  Item.SubItems.add('981260');
  Item.SubItems.add('');
  Item.SubItemImages[0]:=1;
  Item.SubItemImages[1]:=2;
  Item.SubItemImages[2]:=3;
  Group.Footer := 'Here is empty to keep line height';
  ListView1.items.endupdate;
end;

--------------------part code with delphi------

since delphi can not display utf8 data from db. even can not wirte into db. firedac is same question.
when your application use offline built-in db. user can not move application to other computer, because different window language, lcid etc, new computer not display non-english character.
that so bad logic today. why use lcid to limit user language. so you choose Lazarus is best way.
« Last Edit: September 13, 2024, 12:46:13 pm by jenson »

VisualLab

  • Sr. Member
  • ****
  • Posts: 445
Re: Listview how to custom or show subtitle
« Reply #4 on: September 13, 2024, 05:06:37 pm »
Share about listview group subtitle example with delphi.

Code: Pascal  [Select][+][-]
  1. ...
  2. procedure TForm1.Button1Click(Sender: TObject);
  3. var
  4.   Group: TListGroup; // <- this class is not present in the sources of the TListView control from the LCL library...
  5.   Item: TListItem;
  6.   image: tbitmap;
  7. begin
  8.   ListView1.items.beginupdate;
  9.   Group := ListView1.Groups.Add; // ...so it won't work
  10.   Group.GroupID := ListView1.Groups.NextGroupID; // ...and that won't work either
  11.   Group.TitleImage := 8; // ...and that won't work either
  12.   Group.Header := 'Here is long title need full display '; // ...and that won't work either
  13.   Group.HeaderAlign:= taLeftjustify; // ...and that won't work either
  14.   Group.Subtitle := 'Here is subtitle about intro ...'; // ...and that won't work either
  15. ...


Unfortunately, the TListView control (widget) present on the Lazarus palette does not have the Groups and GroupView properties, which the TListView control present in Delphi does. At least that's what the LCL library in Lazarus 3.4 does. The documentation of this class (from Lazarus) is available at: TListView.

As for the continuous display of successively appearing data1), you can use TListView operating in external data display mode, i.e. by setting the OwnerData and OwnerView properties to True and programming events: OnDrawItem and OnData, OnDataFind, OnDataHint. However, you probably won't like the view mode, because this is mainly intended for ViewStyle = vsReport.

---
1) I.e. the oldest item of the list is removed, the next item is added to its end, i.e. displaying in data streaming mode.

jenson

  • New Member
  • *
  • Posts: 12
Re: Listview how to custom or show subtitle
« Reply #5 on: September 14, 2024, 04:43:56 am »
At first, i think the listview or other similar component should contain stream browse, this is basic component function for Internet.
above code only show and lets everyone know it, we can do more use lazarus.

try to create new component maybe is best way, but need few simple example to learning. this page https://wiki.freepascal.org/How_To_Write_Lazarus_Component
can not let new user get more. it only just have few step.
« Last Edit: September 14, 2024, 05:40:28 am by jenson »

VisualLab

  • Sr. Member
  • ****
  • Posts: 445
Re: Listview how to custom or show subtitle
« Reply #6 on: September 14, 2024, 02:07:51 pm »
At first, i think the listview or other similar component should contain stream browse, this is basic component function for Internet.

But what streams? Do you mean streams represented by the TStream class (or its descendants)? Such a stream can contain a variety of data. The programmer's role here is to write procedures that retrieve this data from the stream and pass it to the list in the form that the list can display. A separate issue is the presence (or lack) of these features in TListView that you would like to use. Also note that the TListView control is designed to support the GUI of typical window programs. It was not designed for Internet applications (like other GUI controls, by the way). I understand your disappointment, because I myself have often needed something that was not in the standard library. And I had to do it myself. This is the everyday work of most programmers.

try to create new component maybe is best way, but need few simple example to learning. this page https://wiki.freepascal.org/How_To_Write_Lazarus_Component
can not let new user get more. it only just have few step.

Well, designing and implementing complex controls that are interactive is quite a difficult and time-consuming task. I'm afraid there is no comprehensive manual for creating them. And not just in the Object Pascal language. I used books describing the VCL library (from Delphi), on which the LCL library is modeled to some extent. But the vast majority of knowledge and experience I gained through:
  • browsing and analyzing the source code of classes from the VCL library,
  • creating new classes myself: components and controls.
Similarly, I analyzed (and often still do) the source code of the FCL and LCL libraries.

This is a slow and time-consuming process, but I guess there are no "shortcuts". I think the reason why there are no thick and comprehensive manuals available that describe in detail how to create complex controls for Lazarus (and Delphi) is that:
  • such a book would take a very long time to write,
  • its authors would have to prepare a lot of examples (including source code),
  • the examples would have to be supplemented with screenshots, descriptions of algorithms and design patterns used in building controls.
Unfortunately, no one has enough free time to do this. Therefore, most programmers who know how to create controls probably followed a path similar to mine. What I wrote doesn't help, of course, but I think that no one should be deceived (or given false hope).

wp

  • Hero Member
  • *****
  • Posts: 12345
Re: Listview how to custom or show subtitle
« Reply #7 on: September 14, 2024, 04:41:18 pm »
Do you need an inplace editor? If not, you could use an owner-drawn ListBox rather than a ListView. Owner-drawing means that you can display any information in any line in any arrangement. Requires some programming though...

zeljko

  • Hero Member
  • *****
  • Posts: 1642
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Listview how to custom or show subtitle
« Reply #8 on: September 14, 2024, 08:45:48 pm »
You should use TVirtualStringTree IMO.

jenson

  • New Member
  • *
  • Posts: 12
Re: Listview how to custom or show subtitle
« Reply #9 on: September 16, 2024, 05:36:20 pm »
Yeah,i think all program language should become simple.
"Shortcuts" that my need. Window PC application language update too slow. i love internet program code, js,swift,electron,python, and so easy to learning.

If just program tradition pc application, lazarus and delphi are so good and easy. but me need few new function display streams info, as http, ws, p2p, irc, mqtt message. i find lz and delphi can not display one base web page. ie.: use TwebBrowser component can not load an resources(RCDATA) file (its include html+js+css), since TwebBrowser base on ie9, its can not contain indexof and filter etc. use webkit can do few thing but pascal forget to update the webkit. you know old webkit still better than the ie9.

ok, you maybe want ask me, why not use cef3,or mircosoft new Browser component?
because, today all Browser is spy tools. only a bit cookies, all Browser integration webrtc,ws,and more private protocol. they just want help you save data to cloud.

i just want use smallest code, smallest size to build few small pc application. use ws, http only want build an chat/talk application etc.
But Browser use the ws,rtc that is thief tools.

Now, assume your need build the chat application use the delphi or lazarus. you need design db, cache, queue, chat listviw, wss authenticate (dont talk me use old way to connect wss, that you can help google robot essy to get more).

Current, i know and find more quesiton when use vc,lazarus,delphi. i am new pascal user. so need few time.

VisualLab

  • Sr. Member
  • ****
  • Posts: 445
Re: Listview how to custom or show subtitle
« Reply #10 on: September 16, 2024, 11:38:39 pm »
Yeah,i think all program language should become simple.

Simpler, which means what? What is this simplicity supposed to consist of? Because each person probably understands simplicity a bit differently. For one person, a Trabant car is simple, while a Boeing 777 is complicated. And for another, a stick is simple, while a Trabant is incredibly complicated. Besides, there were many before you who wanted simple languages. And they set out to create them. Denis Ritchie also created a very simple programming language. So what, is C simple? Graydon Hoare was annoyed that C was terrible, complicated, and full of traps, so he started creating Rust. So what, is Rust simple? It was the same every time - after many years, every simple programming language became complicated, even Python, adored by script kiddies :)

Window PC application language update too slow.

Which language? Or maybe you mean the process of developing programming languages? There is no such thing as a "Windows PC programming language". Some programming languages ​​are narrowly specialized (JavaScript, Matlab, R), others have broader applications (e.g. those compiled to machine code). The development of languages ​​is decided by people involved in the tools (compilers, interpreters) that allow these languages ​​to be used in practice. And the users choose what suits them.

i love internet program code, js,swift,electron,python, and so easy to learning.

OK. So use them. But if you are asking on this forum about solving some programming problems, then I suspect that the languages ​​you mentioned have some flaws and/or limitations. Otherwise, you wouldn't be asking. It's true that they are easy to learn. But at the same time, they also have limited capabilities. These are languages ​​for writing scripts, not creating software programs.

If just program tradition pc application, lazarus and delphi are so good and easy. but me need few new function display streams info, as http, ws, p2p, irc, mqtt message.

What you wrote about are data transfer protocols, not streams. Data streams are handled by internal classes of the WWW browser. Writing a class that supports these protocols requires considerable programming knowledge.

i find lz and delphi can not display one base web page. ie.: use TwebBrowser component can not load an resources(RCDATA) file (its include html+js+css), since TwebBrowser base on ie9, its can not contain indexof and filter etc. use webkit can do few thing but pascal forget to update the webkit. you know old webkit still better than the ie9.

The part of the browser that handles data processing (HTML, CSS, JS) and its display and playback is significantly complex. Those are thousands of classes written in C++. KDE programmers, then Apple and Google, wrote and improved it for many years. What Delphi or Lazarus offers is a set of classes that provide the facade of this vastness.

ok, you maybe want ask me, why not use cef3,or mircosoft new Browser component?
because, today all Browser is spy tools. only a bit cookies, all Browser integration webrtc,ws,and more private protocol. they just want help you save data to cloud.

Well, you can always try using C++, C# or Java. But there will be some difficulties when programming in these languages, just like in the case of Object Pascal. It is often a matter of the size and capabilities of the libraries.

i just want use smallest code, smallest size to build few small pc application. use ws, http only want build an chat/talk application etc.
But Browser use the ws,rtc that is thief tools.

Web service applications that need to use network protocols seem simple to build. But that's an illusion. Their internal architecture is typically quite complex.

Now, assume your need build the chat application use the delphi or lazarus. you need design db, cache, queue, chat listviw, wss authenticate (dont talk me use old way to connect wss, that you can help google robot essy to get more).

Well, if you want to create such a program, then the burden of designing it, selecting tools and libraries falls on you. But you will also have to write a lot of code yourself. This is what programming is all about. We can only advise you, point out some solutions or try to find errors when you encounter a more difficult problem. But you are the author and you know best what the goal you are striving for should look like.

Current, i know and find more quesiton when use vc,lazarus,delphi. i am new pascal user. so need few time.

Yes. Most of the participants of this forum have gone down this path in the past (and some are probably still on it).



You may be offended (although that's not the goal), but if you started your "encounter with programming" by creating websites (HTML, CSS, JS) and then writing scripts in Python, then I understand the difficulties that arise (that's what your complaining suggests). Writing simple things in scripting languages (especially: Python, Electron, etc. monsters and nightmares) gives a false sense of being able to program. Because many people think that writing programs consists of taking library X, then gluing it to library Y, and then connecting what was created to Z.

I myself remember how many years ago (17-20) on some forum someone wrote that he wanted to create a game of the FPP shooter type, in connection with which he had a question whether there was a component like TQuake (or similar), because it would allow him to simplify writing "his" game. Needless to say, the regulars had a lot of fun. Besides, at that time there was a lot of criticism of the component and widget approach (unfairly, as time has shown).

However, programming is not about "gluing libraries together" or "placing components on forms". Yes, libraries are very useful (even desirable) so as not to "reinvent the wheel". But there are no libraries that solve every problem. So you either have to adapt what is there (classes, procedures) to your needs or write the necessary code yourself. And that requires a lot of learning and work.
« Last Edit: September 17, 2024, 05:34:06 pm by VisualLab »

jenson

  • New Member
  • *
  • Posts: 12
Re: Listview how to custom or show subtitle
« Reply #11 on: September 17, 2024, 05:06:49 am »
Do you need an inplace editor? If not, you could use an owner-drawn ListBox rather than a ListView. Owner-drawing means that you can display any information in any line in any arrangement. Requires some programming though...

Thank your help. the listview only display.
I will use other way as js should be perfect.

jenson

  • New Member
  • *
  • Posts: 12
Re: Listview how to custom or show subtitle
« Reply #12 on: September 17, 2024, 05:51:18 am »
To: VisualLab

Thank you for your advise.

Program application is my amateur interest, and spend more time want to resign coding. you know that is impossibly. lol.

More people use full-time to focal program details. even more than 20+ year and more. thank you!

When i know most software or app can not get expectancy by application market. I just want build few small tools that can help myself work. as finance, stock trading...maybe more programmer love it.

so, more time, move, move mouse, mouse move, ctrl c, and ctrl v. move...lol
« Last Edit: September 17, 2024, 06:00:51 am by jenson »

VisualLab

  • Sr. Member
  • ****
  • Posts: 445
Re: Listview how to custom or show subtitle
« Reply #13 on: September 17, 2024, 05:48:48 pm »
Program application is my amateur interest, and spend more time want to resign coding.

In all the excitement of the programming discussion (which was more philosophical than practical), the reply written by zeljko (message no. "8") was missed. He proposed the TVirtualStringTree class (VirtualTreeView package, VirtualTreeview Example for Lazarus). It has a lot of possibilities to customize the way data is displayed. Many tutorials on the Internet describe a version intended for Delphi (which should work with Lazarus in most cases). Maybe this class will be sufficient for your needs.

 

TinyPortal © 2005-2018