Forum > Packages and Libraries

DBGRID from program how create onkeypress event

(1/2) > >>

eldonfsr:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Procedure PageClients();Var PageClients:TCDpageControl;    TabsCli: TCDTabsheet;//    DbGCli:TDbGrid;begin   PageClients:= TCDPageControl.Create(nil);   FormMain.PageControl3.visible:=false  ;   PageClients.Parent := FormMain.Panel2;   PageClients.Top:= 45;   PageClients.Width:=656;   PageClients.Height:=155;   PageClients.Align:= alClient;   Pageclients.AddPage('Clients');   PageClients.DrawStyle:=dsWin2000;   DbGCli:= TDbGrid.Create(nil);   DbGCli.Parent := PageClients.GetPage(0); //  tabsCli := TCDTabsheet.Create(PageClients); //  tabsCli.Caption := 'Clients';//   tabsCli.PageControl := PageClients;//   DBgCli.Columns:=13;   if( DM.SQLQCu.Active = false) then begin       DM.SQLQCu.open;   end else begin       DM.SQLQCu.Refresh;   end;   PageClients.visible:=true;   DBgCli.DataSource := DM.DSCu;   DBgCli.ReadOnly:=true;   DBgCli.Visible:=true;   DBgCli.DefaultDrawing:=true;   DBgCli.Align:= AlClient;    DBgCli.Columns.Add;   DBgCli.Columns[0].Title.Caption:='Customer ';   DBgCli.Columns[0].Width:=240;   DBgCli.Columns[0].Alignment:=taCenter;   DBgCli.Columns[0].FieldName:='CuCustomer';   DBgCli.Columns[0].Visible:=true;   DBgCli.Columns.Add;   DBgCli.Columns[1].Title.Caption:='Address ';   DBgCli.Columns[1].Width:=280;   DBgCli.Columns[1].FieldName:='CuAddress';   DBgCli.Columns[1].Visible:=true;   DBgCli.Columns.Add;   DBgCli.Columns[2].Title.Caption:='Contact 1 ';   DBgCli.Columns[2].Width:=120;   DBgCli.Columns[2].FieldName:='CuContact1';   DBgCli.Columns[2].Visible:=true;   DBgCli.Columns.Add;   DBgCli.Columns[3].Title.Caption:='Email 1 ';   DBgCli.Columns[3].Width:=120;   DBgCli.Columns[3].FieldName:='CuEmail1';   DBgCli.Columns[3].Visible:=true;   DBgCli.Columns.Add;   DBgCli.Columns[4].Title.Caption:='Phone 1 ';   DBgCli.Columns[4].Width:=60;   DBgCli.Columns[4].FieldName:='CuPhone1';   DBgCli.Columns[4].Visible:=true;   DBgCli.Columns.Add;   DBgCli.Columns[5].Title.Caption:='Contact 2 ';   DBgCli.Columns[5].Width:=120;   DBgCli.Columns[5].FieldName:='CuContact2';   DBgCli.Columns[5].Visible:=true;   DBgCli.Columns.Add;   DBgCli.Columns[6].Title.Caption:='Email 2 ';   DBgCli.Columns[6].Width:=120;   DBgCli.Columns[6].FieldName:='CuEmail2';   DBgCli.Columns[6].Visible:=true;   DBgCli.Columns.Add;   DBgCli.Columns[7].Title.Caption:='Phone 2 ';   DBgCli.Columns[7].Width:=50;   DBgCli.Columns[7].FieldName:='CuPhone2';   DBgCli.Columns[7].Visible:=true;   DBgCli.Columns.Add;   DBgCli.Columns[8].Title.Caption:='Web ';   DBgCli.Columns[8].Width:=120;   DBgCli.Columns[8].FieldName:='CuWeb';   DBgCli.Columns[8].Visible:=true;   DBgCli.Columns.Add;   DBgCli.Columns[9].Title.Caption:='Account ';   DBgCli.Columns[9].Width:=60;   DBgCli.Columns[9].FieldName:='CuAccount';   DBgCli.Columns[9].Visible:=true;   DBgCli.Columns.Add;   DBgCli.Columns[10].Title.Caption:='Our Code ';   DBgCli.Columns[10].Width:=60;   DBgCli.Columns[10].FieldName:='CuCode';   DBgCli.Columns[10].Visible:=true;   DBgCli.Columns.Add;   DBgCli.Columns[11].Title.Caption:='Fed Tax ID ';   DBgCli.Columns[11].Width:=60;   DBgCli.Columns[11].FieldName:='CuFedTaxId';   DBgCli.Columns[11].Visible:=true;   DBgCli.Columns.Add;   DBgCli.Columns[12].Title.Caption:='Local Tax ID ';   DBgCli.Columns[12].Width:=60;   DBgCli.Columns[12].FieldName:='CuStateTaxId';   DBgCli.Columns[12].Visible:=true;   DBgCli.Options:=[dgEditing,dgTitles,dgIndicator,dgColumnResize,dgColumnMove,dgColLines,dgRowLines,dgTabs,dgAlwaysShowSelection,dgConfirmDelete,dgCancelOnExit,dgDisplayMemoText];   DbGCli.OnKeyPress:=BuscarClient(Sender :Tobject;var Key: char);  // how i can reference what key was push//   tabsCli.Color:= clblue;end;Procedure BuscarClient(Sender:Tobject , var Key: char);begin   if( (key >=#40) and (key <=#125)) then begin    search +=key;    if( DBgCli.SelectedIndex=0) then begin      with DBgCli do begin           DBgCli.DataSource.DataSet.Locate('cucustomer',search,[loCaseInsensitive,LoPartialKey]);      end;    end;    if( DBgCli.SelectedIndex=1) then begin      with DBgCli do begin           DBgCli.DataSource.DataSet.Locate('cuaddress',search,[loCaseInsensitive,LoPartialKey]);      end;    end;    if( DBgCli.SelectedIndex=2) then begin      with DBgCli do begin           DBgCli.DataSource.DataSet.Locate('cuconact1',search,[loCaseInsensitive,LoPartialKey]);      end;    end;    if( DBgCli.SelectedIndex=3) then begin      with DBgCli do begin           DBgCli.DataSource.DataSet.Locate('cuemail1',search,[loCaseInsensitive,LoPartialKey]);      end;    end;    key:=#0;  end;  if (key=#27) then  begin    search :='';    with DBgCli do begin      DBgCli.DataSource.DataSet.Locate('cucustomer',search,[loCaseInsensitive,LoPartialKey]);    end;   end;end;    

paweld:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Procedure PageClients(); var   // ... begin   // ...   DbGCli.OnKeyPress := @BuscarClient //in mode ObjFPC, or `:= BuscarClient` in mode Delphi //  tabsCli.Color:= clblue; end;   Procedure BuscarClient(Sender:Tobject , var Key: char); begin   // ... end;

Bart:
Please fix the Subject line of your first post.
I have no idea what "onkerparss" is  :)

Bart

eldonfsr:
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:
Your Buscarclient procedure must be a method of a class. See the definition of TKeyPressEvent:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type TKeyPressEvent = procedure(Sender: TObject; var Key: Char) of object;
The "of object" means it is part of a class.

Bart

Navigation

[0] Message Index

[#] Next page

Go to full version