Re: TZF - Sorting in TTzComboBoxes

Chris Morgan <[email protected]> Mon, 1 Sep 2003 11:47:00 +0100
Newsgroups gmane.comp.lang.delphi.topaz
Message-ID <[email protected]>
Hi Jerry,

TzVFile virtual tables are quite handy to use sometimes,
and can be quicker to use and access than standard
file-based DBF files.

The important thing to remember with them is that the
only inherent ordering in a VFile is the order in which
the records are added.

You can, however, create a new index to reorder the records in
any order which you chose. This index will not be saved to file
as a standard DBF MDX or NDX index though.

There are two ways to order fields.

1. First set the AppendMode property to ASCENDING in the
   object inspector. I think you have to do this before
   you load records into the VFile - I haven't
   investigated it very much.

2. Then use the object inspector to create a KeyMaker event.
   This event will be used to order the records in whatever
   order you decide, so to sort the VFile alphabetically by
   the 3rd field, just add

   Result := TzVFile1.Fields[2].AsString;

   into the empty KeyMaker event handler you have created.
   (I normally use the standard Delphi TDataset methods to get and
   set fields as I use other types of databases as well, but
   you could just as easily use code like

   Result := TzVFile1.GetCField('FIELDNAME');

   in the event handler if you prefer).
   Topaz uses the result of this event handler in a sort
   algorithm - it will call this event for each record in the
   VFile, and the end result is that your VFile will be sorted.

Regarding the TzComboBox - I've not used this component so can't
comment on it, but I would assume that if you use the KeyMaker
event to specify your sort order for the VFile, then you won't
need to explicitly sort the combo box items before displaying them.

I know what you mean about programming being more time-consuming than
you think though, even the simplest tasks seem to have endless
ramifications as soon as you add a 'Cancel' button!

Cheers,


Chris

----- Original Message ----- 
From: "Jerry Mallett" <[email protected]>
To: <[email protected]>
Sent: Sunday, August 31, 2003 3:38 PM
Subject: TZF - Sorting in TTzComboBoxes


HELP........Struggling NEWBIE   AGAIN !!!!!!!!!!!!!
Trying to build his first decent application to help with my
business..

Here's hoping I can explain my problem properly......

I have two Forms.
one which contains a QuickReport ( and thats a whole other story lol )
while the other one is full of data entry fields.

The data entry one is to facilitate in house quotations and contains a
number of
TTzComboBox's.   Each one linked to a specific field in my products
database.

My products need to be sorted when I click the dropdown list icon and
I
tried using the "product.sorted" command but it then requires two
clicks
to
drop the list and when the list drops creates two copies of each
product.

I'm using two events for the TTzComboBoxes... OnChange & OnEnter and
they
look like so.............

procedure TQuoteForm.mboardEnter(Sender: TObject);
// Motherboard selection
Var pd, pc : string;
// pd = Product Description & pc = Product Code
begin
  DataMod.Products.Active := True;

  mboard.sorted := True;
  // Tried to sort dropdown list here with above line and it
  // does sort it but it produces two of everything and I
  // have to click twice to drop the list.

  mboard.Items.Add('No Selection'); //  Add a "No Selection" option
  While NOT DataMod.Products.dEOF Do
  Begin
    If Trim(DataMod.Products.GetCField('PRODGROUP')) = 'PROD_MBRD'
Then
      Begin
       pd := Trim(DataMod.Products.GetCField('PRODDESC'));
       pc :=
LPad(IntToStr(DataMod.Products.GetLongField('ProdCode')),4);
       UnitPrice := DataMod.Products.GetRealField('oneoff');
       mboard.Items.Add(pd+' - ('+pc+') £'+SReal(UnitPrice,6,2));
      End;
   DataMod.Products.skip(1);
  End;
  DataMod.Products.Active := False;
end;

procedure TQuoteForm.mboardChange(Sender: TObject);
Begin

  // here we extract the revelant info like product name, code,
  // net price etc.,

  mboard.sorted := True;

  // Tried to sorth the dropdown list with the above line here but it
  // won't sort

end;

I was trying to use a TzVFile and sort it prior to dropping this list
but I'm finding this impossible to do as well.

I saw Marie Vihonsky's reference to it, (TzVFile), in a recent
posting....
but I'm afraid it went way way over my head as did Chris Morgan's.

Sorry guys.....but I'm a little long in the tooth and the old grey
brain
cells
are fading fast.......I'm 49, 50 come October, and I'm a self taught
computer
technician.  Left school at 15 and had a number of jobs over the
years.
Started
repairing, Building and upgrading PC's in 1985 and own my own repair
shop.
In what little free time I have I try to get to grips with as wide a
range of
software products as I can and have mastered quite a few.
Programming tho is a little more time consumming and if you leave if
for
a few
weeks it's hard to remember where you left of...

Why am I telling you all this??????

So that you'll go easy on me of course...........lmao

Many thanks for the help in advance...

--^----------------------------------------------------------------
This email was sent to: [email protected]

EASY UNSUBSCRIBE click here: http://topica.com/u/?clvXPN.a5kvff.Z2NsZHQt
Or send an email to: [email protected]

TOPICA - Start your own email discussion group. FREE!
http://www.topica.com/partner/tag02/create/index2.html
--^----------------------------------------------------------------