Author Topic: Delphi + Listbox--Question  (Read 12834 times)

Chris

  • Posts: 2210
Delphi + Listbox--Question
« on: 24 May '03 - 22:21 »
Please don't smash with stones to me , but one (NOBASS) Question..
I have the following Problem...
I load my Playlist(LiSTBOX)
Listbox1.Items.loadFromFile(progdir+'playlist1.txt')

But that are ca 10.000 Items)...
and it will persist ca 7-8 seconds til the Items will  be shown....
What do you think how can I speed up the the Items will shown faster...????
Many Thanks
Greets Chris
« Last Edit: 25 May '03 - 01:08 by Chris »

DanaPaul

  • Posts: 335
Re: Listbox--Question...+Delphi
« Reply #1 on: 25 May '03 - 00:04 »
LockWindowUpdate(Listbox1.Handle);
Try
 Listbox1.Items.loadFromFile('File.txt')
Finally
 LockWindowUpdate(0);
 end;

fredvs

  • Posts: 325
Re: Listbox--Question...+Delphi
« Reply #2 on: 25 May '03 - 00:09 »
Hi Chris.

Difficult...

I have the same problem, i have try lots of listbox, memo, etc.. to find the one who show the fastest.

For me it is the stringgrid is the fastest.

And you can also show record by record while filling.

 while not eof(list) do
   begin
     x := x + 1 ;
     Readln(list, data);
     stringgrid.Cells[0,x] := trim(data) ;
     //stringgrid.refresh // show record by record while filling.
       end;

« Last Edit: 25 May '03 - 00:17 by fredvs »

Chris

  • Posts: 2210
Re: Listbox--Question...+Delphi
« Reply #3 on: 25 May '03 - 00:53 »
@ DanaPaul....a litle bit faster  
without your code...8 Seconds   with your code ca 5 seconds


@ Fred.....

StringGrid faster as a Listbox ??? I don`t think so..
but look...
I think my Items are much longer than yours...
Example

In every Item of my Playlist are

FileName,ItemsCount,Tag-Interpret,Tag-Titel,Audiolength1(TimeFormat) AudioLength2(IntegerFormat)
BPM,FileTyp,Startposition,Endposition  and 20 CuePoints...

(i'm using a LMDListbox with Columns)same fast as a normaly Listbox

greets
Chris
« Last Edit: 25 May '03 - 00:54 by Chris »

DanaPaul

  • Posts: 335
Re: Listbox--Question...+Delphi
« Reply #4 on: 25 May '03 - 01:58 »
Quote

For me it is the stringgrid is the fastest.


Ditto.  However, I use TStrings.Assign for each row and/or column.

Artist    - Album    - Title
Strings[0]-Strings[1]-Strings[2]

TStrings(Rows
  • ).Assign(Strings)

    Using LockWindowUpdate and Assign with StringGrid blows the competition away :)
« Last Edit: 25 May '03 - 01:59 by DanaPaul »

fredvs

  • Posts: 325
Re: Delphi + Listbox--Question
« Reply #5 on: 25 May '03 - 05:21 »
Hi Chris

Quote
I think my Items are much longer than yours...


::) Not shure because you see only 3 col but in fact they are 10 colomns (7 are hidden) : full path ,file name,time,bpm,title,artist,album,year,genre,comment)...

DanaPaul

  • Posts: 335
Re: Delphi + Listbox--Question
« Reply #6 on: 25 May '03 - 09:13 »

Quote

you see only 3 col but in fact they are 10 colomns (7 are hidden) : full path ,file name, time, bpm, title, artist, album, year, genre, comment)...


Now all you need is a database that has a TString data type and your app is golden.

Longer is better :)

fredvs

  • Posts: 325
Re: Delphi + Listbox--Question
« Reply #7 on: 25 May '03 - 14:29 »
Hi Chris

Quote
Now all you need is a database


Are you toking about dbe ?
In my opinion, i dont want to use an external database (like dbe, sql, etc..).
I do the database with a text file with coma delimited and my codes for seeking, storing, etc.

But im very interested about your feeling, what do you meen with "Now all you need is a database".

DanaPaul

  • Posts: 335
Re: Delphi + Listbox--Question
« Reply #8 on: 25 May '03 - 19:16 »

Quote

Are you toking about dbe ?  But im very interested about your feeling, what do you meen with "Now all you need is a database".


Question 1 = Yes, or other database alternatives. Question 2 = speed.  Comma delimited is s-l-o-w :)

fredvs

  • Posts: 325
Re: Delphi + Listbox--Question
« Reply #9 on: 25 May '03 - 21:14 »
Quote
Comma delimited is s-l-o-w


Yes and without license, without dll or install, easy to edit and dont eat any kb.

But i agree, it is slower (not very much slower).

Chris

  • Posts: 2210
Re: Delphi + Listbox--Question
« Reply #10 on: 25 May '03 - 22:13 »
MM  Database + StringGrid fast thats true...BUT......

With a StringGrid you have no chance  about OwnerDraw..or..??

Example in a good AudioPlaylist you will need 2 different
Font-Colours.. Examble one Colour for the active Playling song one Colour for ItemIndex...
Have look on my HomePage and you will seen what I mean
http://www.cst-tech.de

And so long as I know is`t that possible with a StringGrid...
Greets Chris
« Last Edit: 25 May '03 - 22:14 by Chris »

