Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 9 of 9 total
Thread display button indicators for records.
Tue, May 2 2006 11:49 PMPermanent Link

Aaron Taylor
couldnt think of an appropriate discription but heres what i want to do.

i have 26 buttons a to z

i want to enable / disable the buttons depending on wether there are records starting with the same letter.

i thought of using select distinct then scanning through the result and enabling the buttons.
but this would have to be done every post, delete and edit and may be to recorce hungry.

does anyone have any input?

dbisam 4 delphi 7

thanx
Wed, May 3 2006 2:58 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Aaron


Can you give a bit more (or a lot more) information. My initial reaction was to have an extra table - 26 rows which has a count field showing how many records start with each letter. That's a bit of work keeping up to date but would be faster than continually using sql, but it might not suit your app.

Roy Lambert
Thu, May 4 2006 1:19 AMPermanent Link

Aaron Taylor
the buttons a to z set a filter to only show records starting with that letter.

i just want the buttons enabled if there are records that suit.

Smile


Roy Lambert <roy.lambert@skynet.co.uk> wrote:

Aaron


Can you give a bit more (or a lot more) information. My initial reaction was to have an extra table - 26 rows which has a count field showing how
many records start with each letter. That's a bit of work keeping up to date but would be faster than continually using sql, but it might not suit your
app.

Roy Lambert
Thu, May 4 2006 4:04 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Aaron


All I can suggest is:

1. a separate table, where you increment and decrement records starting with the appropriate letter

2.  have an extra field in the database and store the initial letter in there. Index the field then it will be fast to test for each letter.

3. If the field itself is indexed it might be fast to do a FindNearest

And I'd use a TDBISAMTable rather than a TDBISAMQuery

Otherwise unless someone comes up with a brilliant idea I think you'll just have to take the time penalty.

Roy Lambert
Thu, May 4 2006 7:33 AMPermanent Link

"Robert"

"Roy Lambert" <roy.lambert@skynet.co.uk> wrote in message
news:4C8DF9BF-F779-4B79-9153-154609D899A4@news.elevatesoft.com...

Either this

select distinct substring(FIELD from 1 for 1) as letter from TABLE order by
letter

or this

procedure TForm1.Button1Click(Sender: TObject);
var j : integer;
   c : char;
begin
   memo1.Clear;
   DBISAMTable1.Open;
   for j := 1 to 26 do begin
     c := char(j + 64);
     if DBISAMTable1.Locate('FIELD', c, [loPartialKey])
     then memo1.Lines.Add(c);
  end;
end;

are pretty fast, though the loop using a tTable is much faster.

My table already contains a string field in uppercase that is used to sort
by name.

Robert

Thu, May 4 2006 8:06 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Robert


That's the sort of thing I was thinking of.

Roy Lambert
Thu, May 4 2006 8:21 PMPermanent Link

Aaron Taylor
thanx guys.
Tue, May 9 2006 9:43 PMPermanent Link

Aaron Taylor
"Robert" <ngsemail2005withoutthis@yahoo.com.ar> wrote:


"Roy Lambert" <roy.lambert@skynet.co.uk> wrote in message
news:4C8DF9BF-F779-4B79-9153-154609D899A4@news.elevatesoft.com...

Either this

select distinct substring(FIELD from 1 for 1) as letter from TABLE order by
letter

or this

procedure TForm1.Button1Click(Sender: TObject);
var j : integer;
   c : char;
begin
   memo1.Clear;
   DBISAMTable1.Open;
   for j := 1 to 26 do begin
     c := char(j + 64);
     if DBISAMTable1.Locate('FIELD', c, [loPartialKey])
     then memo1.Lines.Add(c);
  end;
end;

are pretty fast, though the loop using a tTable is much faster.

My table already contains a string field in uppercase that is used to sort
by name.

Robert

Tue, May 9 2006 10:11 PMPermanent Link

Aaron Taylor
For those who want to know how its done heres how.
Thanx to Robert For his code snippet.

Var MyBtn: Array[1..26] of TButton;

MyBtn[1]:=ButtonA;
 .
 .
repeat to z
 .
 .
MyBtn[26]:=ButtonB;

procedure SetButtons;
var j : integer;
    c : char;
begin
With DBISAMTable Do
 begin
  DisableControls;
  for j := 1 to 26 do
   begin
    c := char(j + 64);
    MyBtn[j].Enabled:= Locate('FIELD', c, [loPartialKey]);
  end;
 EnableControls
end;
end;
Image