Jump to content
#ifdef

TControlList — need help!

Recommended Posts

I started to display your test just in a THTML viewer.

Nice, because you can continue to format the text with whatever you want (colors, fonts, etc)

The wordwrap is very fast. Maybe you can even add an onClick in code to capture a click on one of the <div>

 

procedure TForm1.BitBtn1Click(Sender: TObject);
var
  idx: Integer;
begin
  for idx := 1 to 10 do
  Begin
    HtmlViewer1.Text:=HtmlViewer1.Text+'<div>'+IntToStr(idx)+': '+setCaption+'</div><br>';
  End;
end;

 

image.thumb.png.25902d61d5a5628a4bc46c2813286f01.png

 

 

HtmlViewer 10.2 is still available at: http://code.google.com/p/thtmlviewer/
HtmlViewer 11.x is available at: https://sourceforge.net/projects/htmlviewer/
HtmlViewer development is hosted at: https://github.com/BerndGabriel/HtmlViewer

  • Like 1

Share this post


Link to post
23 hours ago, Die Holländer said:

I started to display your test just in a THTML viewer.

Nice, because you can continue to format the text with whatever you want (colors, fonts, etc)

The wordwrap is very fast. Maybe you can even add an onClick in code to capture a click on one of the <div>

 


procedure TForm1.BitBtn1Click(Sender: TObject);
var
  idx: Integer;
begin
  for idx := 1 to 10 do
  Begin
    HtmlViewer1.Text:=HtmlViewer1.Text+'<div>'+IntToStr(idx)+': '+setCaption+'</div><br>';
  End;
end;

 

image.thumb.png.25902d61d5a5628a4bc46c2813286f01.png

 

 

HtmlViewer 10.2 is still available at: http://code.google.com/p/thtmlviewer/
HtmlViewer 11.x is available at: https://sourceforge.net/projects/htmlviewer/
HtmlViewer development is hosted at: https://github.com/BerndGabriel/HtmlViewer

It looks really good, but on older computers 1000+ lines are too slow to render when resizing the canvas — and I can’t use pagination because the entire list must be available. But thanks anyway!

Share this post


Link to post
17 minutes ago, #ifdef said:

It looks really good, but on older computers 1000+ lines are too slow to render when resizing the canvas — and I can’t use pagination because the entire list must be available. But thanks anyway!

Are you sure? Did you tried it? 

The speed is in no way comparible with your TControlList example.

The HTML renderer is very fast, also on older computers.

Otherwise displaying a webpage on these computers is also not possible..

Share this post


Link to post
Posted (edited)

Yes, I'm sure :classic_smile:

 

THtmlViewer + 10000 (start is ~5 seconds, resize is slow):

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, System.Math,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, HTMLUn2, HtmlView;

type
  TForm1 = class(TForm)
    HtmlViewer1: THtmlViewer;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function setCaption: string;
var
  Lt: string;
  Li, Ll: integer;
begin
  Ll := RandomRange(10, 1000);

  Lt := '';

  for Li := 1 to Ll do
    begin
      if (Random(10) = 0) and (Li < Ll) then
        begin
          Lt := Lt + ' ';
        end
      else
        begin
          if Random(2) = 0 then Lt := Lt + Chr(RandomRange(65, 90)) else Lt := Lt + Chr(RandomRange(97, 122));
        end;
    end;

  Result := Lt;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  Li: integer;
  Ls: string;
begin
  for Li := 1 to 10000 do Ls := Ls + '<div>' + Li.ToString + ': ' + setCaption + '</div><br>';

  HtmlViewer1.Text := Ls;
end;

end.

 

 

 

TControlList + 10000 (start is ~1 second, resize is ok):

 

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, System.Math,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ControlList;

type
  TForm1 = class(TForm)
    ControlList1: TControlList;
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure ControlList1BeforeDrawItem(AIndex: Integer; ACanvas: TCanvas; ARect: TRect; AState: TOwnerDrawState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  FList: TStringList;

implementation

{$R *.dfm}

function setCaption: string;
var
  Lt: string;
  Li, Ll: integer;
begin
  Ll := RandomRange(10, 1000);

  Lt := '';

  for Li := 1 to Ll do
    begin
      if (Random(10) = 0) and (Li < Ll) then
        begin
          Lt := Lt + ' ';
        end
      else
        begin
          if Random(2) = 0 then Lt := Lt + Chr(RandomRange(65, 90)) else Lt := Lt + Chr(RandomRange(97, 122));
        end;
    end;

  Result := Lt;
end;

procedure TForm1.ControlList1BeforeDrawItem(AIndex: Integer; ACanvas: TCanvas; ARect: TRect; AState: TOwnerDrawState);
begin
  Label1.Caption := FList[AIndex];
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  FList := TStringList.Create;

  ControlList1.ItemCount := 10000;

  for var Li := 0 to ControlList1.ItemCount - 1 do FList.Add(Li.ToString + ': ' + setCaption);
end;

end.
Edited by #ifdef

Share this post


Link to post
18 minutes ago, #ifdef said:

ControlList + 10000 (start is ~1 second, resize is ok):

Yes, but its only resizing/displaying a small part of the text height, while the HTML is showing the entire text..

I wonder what your user case is. Who is going to read that much text at once when you can't use pagination, etc..

 

Share this post


Link to post
2 hours ago, Die Holländer said:

Yes, but its only resizing/displaying a small part of the text height, while the HTML is showing the entire text..

I wonder what your user case is. Who is going to read that much text at once when you can't use pagination, etc..

 

That's why I chose the TControlList — it allows to instantly move to any place, all that remains is to fix the fixed row height 🙂

Share this post


Link to post

@#ifdef Well , while i hate my life nowadays, and while just waiting for the blackout to brighten my day after only 3 hours of power, i tried to build you something 

Animation5.thumb.gif.e9cfd2e579dd06483ac96f97f8af42cd.gif

 

Far from finished or polished, take it as example or prototype for what you can do with custom drawing, notice it is 10000 strings !

ListBoxAsStringList.zip

 

My suggestion is to use VirtualTreeView, i couldn't find working copy of VTV on my PC now, and don't want to waste time downloading my encrypted archives from the cloud, so i used TListBox, it is simple easy and pretty straight forward.

Notes:

1) i didn't use FillRec on the whole Listbox, while it is more efficient and faster to clear the background for all the items in one go, this will introduce an ugly flicker in the bottom half, do the system rendering which doesn't wait for anyone, by clearing the background for each item in time, we prevent this flicker, but will introduce small performance hit in overall drawing.

2) i disabled the selected item highlighting, because it does need little different approach, yet it is easy, just adjust the canvas brush color before the FillRect, this will be up to you to implement, as i said i don't have time and don't have the skins on the latest IDE versions to test and play with.

3) customize as you wish, like ... can you this ? ( there is no noticeable performance change)

image.thumb.png.e5b0f7155da9b1eb32632aa8ad73ed20.png

 

Hope that helps, also never underestimate Windows custom drawing, it is fucking blazing fast when done right.

  • Like 3

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×