DanaPaul

  • Posts: 335
Re: Delphi + Listbox--Question
« Reply #11 on: 25 May '03 - 22:27 »

Quote

But i agree, it is slower (not very much slower).


Well, not to labor a point, but I will present my case...

Delphi "string" is a 4 byte pointer, a known quantity (4 bytes) residing in memory, or residing in a (String) list.  On the other hand, comma delimited text is an unknown quantity that must be parsed from char[1] to (last) Char
  • , for each and every row, or each and every column.

    This is the rational behind "TStrings.Assign", which is (much) quicker than parsing comma delimited text. The compiler can iterate 4 byte pointers represent each cell in a complete row or column in a StringGrid. Conveniently, these Rows and Columns are predefined as TStrings types by Delphi.

    Granted, a database is somewhat cumbersome depending on the nature of any given application, but its added value for speed cannot be easily brushed aside. Delphi packaged a working database with its product.  Nevertheless, a flat file can save multiple TString objects using Delphi's Reader and Writer classes :)

DanaPaul

  • Posts: 335
Re: Delphi + Listbox--Question
« Reply #12 on: 25 May '03 - 22:49 »

Quote

With a StringGrid you have no chance  about OwnerDraw..or..??


For owner draw you would use a DrawGrid, the base class for StringGrid.

If you cruise the major Delphi sites you will find many (freebie) Delphi components.  Some of these components paint a unique color for each grid cell.  I've collected some very nice objects floating around these sites.  Coincidently, that's how I stumbled across BASS.

I've been using a suite of very well designed VCL components from a couple of Russians for many years, their help files and resource files are in many languages :)

http://www.developpez.com/delphi/freewares/RxLib/


Chris

  • Posts: 2210
Re: Delphi + Listbox--Question
« Reply #13 on: 26 May '03 - 00:41 »
Quote
Well, not to labor a point, but I will present my case...

Delphi "string" is a 4 byte pointer, a known quantity (4 bytes) residing in memory, or residing in a (String) list.  On the other hand, comma delimited text is an unknown quantity that must be parsed from char[1] to (last) Char[x], for each and every row, or each and every column.

This is the rational behind "TStrings.Assign", which is (much) quicker than parsing comma delimited text. The compiler can iterate 4 byte pointers represent each cell in a complete row or column in a StringGrid. Conveniently, these Rows and Columns are predefined as TStrings types by Delphi.

Granted, a database is somewhat cumbersome depending on the nature of any given application, but its added value for speed cannot be easily brushed aside. Delphi packaged a working database with its product.  Nevertheless, a flat file can save multiple TString objects using Delphi's Reader and Writer classes

@ DanaPaul very interesting..

