Recent

Author Topic: [DELETED] Purge keypresses  (Read 935 times)

pcurtis

  • Hero Member
  • *****
  • Posts: 951
[DELETED] Purge keypresses
« on: October 24, 2020, 03:35:44 pm »
Hi All,

Is there a way to clear all cached key pressed from a DB grid.

I've tried OnKeyUp Key := 0 but when I release the UP / DOWN arrow key the grid scroll one or more records further.

Thanks in advance.
« Last Edit: October 27, 2020, 11:05:58 am by pcurtis »
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

jamie

  • Hero Member
  • *****
  • Posts: 6077
Re: Purge keypresses
« Reply #1 on: October 24, 2020, 05:42:32 pm »
try the onKeyDown event, set the KEY := 0
The only true wisdom is knowing you know nothing

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: Purge keypresses
« Reply #2 on: October 24, 2020, 06:11:40 pm »
That just eats all the key presses.

What I am trying to do is navigate the grid, when the key is released the grid stops moving and does not jump backwards or forwards.
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

jamie

  • Hero Member
  • *****
  • Posts: 6077
Re: Purge keypresses
« Reply #3 on: October 24, 2020, 10:27:05 pm »
so you are saying the grid is scrolling past where you want to be.
The only true wisdom is knowing you know nothing

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: Purge keypresses
« Reply #4 on: October 25, 2020, 07:16:47 am »
Yes. It's doing my head in  >:(

Give me a little time and i'll post the logic I am using.
« Last Edit: October 25, 2020, 07:19:40 am by pcurtis »
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: Purge keypresses
« Reply #5 on: October 25, 2020, 07:44:56 am »
So, I am using ZEOSDBO and SQLITE3

Zconnection --> ZQuery --> Datasource --> DBGrid

I have a global variable bKeyDown

Code: Pascal  [Select][+][-]
  1. procedure TForm1.DBGrid1KeyDown(Sender : TObject; var Key : Word;
  2.   Shift : TShiftState);
  3. begin
  4.   bKeyDown := true;
  5. end;
  6.  
  7. procedure TForm1.DBGrid1KeyUp(Sender : TObject; var Key : Word;
  8.   Shift : TShiftState);
  9. begin
  10.   bKeyDown := false;
  11.   Key := 0;
  12.   DataSource1DataChange(nil, nil);
  13. end;
  14.  
  15. procedure TForm1.DataSource1DataChange(Sender: TObject; Field: TField);
  16. var
  17.   iTemp : integer;
  18. begin
  19.   if bKeyDown then exit;
  20.  
  21.   if ZQuery1.RecordCount < 1 then
  22.     begin
  23.       Image1.Picture.Clear;
  24.       exit;
  25.     end;
  26.  
  27.   iTEMP := ZQuery1['fnIDX'];
  28.  
  29.   LoadLogo(iTemp);
  30. end;
  31.  
  32. procedure TForm1.LoadLogo(AIDX : integer);
  33. var
  34.   MyStream : TMemoryStream;
  35.   MyImage : TFreeWinBitmap;
  36.   MyQuery : TZQuery;
  37.   sSQL : string;
  38. begin
  39.  
  40.   sSQL := ' SELECT fnIMAGE FROM tnLOGOS' +
  41.                 ' WHERE fnSTATION_IDX = :Param1';
  42.  
  43.   MyQuery := TZQuery.Create(self);
  44.   MyQuery.Connection := ZConnection1;
  45.   MyQuery.SQL.Clear;
  46.   MyQuery.SQL.Add(sSQL);
  47.   MyQuery.ParamByName('Param1').AsInteger := AIDX;
  48.   MyQuery.Open;
  49.  
  50.   if MyQuery.RecordCount < 1 then
  51.     begin
  52.       MyQuery.Free;
  53.       exit;
  54.     end;
  55.  
  56.   MyImage := TFreeWinBitmap.Create(FIT_BITMAP);
  57.   MyStream := TMemoryStream.Create;
  58.   TBlobField(MyQuery.FieldByName('fnIMAGE')).SaveToStream(MyStream);
  59.   MyStream.Position := 0;
  60.   MyImage.LoadFromStream(MyStream);
  61.   MyStream.Free;
  62.   //MyImage.ConvertToGrayscale;
  63.  
  64.   Image1.Picture.Bitmap.Handle := MyImage.CopyToBitmapH;
  65.   MyImage.Free;
  66.   MyQuery.Free;
  67. end;
  68.  

LoadLogo loads a blob (webp) and displays it in a TImage.

The DBGrid only scrolls away after the call to LoadLogo and I can't figure out why.

The erroneous scrolling only happens occasionally.
« Last Edit: October 25, 2020, 07:53:11 am by pcurtis »
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: Purge keypresses
« Reply #6 on: October 25, 2020, 10:36:13 am »
Basically I'm thinking block all grid movement on KeyUp event, but I don't know how.
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

 

TinyPortal © 2005-2018