求教:TDataSet.AfterScroll事件和TDataSource.OnDataChange事件的区别?

rick29 2005-12-23 09:32:56
我是个DELPHI新手。在公司现在需要用到dxDbGrid,当然有相应的DataSet、DataSource与之关联。现在的情况是这样的,用Grid查询显示到一批数据,Grid之外还有一些非数据感知的EditBox,我们需要在鼠标单击或键盘操作(方向箭、PgUp、PgDn等)选择不同的记录时,在那些非数据感知的控件中显示相关的一些内容。因一些原因暂时不考虑Grid的OnNodeChange事件。

  我将其放入相应DataSource之OnDataChange事件后,问题可以解决。
但我们的主管要求我放入DataSet之AfterScroll事件进行处理。于是问题出现,在查询Refresh(相应的DataSet先Close再Open实现Refresh)时这个AfterScroll会触发很多次。因为外部非数据感知控件的查询是根据当前Grid的内容来继续Query数据库的,因此多次触发导致效率严重下降,界面停顿。

  我查阅了Delphi的相关控件的Help。可以读懂两者对应的解释。以我对Help的理解,感觉放到OnDataChange中更好一些。但是我还是比较迷茫,这两个事件的区别在哪里?分别用到什么地方最为休合适?——如果我用OnDataChange,我想我得有足够的理由去和主管解释。

  诚心求教,分不够可以再加。在线等待,谢谢!
...全文
804 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhangl_cn 2005-12-23
  • 打赏
  • 举报
回复
那这样,刷新之前先令OnAfterScroll:=nil;完了再把OnafterScroll:=OnAfterScroll

//大概就是这样子吧,你再试试
rick29 2005-12-23
  • 打赏
  • 举报
回复
报告,在刷新之前DisableControls,导致Grid里什么也显示不出来。在刷新之后再EnableControls,问题仍在,AfterScroll似乎读一条数据就会刷新一次。我做了个5条数据的试验,结果发现触发AfterScroll有9次之多。
rick29 2005-12-23
  • 打赏
  • 举报
回复
多谢楼上,我也去瞧瞧。另,我的GRID是整行选中的,而且不允许EDIT,这样应该不存在列间切换(?)。我也去试一把。谢谢!
zhangl_cn 2005-12-23
  • 打赏
  • 举报
回复
OnDataChange应该是不仅仅针对行的,同一行不同列之间切换也会触发该事件,

AfterScroll只是针对行变化的才触发的,

////以上是猜的,手头现在没有DELPHI,稍候去验证一下。


放在AfterScroll中的话,不知道你Refresh之前先DataSet.DisableControls一下不知有没有效果
呆会给一起验证一下

rick29 2005-12-23
  • 打赏
  • 举报
回复
江湖救急,UP一个。。
rick29 2005-12-23
  • 打赏
  • 举报
回复
up
rick29 2005-12-23
  • 打赏
  • 举报
回复
看了一下,这里好象只说明了deRecordChange, deDataSetChange, deDataSetScroll, deLayoutChange时触发FOnDataChange,我想知道AfterScroll和DataSet的OnDataChange有什么区别,或者,在我现在这个情况下,用哪个比较好,为什么?本来这种问题我可以不问的,可是我们那位仁兄是个非常坚持己见的人,通常不会去听别人的意见。否则我早用OnDataChange,一切搞定。
rick29 2005-12-23
  • 打赏
  • 举报
回复
多谢,俺研究一下。:)
Changefish 2005-12-23
  • 打赏
  • 举报
回复
procedure TDataSource.DataEvent(Event: TDataEvent; Info: Longint);
begin
if Event = deUpdateState then UpdateState else
if FState <> dsInactive then
begin
NotifyDataLinks(Event, Info);
case Event of
deFieldChange:
if Assigned(FOnDataChange) then FOnDataChange(Self, TField(Info));
deRecordChange, deDataSetChange, deDataSetScroll, deLayoutChange:
if Assigned(FOnDataChange) then FOnDataChange(Self, nil);
deUpdateRecord:
if Assigned(FOnUpdateData) then FOnUpdateData(Self);
end;
end;
end;
看看这段源码 应该就非常清楚OnDataChange了
Changefish 2005-12-23
  • 打赏
  • 举报
回复
(相应的DataSet先Close再Open实现Refresh)时这个AfterScroll会触发很多次

这种做法OnDataChange也会触发
Changefish 2005-12-23
  • 打赏
  • 举报
回复
OnDataChange比较好
rick29 2005-12-23
  • 打赏
  • 举报
