I suspect the following has either a very complex or very stupid
explanation.
Advice please.
In a D1 app I display a grid from a query sequenced by Description. When
the user presses a character key I position in the grid to the first entry with
that letter. The Datasource gets detached and attached because it looks ugly
watching the progress and detached is much faster.
So far so good.
The function works fine for every letter other than the letter 'L'. I have
been through the alphabet on this, all but 'L' is OK. When 'L' is pressed, the
program terminates.
This same problem has been reported on a different (client's) machine also.
The problem occurs with different data as well. Same problem if there is
Description beginning with 'L' or not.
In debug I can trace it as far as the "while" loop - it seems to
spin out at that point.
procedure TViewer.FormKeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
begin
if (Key = VK_RETURN) then
OKBtnClick(Sender);
if (not (chr(Key) < 'A') and (not (chr(Key) > 'Z')))
or (not (chr(Key) < 'a') and (not (chr(Key) > 'z')))
or (not (chr(Key) < '0') and (not (chr(Key) > '9'))) then begin
Screen.Cursor := crHourGlass;
DBGrid1.DataSource := Nil;
with qrydash do begin
if (copy(Fields[2].asstring,1,1) > chr(Key)) then begin
First;
end;
while ((copy(Fields[2].asstring,1,1) < chr(Key)) and (not eof)) do begin
Next;
end;
Shift: TShiftState);
begin
if (Key = VK_RETURN) then
OKBtnClick(Sender);
if (not (chr(Key) < 'A') and (not (chr(Key) > 'Z')))
or (not (chr(Key) < 'a') and (not (chr(Key) > 'z')))
or (not (chr(Key) < '0') and (not (chr(Key) > '9'))) then begin
Screen.Cursor := crHourGlass;
DBGrid1.DataSource := Nil;
with qrydash do begin
if (copy(Fields[2].asstring,1,1) > chr(Key)) then begin
First;
end;
while ((copy(Fields[2].asstring,1,1) < chr(Key)) and (not eof)) do begin
Next;
end;
{ if no entries
for a letter, show previous highest entry }
if (copy(Fields[2].asstring,1,1) <> chr(Key)) and not eof then begin
Prior;
end;
end;
DBGrid1.DataSource := DS;
Screen.Cursor := crDefault;
end;
if (copy(Fields[2].asstring,1,1) <> chr(Key)) and not eof then begin
Prior;
end;
end;
DBGrid1.DataSource := DS;
Screen.Cursor := crDefault;
end;
end;