uniguisyriusz Posted July 16, 2019 Share Posted July 16, 2019 how set datasource of tunidbgrid after dataset open? Quote Link to comment Share on other sites More sharing options...
Abaksoft Posted July 16, 2019 Share Posted July 16, 2019 Can you clarify ? Quote Link to comment Share on other sites More sharing options...
uniguisyriusz Posted July 17, 2019 Author Share Posted July 17, 2019 First situation: Unidbgrid.datasource = datasource1; datasource1.dataset = fdquery1; after fdquery1.open in unidbgrid I can see columns and rows with data. Second situation: unidbgrid.datasource = null; datasource1.dataset = fdquery1; fdquery1.open; In afteropen of fdquery1: unidbgrid.datasource = datasource1; In this situation I can't see columns and rows, unidbgrid is "empty" until browser resize, form resize or click on refresh button of unidbgrid. Calling unidbgrid.JSInterface.JSCall('view.refresh', []); in afteropen of fdquery works, but when I set fdquery.ResourceOptions.CmdExecMode := amAsync then exception "Attempt to access nil session reference" is raising. Quote Link to comment Share on other sites More sharing options...
Abaksoft Posted July 17, 2019 Share Posted July 17, 2019 May be : Set your datasource on beforOpen of FdQuery1. Ok, but why are you doing this gymnastic ? Quote Link to comment Share on other sites More sharing options...
uniguisyriusz Posted July 17, 2019 Author Share Posted July 17, 2019 It takes a long time to open the query. I want to show a form with an empty grid, after running a query in the background (fdquery.ResourceOptions.CmdExecMode: = amAsync) I want to show data in the grid, so it can not be done in beforeOpen. The second reason is two different queries, with different columns that I want to show in the same grid. Quote Link to comment Share on other sites More sharing options...
Abaksoft Posted July 17, 2019 Share Posted July 17, 2019 1 hour ago, uniguisyriusz said: > It takes a long time to open the query OK, May be : 1. DataSet : FdQuery1.FecthAll := False; FdQuery1.Open 2. UnidbGrid : WebOptions > FetchAll : False Paged : True PageSize : 25 It's very fast even if you have 1 000 000 records ! Quote Link to comment Share on other sites More sharing options...
uniguisyriusz Posted July 17, 2019 Author Share Posted July 17, 2019 Count of records is not problem (the number of rows is small), and I can't have pagination. Thank You for your help but You not trying to solve my problem, you are looking for other solutions. Quote Link to comment Share on other sites More sharing options...
Hayri ASLAN Posted July 17, 2019 Share Posted July 17, 2019 6 hours ago, uniguisyriusz said: Calling unidbgrid.JSInterface.JSCall('view.refresh', []); in afteropen of fdquery works, but when I set fdquery.ResourceOptions.CmdExecMode := amAsync then exception "Attempt to access nil session reference" is raising. In your stuation, something happening in background. You can't update user interface. To be able to update it, you need an event from client side. What i suggest is, add an unitimer to form and set enabled=False when query open. This timer will create events for you. Quote Link to comment Share on other sites More sharing options...
uniguisyriusz Posted July 17, 2019 Author Share Posted July 17, 2019 What would the timer do? Quote Link to comment Share on other sites More sharing options...
Hayri ASLAN Posted July 17, 2019 Share Posted July 17, 2019 It will create ajaxevents from client side to server side. All you need is an event to update ui. Quote Link to comment Share on other sites More sharing options...
uniguisyriusz Posted July 17, 2019 Author Share Posted July 17, 2019 This solution raise the same exception "Attempt to access nil session reference " Quote Link to comment Share on other sites More sharing options...
Hayri ASLAN Posted July 17, 2019 Share Posted July 17, 2019 Are you calling refresh on open? Quote Link to comment Share on other sites More sharing options...
uniguisyriusz Posted July 17, 2019 Author Share Posted July 17, 2019 Refresh on UniDbGrid? unit Main; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, uniGUITypes, uniGUIAbstractClasses, uniGUIClasses, uniGUIRegClasses, uniGUIForm, FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Param, FireDAC.Stan.Error, FireDAC.DatS, FireDAC.Phys.Intf, FireDAC.DApt.Intf, FireDAC.Stan.Async, FireDAC.DApt, Data.DB, FireDAC.Comp.DataSet, FireDAC.Comp.Client, uniGUIBaseClasses, uniBasicGrid, uniDBGrid, uniButton, uniPanel, uniTimer, uniThreadTimer; const WM_MY_MESSAGE = WM_USER + 0; type TMainForm = class(TUniForm) FDQuery1: TFDQuery; UniDBGrid1: TUniDBGrid; DataSource1: TDataSource; UniButton1: TUniButton; UniTimer1: TUniTimer; procedure FDQuery1AfterOpen(DataSet: TDataSet); procedure UniButton1Click(Sender: TObject); private public { Public declarations } end; function MainForm: TMainForm; implementation {$R *.dfm} uses uniGUIVars, MainModule, uniGUIApplication; function MainForm: TMainForm; begin Result := TMainForm(UniMainModule.GetFormInstance(TMainForm)); end; procedure TMainForm.FDQuery1AfterOpen(DataSet: TDataSet); begin DataSource1.DataSet := FDQuery1; UniDBGrid1.DataSource := DataSource1; UniTimer1.Enabled := false; //UniDBGrid1.JSInterface.JSCall('view.refresh', []); end; procedure TMainForm.UniButton1Click(Sender: TObject); begin FDQuery1.Open(); end; initialization RegisterAppFormClass(TMainForm); end. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.