回复
是个办法,不过这样做在我们头儿看来也是投机取巧。如果这样可以的话,那我用OnDataChange的写法早就通过了,唉。。。
还是谢谢!
ZeosDBO is a database middleware components for Borland development tools, including Delphi, C++ Builder and Kylix. The following compilers are supported: Delphi 5 - 7C++ Builder 5 - 6Kylix 2 - 3ZeosDBO supports direct connectivity to the following databases using the vendor provided, native interface: MySQL 3.20 - 4.1PostgreSQL 6.5 - 7.4Firebird 1.0 - 1.5Interbase 5.0 - 7.5Microsoft SQL Server 7, 2000Sybase ASE 12.0, 12.5Oracle 9iSQLite 2.8For other databases we propose to use implemented Active Data Objects (ADO) Bridge. Advantages of using ZeosDBO: Platform independance. The ZeosDBO is highly generic. Applications written in ZeosDBO can be migrated across databases without major changes. ZeosDBO is open source, written for usability and extensibility. ZeosDBO leverages the amazing power of the Delphi development environment without relying on a performance killing middleware. ZeosDBO is an extremely thin abstraction layer, unlike ‘thick‘ layered protocols like ADO and BDE. Package contents: ZCore - Core classes and interfaces. Contains Java style objects and collections as well as compatibility types and functions. ZParseSql - SQL specific for syntax and lexical analysis. ZPlain - Native plain API to supported SQL servers. ZDbc - Port of Java Database Connectivity API (JDBC 2.0). DBC API acts as intermediate layer between Plain API and highlevel TDataset or DBExpress components. ZComponent - visual components descended from TDataset. Installed components: TZConnection: This component encapsulates the database connection and transaction management. TZReadOnlyQuery: TDataset component to execute SQL queries and process data in read-only mode. TZQuery: TDataset component which allows data modifications in regular and cached mode. TZUpdateSQL: Analog of standard TUpdateSQL component to explicite definition of Insert/Update/Delete SQL statements for TDataset modifications. TZStoredProc: The component to execute SQL stored procedures. TZSQLProcessor: The component to execute SQL scripts for different SQL and various delimiter types. TZSQLMonitor: The component to monitor all outgoing SQL queries and other logging information. TZSQLMetadata: Specialized TDataset component which provides an access to database metadata such as tables, columns, indices, etc.
0.83.5.820 +---------------------------------------------------------------------------------------- - 0000796: DBGrid: Render bug when Column color is clWindow and project is created with 0.82 - 0000795: Grid: Cell background color change poor render performance - 0000791: UniDBGrid, UniStringGrid: Option to disable custom renderer to speed-up render time. 0.83.4.819 +---------------------------------------------------------------------------------------- - 0000789: UniDBComboBox, UniDBListBox: Edit mode is not set when changed - 0000784: TUniStringGrid: Data not restored after decreasing/increasing Row count - 0000788: Bug in Grid Row/Col translation - 0000787: UniDBGrid: Broken CellSelect behavior - 0000786: MessageDlg and mtInformation bug. 0.83.2.817 +---------------------------------------------------------------------------------------- - 0000781: UniDBGrid: Row selection bug when no data is in dataset - 0000779: UniStringGrid: OnClick event implemented - 0000780: UniDBGrid: OnCellClick bug - 0000777: TUniDBGridColumn.ReadOnly property - 0000778: UniStringGrid: Assigning HTML content to cells - 0000776: UniDBLookUpXXX: ListSource cursor position does not follow Lookup value - 0000773: UniDBGrid: Column.Title.Font/Color - 0000771: UniDBGrid: Column.Font property - 0000772: UniDBGrid: Column.Color property - 0000775: UniFont: [fsUnderline, fsStrikeOut] implemented - 0000774: TUniStringGrid: OnDrawCell event - 0000769: UniDBGrid: Row position is ignored if row is immediately changed after a call to Open() - 0000673: UniDBGrid: OnDrawColumnCell event - 0000768: Better "ext\" folder translation - 0000766: TUniCalender.FirstDayOfWeek property - 0000767: TUniDateTimePicker.FirstDayOfWeek property - 0000765: UniImage: Bug when both Proportional and Stretch are true - New Demo: DrawCell 0.83.1.812 +---------------------------------------------------------------------------------------- - 0000764: KeyValue property for UniDBLookupXXX - 0000763: UniDBGrid doesn't handle TDataSet.Refresh() - 0000762: UniListBox and Items.Delete bug - 0000760: UniDBLookupXXX: KeyField value submit bug - 0000761: UniEdit and KeyXXX event bug - 0000759: UniDBLookupXXX: KeyField value problem 0.83.0.811 +---------------------------------------------------------------------------------------- - 0000756: MenuItem.Enabled property - 0000755: MenuItem.Visible not working in web mode. - 0000754: UniPageControl: UniTabSheet design time editor - 0000661: enabled/disabled property of TUniToolbarButton - 0000751: UniRadioButton value submission bug - 0000749: Changing ReadOnly := False in UniDateTimePicker & UniDbLookupComboBox raises AV - 0000721: Set ReadOnly := False on UniDB controls on runtime raises AV - 0000445: Customizable Timeout and Terminate pages. - 0000558: Customizable End of Session - 0000748: Field property for DB aware controls - 0000747: AV when trying to access the property TUniDBEdit.Field - 0000746: SessionManager: Bug when there is an Exception in session.Destroy - 0000745: TUniMemo.Clear bug - 0000740: UniTreeView: Node.Data not implemented - 0000744: UniDBMemo.Lines property - 0000743: UniDBMemo.Text porperty is not published - 0000739: UniTreeView: Items.Clear not implemented - 0000736: UniPageControl: Runtime assignment of OnChange event - 0000737: UniDBLookupXXX: Bug when there is " in string - 0000738: UniTreeView: GetFirstNode not implemented - 0000485: TUniButton renders non-themed! - 0000698: Toolbar Button Image/Text alignment - 0000732: TUniPageControl: Bug while setting designtime ActivePage - 0000716: Change Tab title in runtime - 0000507: Direct filename or image URL for TUniImage - 0000733: TUniScreenMask with a TUniPageControl does not work - 0000734: AutoScroll property for UniHTMLFrame - 0000680: The Alignment taRightJustify of a TUniDBGrid column - 0000610: TabOrder for dynamically created controls - 0000627: Unpublish OnChange in TUniComboBox web mode - 0000601: New Event in ServerModule to handle exceptions - 0000728: Disabled UniEdit does not receive values assigned with Control.Text := Value - 0000720: Tag property for DBGrid Columns - 0000723: DBGrid: numeric column is not aligned to right - 0000722: Setting Align := alCenter on DBGridColumns does not work - 0000715: OmniHTTPD and UniGUI ISAPI - 0000724: Runtime assignment for Align/Alignment property of UniDbGrid column - 0000714: UniDBGrid: Implement StripeRows property - 0000712: raise error if Form owner is not either TUniGUIApplication or TApplication - 0000609: TUniTimer: Attach to TUniScreenMask - 0000703: TUniDBLookUpxxx bug when datasource and datafield are not assigned - 0000731: Broken TabOrder in 0.82.0 - 0000708: UniGroupBox: Caption assignment when created dynamically - 0000706: UniEdit: Password char bug - 0000707: UniSplitter: ScreenMask doesn't work - 0000709: Changes in Form layout not reflected correctly - 0000437: AV when creating inherited forms when no projectgroup is available - 0000413: Maximized ExtWindow can't return to normal size - 0000697: UniPanel: Caption Alignment - 0000696: UniPanel: Caption - 0000699: UniPageControl: TabSheet is visible when TabVisible=False - New Demo: CustomException - New Demo: UniImage 0.82.1.804 +---------------------------------------------------------------------------------------- - 0000630: Big images in buttons - 0000692: Runtime creation and modification of DBLookup components - 0000693: UniDBLookup bug - 0000695: UniDBGrid: Broken OnCellSelect in 0.82.0 0.82.0.803 +---------------------------------------------------------------------------------------- - 0000668: UniDBGrid with data Memory leak - 0000686: New TUniHTMLFrame Component - 0000570: New TUniDBLookupComboBox and TUniDBLookupListBox Components - 0000689: CustomFiles property for ServerModule to add custom CSS and JS files - 0000688: Bug in installer Environment setter - 0000687: "Script" property for TUniForm for adding Custom JS - 0000665: Compatibility with multiple IP systems - 0000685: UniDBGrid: Ellipsis in first column bug (IE) - 0000690: UniDBGrid: OnTitleClick event - 0000684: UniEdit: Text alignment - 0000683: UniScreenMask bug with Maximized Form and mfPage set - 0000682: UniStringGrid: OnSelectCell bug - 0000679: Common DB Controls bug - 0000641: UniTabSheet.TabVisible property - 0000678: Core bug: Setting Align property at runtime - 0000677: Hiding or showing controls doesn't apply alignment/anchoring correctly - 0000675: Setting position of a UniTrackbar at run time - 0000671: UniDBListBox: Dataset is not set to edit mode after change - New Demo: DBLookup - New Demo: HTMLFrame - New Demo: Basic jQuery 0.81.2.801 +---------------------------------------------------------------------------------------- - TUniScreeMask issue with borderless MainForm - Installer: Bug resolved when selected Delphi version is not installed - XE DCU files compiled with Update 1 - Borderless MainForm bug fix 0.81.1.800 +---------------------------------------------------------------------------------------- - UniDBGrid: Critical bug in ISAPI mode - Critical bug in AssignGlobalDateParams 0.81.0.798 +---------------------------------------------------------------------------------------- - New Component UniDBText - Ability to create a windowless borderless MainForm - UniTreeView: Node dynamic add/delete support - UniTreeView: Several Memory leak issues - UniDBGrid: DBGrid.Column.Visible bug - PageControl: Render problem in invisible tabs - TUniListBox: Items are not rendered if placed on UniPageControl invisible Tab - ISAPI: Bug when pathInfo contains Unicode chars - TUniLabel Text alignment - UniDBGrid: _OnDataLoaded may be called before Grid is rendered - UniPageControl: TabIndex doesn't return correct index - UniComboBox in hidden TabPage bug in Chrome browser - UniApplication: New ClientInfo property - New Demo: TreeView - New Demo: ClientInfo - New Demo: Windowless 0.80.2.796 +---------------------------------------------------------------------------------------- - TUniChart moved to UniGUIEx package - TUniSplitter: Runtime create problem - Memory Leak in TUniForm 0.80.1.794 +---------------------------------------------------------------------------------------- - Apache web server and CoInitialize issue - UniSplitter Color in Web mode - UniSplitter broken and Ext JS 3.3.0 issue - New Component: TUniChart Component first preview - UniDateTimePicker: OnEnter, OnExit Events - UniGroupBox: CSS frame margin bug (IE) - TUniLabel: AutoSize problem - UniFileUpload: several changes - UniFileUpload: File names containing Unicode chars are returned correctly - Change color of label at runtime - Various runtime property assignment bugs - DataStores and AutoDestroy - Changing Server Port at runtime. - TabOrder and TabStop for Web - Upgraded to Latest Ext JS release (3.3.0) - UniTrackBar: Set Max at runtime - UniDBGrid: DataSet AfterEdit: Reload grid only when needed - New Demo: Chart Demo 0.79.1.788 +---------------------------------------------------------------------------------------- - UniRadioGroup: Render bug when control is disabled - Style:"color:#000000" in FontStyle bug - FileUpload bug - New TUniScreenMask component - Add startup "Loading..." message - Server Bindings property implemented - OwnerForm.IsDestroying: When owner is TUniFrame - DB Controls: Check IsDestroying - Allow suppressing "Ajax" and "Object not found" Errors - SynEdit: some unicode widechars cause problem in D2009+ (removed) - InsertControl/RemoveControl internal bug - TUniToolButton: Dynamic creation - UniDBGrid: Grid row doesn't change when table row changes - UniDBGrid: Master/Detail Support - uniDBGrid: Assigning ReadOnly property in runtime - uniDBGrid: Assigning Options.dgEditing property in runtime - UniForm: Event OnScreenResize implemented - UniForm: Event OnResize implemented - UniApplication: ScreenWidth, ScreenHeight Property - UniTreeView: AutoExpand Property - A mean to determine dimensions of the browser window - ExtPascal: Param Place Holders problem - TreeView: Full Tree load on first call - UniTreeView: TTreeNode.MakeVisible implemented - uniDBGrid: After opening grid row is set to real Dataset cursor location - UniGroupBox: Caption not visible bug - UniRadioGroup: Caption not visible bug - UniRadioButton: OnClick event implemented - UniLabel: Allow HTML Content - ServerModule: Implement Temp Folder Property - Unicode bug in ISAPI module - New Demo: Screen Size - New Demo: UI Mask - New Demo: Download Demo 0.78.0.783 +---------------------------------------------------------------------------------------- - Lots of changes and bug fixes in Unicode and codepage handling - Ajax Core: Queue process improvement - Don't respond Alert() to data requests - UniExtTimer.Stopall: check for null object - ExtJS: Test for "undefined" before destroy - UniDBGrid bug: FColumnsChanged is True after ConfigureExtColumns - A customized version of Indy included (10.5.7) - Unicode data transfer and IIS ISAPI bug - TUniTimer runtime enable bug - ExtPascal: StrToJS problem: Strings containing %nn - Unicode conversion bug - UniToolBar: ShowCaptions implemented - Inherited form Reader bug - Delphi XE: Unicode conversion problem - UniPageControl: Dynamic create: Initial ActiveTab bug? - New Demo: Unicode Demo (for D2009 and later) 0.77.1.781 +---------------------------------------------------------------------------------------- - D2009+ UniFrame creation problem - Other Project Wizard related bugs fixed 0.77.0.780 +---------------------------------------------------------------------------------------- - uniEdit, uniDBEdit: CharEOL property added - Buttons: Click Method implemented - New WebOptions property for uniDBGrid (Paged, PageSize) - CodeMirror: Missing Pascal keywords added - New Demo: CharEOL Demo 0.76.0.779 +---------------------------------------------------------------------------------------- - Delphi XE Support - uniTreeView: AddChild() Implemented - uniTreeNode: IsFirstNode() Implemented - ExtPascal: VarToJSON: WideString conversion bug - uniTreeView: D2009+ resource compatibility issue - In web mode some controls aren't assigned a default Width/Height - In StrToJs is not interpreted correctly. - UniSyntaxEdit: CodePress replaced with CodeMirror (CodePress files removed from installer) - Standalone server will display application name - Control parent assignment bug when parent is TUniForm - UniRadioGroup: runtime OnClick event assignment bug - Other minor changes and fixes - New Demo: SQL Demo ( Requires DBISAM http://www.elevatesoft.com/download?category=dbisam ) 0.75.0.777 +---------------------------------------------------------------------------------------- - Internal Bug fix in TUniExtWinControl.SetComponentsLoaded() - Internal Bug fix in TUniExtWinControl.RemoveControl() - UniEdit: MaxLength Property implemented - UniSplitter improved - Several bug fixes in UniSplitter - UniSyntaxEdit improved - UniSyntaxEdit bug fixes - Now SynEdit Packages are included in the installer 0.74.0.774 +---------------------------------------------------------------------------------------- - New: Inheritable Frames - New: Inheritable DataModules - New: In "Object Inspector" properties that are not implemented in web mode are displayed in gray - Bug in inherited form implementation - Improved exception handling - UniDBGrid: OnCellClick passes wrong Column - TUniDBGridColumn: Implement Field public property - When wsMaximized some components may render in wrong placed (IE8) - TUniForm: OnDestroy() implemented - DB Controls: Dynamic DataSource assignment - Workaround for WindowState wsMaximized problem 0.73.0.770 +---------------------------------------------------------------------------------------- - New: Service Application implemented - Async request mode is default mode now - Several Bug fixes and changes in AJAX Core - DB Controls: Internal improvements and fixes 0.72.2.767 +---------------------------------------------------------------------------------------- - Several internal core changes and bug fixes 0.72.1.766 +---------------------------------------------------------------------------------------- - Sync mode partially disabled 0.72.0.765 +---------------------------------------------------------------------------------------- - New Component TUniFileUpload - KeyEvents internal bug - TUniDBNavigator: VisibleButtons Property implemented - TUniEdit: Clear Method implemented - Bug: Showing a Window in another Window's OnShow event - uniMainMenu: Top level menus OnClick event not implemented - KeyEvents Bug - AJAX Core problem - Now Close tool button on Window can be removed - New Sync/Async modes implemented - Bug: Calling DataSet.Refresh in OnClose event may raise Ajax Error - When no project is active creating a new Form or DataModule fails - TUniImage: PNG Images are not shown in Web Mode - PNG/GIF type Images will not be converted to other formats - AV when calling FullExpand method of TUniTreeView - TUniTreeView: FullCollapse implemented - Internal Bug in DB Control DataChange - TUniForm: OnActivate implemented - Bug in ShowMessage - New Demo: FileUpload 0.71.0.760 +---------------------------------------------------------------------------------------- - New Component TUniDBListBox - New Component TUniDBComboBox - New Component TUniURLFrame - Form Inheritance implemented - OnEnter and OnExit Events implemented - TUniRadioGroup: OnClick Event implemented - Bug in UniTabControl - URL Parameters Implemented - New method: UniApplication.Terminate() - TUniEdit CharCase property implemented - TUniDateTimePicker "Visible" bug fixed - SetFocus bug fixed - TuniRadioGroup: ItemIndex implemented - TUniPageControl: Property ActivePage implemented - TUniListBox: ItemIndex bug fixed - DB Controls: internal Bug fixed - StandAloneServer Control Panel imporved - Improved Project Wizard - UniDateTimePicker: OnChange event implemented - Forms divided into two categories: Application Forms and normal Forms - KeyDown, KeyUp, KeyPress implemented - ExtRoot bug in ServerModule fixed - ClientHeight problem in XP theme fixed - 4 new demos: URLFrame, FormInheritance, Dynamic, URLParameters 0.70.0 +---------------------------------------------------------------------------------------- First Beta

2,497

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