Recent

Author Topic: DBGRID from program how create onkeypress event  (Read 315 times)

eldonfsr

  • Sr. Member
  • ****
  • Posts: 344
DBGRID from program how create onkeypress event
« on: December 01, 2022, 08:50:48 pm »
Hi friends I try to create a debgrid from programd but i need to create a event onkeypress to search but i need to pass reference to object sender and Var key
how  i can create that here is my code, any help great...

Code: Pascal  [Select][+][-]
  1. Procedure PageClients();
  2. Var PageClients:TCDpageControl;
  3.     TabsCli: TCDTabsheet;
  4. //    DbGCli:TDbGrid;
  5. begin
  6.    PageClients:= TCDPageControl.Create(nil);
  7.    FormMain.PageControl3.visible:=false  ;
  8.    PageClients.Parent := FormMain.Panel2;
  9.    PageClients.Top:= 45;
  10.    PageClients.Width:=656;
  11.    PageClients.Height:=155;
  12.    PageClients.Align:= alClient;
  13.    Pageclients.AddPage('Clients');
  14.    PageClients.DrawStyle:=dsWin2000;
  15.    DbGCli:= TDbGrid.Create(nil);
  16.    DbGCli.Parent := PageClients.GetPage(0);
  17.  //  tabsCli := TCDTabsheet.Create(PageClients);
  18.  //  tabsCli.Caption := 'Clients';
  19. //   tabsCli.PageControl := PageClients;
  20. //   DBgCli.Columns:=13;
  21.    if( DM.SQLQCu.Active = false) then begin
  22.        DM.SQLQCu.open;
  23.    end else begin
  24.        DM.SQLQCu.Refresh;
  25.    end;
  26.    PageClients.visible:=true;
  27.    DBgCli.DataSource := DM.DSCu;
  28.    DBgCli.ReadOnly:=true;
  29.    DBgCli.Visible:=true;
  30.    DBgCli.DefaultDrawing:=true;
  31.    DBgCli.Align:= AlClient;
  32.  
  33.    DBgCli.Columns.Add;
  34.    DBgCli.Columns[0].Title.Caption:='Customer ';
  35.    DBgCli.Columns[0].Width:=240;
  36.    DBgCli.Columns[0].Alignment:=taCenter;
  37.    DBgCli.Columns[0].FieldName:='CuCustomer';
  38.    DBgCli.Columns[0].Visible:=true;
  39.    DBgCli.Columns.Add;
  40.    DBgCli.Columns[1].Title.Caption:='Address ';
  41.    DBgCli.Columns[1].Width:=280;
  42.    DBgCli.Columns[1].FieldName:='CuAddress';
  43.    DBgCli.Columns[1].Visible:=true;
  44.    DBgCli.Columns.Add;
  45.    DBgCli.Columns[2].Title.Caption:='Contact 1 ';
  46.    DBgCli.Columns[2].Width:=120;
  47.    DBgCli.Columns[2].FieldName:='CuContact1';
  48.    DBgCli.Columns[2].Visible:=true;
  49.    DBgCli.Columns.Add;
  50.    DBgCli.Columns[3].Title.Caption:='Email 1 ';
  51.    DBgCli.Columns[3].Width:=120;
  52.    DBgCli.Columns[3].FieldName:='CuEmail1';
  53.    DBgCli.Columns[3].Visible:=true;
  54.    DBgCli.Columns.Add;
  55.    DBgCli.Columns[4].Title.Caption:='Phone 1 ';
  56.    DBgCli.Columns[4].Width:=60;
  57.    DBgCli.Columns[4].FieldName:='CuPhone1';
  58.    DBgCli.Columns[4].Visible:=true;
  59.    DBgCli.Columns.Add;
  60.    DBgCli.Columns[5].Title.Caption:='Contact 2 ';
  61.    DBgCli.Columns[5].Width:=120;
  62.    DBgCli.Columns[5].FieldName:='CuContact2';
  63.    DBgCli.Columns[5].Visible:=true;
  64.    DBgCli.Columns.Add;
  65.    DBgCli.Columns[6].Title.Caption:='Email 2 ';
  66.    DBgCli.Columns[6].Width:=120;
  67.    DBgCli.Columns[6].FieldName:='CuEmail2';
  68.    DBgCli.Columns[6].Visible:=true;
  69.    DBgCli.Columns.Add;
  70.    DBgCli.Columns[7].Title.Caption:='Phone 2 ';
  71.    DBgCli.Columns[7].Width:=50;
  72.    DBgCli.Columns[7].FieldName:='CuPhone2';
  73.    DBgCli.Columns[7].Visible:=true;
  74.    DBgCli.Columns.Add;
  75.    DBgCli.Columns[8].Title.Caption:='Web ';
  76.    DBgCli.Columns[8].Width:=120;
  77.    DBgCli.Columns[8].FieldName:='CuWeb';
  78.    DBgCli.Columns[8].Visible:=true;
  79.    DBgCli.Columns.Add;
  80.    DBgCli.Columns[9].Title.Caption:='Account ';
  81.    DBgCli.Columns[9].Width:=60;
  82.    DBgCli.Columns[9].FieldName:='CuAccount';
  83.    DBgCli.Columns[9].Visible:=true;
  84.    DBgCli.Columns.Add;
  85.    DBgCli.Columns[10].Title.Caption:='Our Code ';
  86.    DBgCli.Columns[10].Width:=60;
  87.    DBgCli.Columns[10].FieldName:='CuCode';
  88.    DBgCli.Columns[10].Visible:=true;
  89.    DBgCli.Columns.Add;
  90.    DBgCli.Columns[11].Title.Caption:='Fed Tax ID ';
  91.    DBgCli.Columns[11].Width:=60;
  92.    DBgCli.Columns[11].FieldName:='CuFedTaxId';
  93.    DBgCli.Columns[11].Visible:=true;
  94.    DBgCli.Columns.Add;
  95.    DBgCli.Columns[12].Title.Caption:='Local Tax ID ';
  96.    DBgCli.Columns[12].Width:=60;
  97.    DBgCli.Columns[12].FieldName:='CuStateTaxId';
  98.    DBgCli.Columns[12].Visible:=true;
  99.    DBgCli.Options:=[dgEditing,dgTitles,dgIndicator,dgColumnResize,dgColumnMove,dgColLines,dgRowLines,dgTabs,dgAlwaysShowSelection,dgConfirmDelete,dgCancelOnExit,dgDisplayMemoText];
  100.    DbGCli.OnKeyPress:=BuscarClient(Sender :Tobject;var Key: char);  // how i can reference what key was push
  101. //   tabsCli.Color:= clblue;
  102. end;
  103. Procedure BuscarClient(Sender:Tobject , var Key: char);
  104. begin
  105.    if( (key >=#40) and (key <=#125)) then begin
  106.     search +=key;
  107.     if( DBgCli.SelectedIndex=0) then begin
  108.       with DBgCli do begin
  109.            DBgCli.DataSource.DataSet.Locate('cucustomer',search,[loCaseInsensitive,LoPartialKey]);
  110.       end;
  111.     end;
  112.     if( DBgCli.SelectedIndex=1) then begin
  113.       with DBgCli do begin
  114.            DBgCli.DataSource.DataSet.Locate('cuaddress',search,[loCaseInsensitive,LoPartialKey]);
  115.       end;
  116.     end;
  117.     if( DBgCli.SelectedIndex=2) then begin
  118.       with DBgCli do begin
  119.            DBgCli.DataSource.DataSet.Locate('cuconact1',search,[loCaseInsensitive,LoPartialKey]);
  120.       end;
  121.     end;
  122.     if( DBgCli.SelectedIndex=3) then begin
  123.       with DBgCli do begin
  124.            DBgCli.DataSource.DataSet.Locate('cuemail1',search,[loCaseInsensitive,LoPartialKey]);
  125.       end;
  126.     end;
  127.     key:=#0;
  128.   end;
  129.   if (key=#27) then  begin
  130.     search :='';
  131.     with DBgCli do begin
  132.       DBgCli.DataSource.DataSet.Locate('cucustomer',search,[loCaseInsensitive,LoPartialKey]);
  133.     end;
  134.  
  135.   end;
  136. end;
  137.  
  138.  
  139.  
  140.  
« Last Edit: December 01, 2022, 10:35:06 pm by eldonfsr »

paweld

  • Hero Member
  • *****
  • Posts: 552
Re: DBGRID from program how create onkerparss event
« Reply #1 on: December 01, 2022, 09:34:49 pm »
Code: Pascal  [Select][+][-]
  1. Procedure PageClients();
  2. var
  3.   // ...
  4. begin
  5.   // ...
  6.   DbGCli.OnKeyPress := @BuscarClient //in mode ObjFPC, or `:= BuscarClient` in mode Delphi
  7. //  tabsCli.Color:= clblue;
  8. end;
  9.  
  10. Procedure BuscarClient(Sender:Tobject , var Key: char);
  11. begin
  12.   // ...
  13. end;
Best regards / Pozdrawiam
paweld

Bart

  • Hero Member
  • *****
  • Posts: 4887
    • Bart en Mariska's Webstek
Re: DBGRID from program how create onkerparss event
« Reply #2 on: December 01, 2022, 09:54:58 pm »
Please fix the Subject line of your first post.
I have no idea what "onkerparss" is  :)

Bart

eldonfsr

  • Sr. Member
  • ****
  • Posts: 344
Re: DBGRID from program how create onkeypress event
« Reply #3 on: December 01, 2022, 10:09:32 pm »
Sorry i Made a mistake ,  Thanks for replay i change as sugest but got a error

uses
  Classes, SysUtils , Forms,Controls, DB, SQldb, DataMod,Fmainp, Dialogs,Graphics, LCLType ,
  ComCtrls,customdrawncontrols,customdrawndrawers,customdrawn_common, DbGrids;


  Procedure  PageClients();
  Procedure  Buscarclient(Sender:TObject ; var Key: char); 

Var
 DbGCli:TDbGrid;
 search:String;


Procedure PageClients();
begin
  DbGCli:= TDbGrid.Create(nil);
   DbGCli.Parent := PageClients.GetPage(0);   
  DbGCli.OnKeyPress:= @BuscarClient ; here send this error you can see at top definition of process
end;


otherpages.pas(121,24) Error: Incompatible types: got "<address of procedure(TObject;var Char);Register>" expected "<procedure variable type of procedure(TObject;var Char) of object;Register>"

Procedure BuscarClient(Sender:Tobject , var Key: char);
begin
   if( (key >=#40) and (key <=#125)) then begin
    search +=key;
end;

i don't know if i need some extrafiles....

Bart

  • Hero Member
  • *****
  • Posts: 4887
    • Bart en Mariska's Webstek
Re: DBGRID from program how create onkeypress event
« Reply #4 on: December 02, 2022, 02:33:22 pm »
Your Buscarclient procedure must be a method of a class. See the definition of TKeyPressEvent:
Code: Pascal  [Select][+][-]
  1. type TKeyPressEvent = procedure(Sender: TObject; var Key: Char) of object;

The "of object" means it is part of a class.

Bart

eldonfsr

  • Sr. Member
  • ****
  • Posts: 344
Re: DBGRID from program how create onkeypress event
« Reply #5 on: December 02, 2022, 04:48:16 pm »
Wow ok let me work on it, I learn litte more let study more and get implement it on my test..

Thanks so much..

 

TinyPortal © 2005-2018