Is it from the Theory possible to make it with a Listbox too ??
because..I the normal load procedure is fast by me....
the only problem is whenn the ItemtxtFile ist to large..
here my normaly Load-Procedure...
(as Listbox I`m using the LMDListbox)

-----------------------------------------------------------
Code: [Select]
 
procedure LoadAudioFiles        (o:Tstrings;L:TLMDListBox);
var
i         :Integer;
TempFile          :TCSTAudioFileReader;
BPM: string;
begin
TempFile := TCSTAudioFileReader.Create(nil);
for I :=0 to o.Count -1 do begin
If ((FileExists(o[i]))and (TempFile.CheckValueFileTyp(o[i])= true))then begin
TempFile.FileName := o[i];
BPM := '120,00';
If o.Count > 20 then begin
L.Items.BeginUpdate;
L.Items.Add ((TempFile.FileName)+';'+inttostr(l.Count+1)+';'+AnsiUppercase(TempFile.Artist)+';'+AnsiUppercase(TempFile.Title)+';'+TempFile.DurationTime+'  '+';'+BPM+';'+(inttostr(TempFile.DurationInt))+';'+TempFile.Typ);
L.Items.EndUpdate;
end
else
L.Items.Add ((TempFile.FileName)+';'+inttostr(l.Count+1)+';'+AnsiUppercase(TempFile.Artist)+';'+AnsiUppercase(TempFile.Title)+';'+TempFile.DurationTime+'  '+';'+BPM+';'+(inttostr(TempFile.DurationInt))+';'+TempFile.Typ);
end;
end;
TempFile.Free;
end;


This will work very well...without problems...

The only Problem what I have is....
when I try this...(and i have to much Items > 5000)
Code: [Select]

LockWindowUpdate(PlayList1.Handle);
PlayList1.items.loadfromfile(progdir+playlist1.txt);
LockWindowUpdate(0);


Mabe  i must generate a new Load procdue the will be work faster.....
Greets
Chris
Ps
Thanks for all you help...you are a refinement for this board....

---------------------------------------------------------

@ Fred.....
I see that your Search-Procedure is very slow...
if you want i can send you the code of a faster Search-Procedure
On my Athlon 1800
for 11.000 Songs ca 4 minutes....
Chris
   
« Last Edit: 26 May '03 - 05:47 by Chris »

DanaPaul

  • Posts: 335
Re: Delphi + Listbox--Question
« Reply #14 on: 26 May '03 - 03:10 »

Quote

Is it from the Theory possible to make it with a Listbox too ??


TListBox.Items.Assign(TStrings);

Quote

L.Items.Add ((TempFile.FileName)+';'+inttostr(l.Count+1)+';'+AnsiUppercase(TempFile.Artist)+';'+AnsiUppercase(TempFile.Title)+';'+TempFile.DurationTime+'  '+';'+BPM+';'+(inttostr(TempFile.DurationInt))+';'+TempFile.Typ);


Well, you could clean it up using Format...

L.Items.Add(Format('%s;%d;%s;%s;%s ;BPM;%d;%s', [TempFile.FileName, l.Count+1, AnsiUppercase(TempFile.Artist), AnsiUppercase(TempFile.Title), TempFile.DurationTime, BPM, TempFile.DurationInt, TempFile.Typ]);

Quote

The only Problem what I have is....
when I try this...(and i have to much Items > 5000)


Never use LockWindowUpdate without a Try... Finally block, your window may, err, "lock up" :) ...

LockWindowUpdate(PlayList1.Handle);
Try
 PlayList1.items.loadfromfile('File.txt');
Finally
 LockWindowUpdate(0);
end;

Quote

if you want i can send you the code of a faster Search-Procedure On my Athlon 1800 for 11.000 Songs ca 1 minute....


I would like a copy of that code :)

Chris

  • Posts: 2210
Re: Delphi + Listbox--Question
« Reply #15 on: 26 May '03 - 04:24 »
@ DanaPaul you have post....
in my Last Post was an Error..not 1 Minute i will mean 4 Minutes...
About the error what I told you in my email email I have found..

Chris
« Last Edit: 26 May '03 - 05:48 by Chris »

fredvs

  • Posts: 325
Re: Delphi + Listbox--Question
« Reply #16 on: 26 May '03 - 06:01 »
Hi Chris

Quote
@ Fred.....
I see that your Search-Procedure is very slow...
if you want i can send you the code of a faster Search-Procedure
On my Athlon 1800
for 11.000 Songs ca 4 minutes....
Chris


...With pleasure... :)

Chris

  • Posts: 2210
Re: Delphi + Listbox--Question
« Reply #17 on: 26 May '03 - 06:24 »
@ Fred you have post..
Chris