Board index » cppbuilder » Virtual Listview and loading from a DB

Virtual Listview and loading from a DB


2003-08-25 04:47:57 AM
cppbuilder57
What little i learned the other day about the virtual listview
i am trying to to implement today. The examples that i had
seen with a virtual listview all had to do with loading your info
into some sort of list, them passing it to the listview. Is it not
possible to add the items directly to the listview from a db
without using a list and a struct? If i go thought the db and
count the records, then go through the db again, that is doing
the same process twice.
How can i grab the info directly from the db and insert it
directly into the listview?
I have 5 fields that i want to grab from each record of the
db and place it into the listview, but i really don't want to
have to do something like this to get it done.
//--------------------------------------------------------
struct TTestInfo
{
AnsiString Field1;
AnsiString Field2;
AnsiString Field3;
AnsiString Field4;
AnsiString Field5;
};
TList* aList;
//--------------------------------------------------------
aList = new TList;
//--------------------------------------------------------
int TableCount = 0;
while(!Table1->Eof)
{
TTestInfo* ti = new TTestInfo;
ti->Field1 = Table1->FieldByName("Field1")->AsString;
ti->Field2 = Table1->FieldByName("Field2")->AsString;
ti->Field3 = Table1->FieldByName("Field3")->AsString;
ti->Field4 = Table1->FieldByName("Field4")->AsString;
ti->Field5 = Table1->FieldByName("Field5")->AsString;
++TableCount;
aList->Add(ti);
}
ListView1->Items->Count = TableCount;
//--------------------------------------------------------
void __fastcall TForm1::ListView1Data(TObject *Sender, TListItem
*Item)
{
TTestInfo* ti = (TTestInfo*)aList->Items[Item->Index];
// Set the Caption and ImageIndex properties.
Item->Caption = ti->Field1;
Item->SubItems->Add(ti->Field2);
Item->SubItems->Add(ti->Field3);
Item->SubItems->Add(ti->Field4);
Item->SubItems->Add(ti->Field5);
}
//--------------------------------------------------------
Can someone elaborate on this topic so i can understand it a bit more,
these records are in the thousands and i would like effiency when
loading
them.
Thanks.
 
 

Re:Virtual Listview and loading from a DB

Quote
However, given the example you have shown, using a list to contain
all of
the DB items, or at least a large amount of them at a time, is best.
Why do
you not want to go that approach?
I was thinking that it was going to utilize way too much memory having
to store
all the info into a TList. I tried it and its pretty fast compared to
what i was using
before, but what about the memory consumption?
Appreciate the help.
 

Re:Virtual Listview and loading from a DB

"Greg Stantin" < XXXX@XXXXX.COM >wrote in message
Quote
I was thinking that it was going to utilize way too much
memory having to store all the info into a TList.
You don't have to store EVERYTHING at one time. That is why the OnDataHint
event exists. It warns you ahead of time which items the ListView is likely
to need soon so that you can pre-cache just those items appropriately for
OnData to use later. Of course, you need to make sure that OnData is also
capable of retreiving item data that has not been cached yet, just in case.
Gambit
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (www.grisoft.com).
Version: 6.0.512 / Virus Database: 309 - Release Date: 8/19/03
 

{smallsort}