使用滑鼠滾輪轉動後將資料帶至Edit1.text問題 |
答題得分者是:mephise
|
kevinsoung
一般會員 發表:36 回覆:41 積分:15 註冊:2011-11-09 發送簡訊給我 |
各位前輩 我有一個Tfrom1在窗內有一個TDBGrid顯示出資料 我用下方式上滑鼠滾輪可以滾動TDBGrid上的資料 我要如何將滑鼠滾輪經過的地方將TDBGrid的第一個欄位的資料放入Edit1.text內 請各位前輩幫幫忙 萬般感激不盡
[code delphi] unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, DB, DBTables, Grids, DBGrids, SMDBGrid; type TDBGrid=class(DBGrids.TDBGrid) public function DoMouseWheel(Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint): Boolean; override; end; type TForm1 = class(TForm) DBGrid1: TDBGrid; DataSource1: TDataSource; Table1: TTable; Edit1: TEdit; private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} function TDBGrid.DoMouseWheel(Shift: TShiftState; WheelDelta: Integer;MousePos: TPoint): Boolean; begin if WheelDelta < 0 then datasource.DataSet.Next; if wheelDelta > 0 then DataSource.DataSet.Prior; end; end. [/code]編輯記錄
kevinsoung 重新編輯於 2012-02-14 01:37:22, 註解 無‧
|
t27
中階會員 發表:34 回覆:95 積分:90 註冊:2002-06-19 發送簡訊給我 |
procedure TFrmBS00A3.DBGridMouseWheelDown(Sender: TObject; Shift: TShiftState;
MousePos: TPoint; var Handled: Boolean); begin inherited; if MasterSrc.DataSet <> nil then begin if (Sender is TDBGrid) then begin with TDBGrid(Sender).DataSource.DataSet do begin if not EOF then Next; end; Handled := True; //GetDataFromDBF(TDBGrid(Sender).DataSource,self); //DispData; edit1.text := TDBGrid(Sender)....... end; end; end;
procedure TFrmBS00A3.DBGridMouseWheelUp(Sender: TObject; Shift: TShiftState; MousePos: TPoint; var Handled: Boolean); begin inherited; if MasterSrc.DataSet <> nil then begin if (Sender is TDBGrid) then begin with TDBGrid(Sender).DataSource.DataSet do begin if not BOF then Prior; end; Handled := True; //GetDataFromDBF(TDBGrid(Sender).DataSource,self); //DispData; edit1.text := ........ end; end; end;
編輯記錄
t27 重新編輯於 2012-02-14 07:21:03, 註解 無‧
|
kevinsoung
一般會員 發表:36 回覆:41 積分:15 註冊:2011-11-09 發送簡訊給我 |
感謝前輩的回覆
我將您提供的放入後如下 unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, DB, DBTables, Grids, DBGrids, SMDBGrid, StdCtrls; type TDBGrid=class(DBGrids.TDBGrid) public function DoMouseWheel(Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint): Boolean; override; end; type TForm1 = class(TForm) DBGrid1: TDBGrid; DataSource1: TDataSource; Table1: TTable; Edit1: TEdit; Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} function TDBGrid.DoMouseWheel(Shift: TShiftState; WheelDelta: Integer;MousePos: TPoint): Boolean; begin if WheelDelta < 0 then Begin datasource.DataSet.Next; End; if wheelDelta > 0 then DataSource.DataSet.Prior; end; procedure TForm1.DBGridMouseWheelDown(Sender: TObject; Shift: TShiftState; MousePos: TPoint; var Handled: Boolean); begin inherited; if MasterSrc.DataSet <> nil then begin if (Sender is TDBGrid) then begin with TDBGrid(Sender).DataSource.DataSet do begin if not EOF then Next; end; Handled := True; //GetDataFromDBF(TDBGrid(Sender).DataSource,self); //DispData; edit1.text := TDBGrid(Sender)....... end; end; end; procedure TForm1.DBGridMouseWheelUp(Sender: TObject; Shift: TShiftState; MousePos: TPoint; var Handled: Boolean); begin inherited; if MasterSrc.DataSet <> nil then begin if (Sender is TDBGrid) then begin with TDBGrid(Sender).DataSource.DataSet do begin if not BOF then Prior; end; Handled := True; //GetDataFromDBF(TDBGrid(Sender).DataSource,self); //DispData; edit1.text := ........ end; end; end; end.
但是不行無法執行 Build 出現以下訊息 [Warning] Unit1.pas(45): Return value of function 'TDBGrid.DoMouseWheel' might be undefined [Error] Unit1.pas(47): Undeclared identifier: 'DBGridMouseWheelDown' [Error] Unit1.pas(47): ';' expected but '(' found [Error] Unit1.pas(48): ';' expected but ')' found [Error] Unit1.pas(50): This form of method call only allowed in methods of derived types [Error] Unit1.pas(52): Undeclared identifier: 'MasterSrc' [Error] Unit1.pas(54): Undeclared identifier: 'Sender' [Error] Unit1.pas(54): Operator not applicable to this operand type [Error] Unit1.pas(64): Undeclared identifier: 'edit1' [Error] Unit1.pas(64): '(' expected but ':=' found [Error] Unit1.pas(64): Statement expected, but expression of type 'TDBGrid' found [Error] Unit1.pas(67): '.' expected but ';' found [Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas' 我用的是DelPhi 7 可否協助排除問題 感激不盡萬般感謝 |
kevinsoung
一般會員 發表:36 回覆:41 積分:15 註冊:2011-11-09 發送簡訊給我 |
|
mephise
高階會員 發表:4 回覆:149 積分:205 註冊:2004-02-09 發送簡訊給我 |
光是程式碼Copy進來可不行, 你還要宣告啊
錯誤訊息說的很清楚, 你使用了未宣告的物件 所以請注意 type 部分的宣告: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, DB, DBTables, Grids, DBGrids, SMDBGrid, StdCtrls; type TDBGrid=class(DBGrids.TDBGrid) public function DoMouseWheel(Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint): Boolean; override; end; type TForm1 = class(TForm) DBGrid1: TDBGrid; DataSource1: TDataSource; Table1: TTable; Edit1: TEdit; Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } 這邊要宣告 procedure TForm1.DBGridMouseWheelDown(Sender: TObject; Shift: TShiftState; MousePos: TPoint; var Handled: Boolean); public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm}
------
Mephise Chen 前興德工程師 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |