Delphi + Listbox--Question

Started by Chris, 24 May '03 - 22:21

Chris

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

DanaPaul

LockWindowUpdate(Listbox1.Handle);
Try
  Listbox1.Items.loadFromFile('File.txt')
Finally
  LockWindowUpdate(0);
  end;

fredvs

#2
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;


Chris

#3
@ 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

DanaPaul

#4
QuoteFor 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 :)

fredvs

Hi Chris

QuoteI 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


Quoteyou 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

Hi Chris

QuoteNow 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


QuoteAre 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

QuoteComma 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

#10
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

DanaPaul


QuoteBut 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


QuoteWith 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

#13
QuoteWell, 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)

-----------------------------------------------------------
 
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)
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
    

DanaPaul


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

TListBox.Items.Assign(TStrings);

QuoteL.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]);

QuoteThe 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;

Quoteif 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

#15
@ 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

fredvs

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


Quick Reply

Warning: this topic has not been posted in for at least 365 days.
Unless you're sure you want to reply, please consider starting a new topic.

Name:
Email:
Verification:
Please leave this box empty:
Type the letters shown in the picture
Listen to the letters / Request another image

Type the letters shown in the picture:
Shortcuts: ALT+S post or ALT+P preview