UniterYazilim Posted February 18, 2019 Share Posted February 18, 2019 Hi, Thank you for your help. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted February 18, 2019 Share Posted February 18, 2019 Hi, You can try to use UniDBGrid -> OnAfterLoad event I guess Quote Link to comment Share on other sites More sharing options...
UniterYazilim Posted February 18, 2019 Author Share Posted February 18, 2019 Hi, Thanks for your help @Sherzod. I can solve the UniDBGrid -> OnAfterLoad event by basing a condition for this example. But there are other similar situations. How can I build the callback structure for such cases? Quote Link to comment Share on other sites More sharing options...
UniterYazilim Posted February 19, 2019 Author Share Posted February 19, 2019 Hi, // I click this button. procedure TframeRapor1.btnKopyalaCopyGroupClick(Sender: TObject); begin try // DB Update Process CopyGroupCalculate(MainDataModule.dsetGetICMUserSymbolCopyGroupValue.Value); // Refresh the grid with DB GetICMReportMaster(UniMainModule.UserID.ToString, String(MainDataModule.dsetAccountAccount.Value)); isCalculateCopyGroup := true; except on E: Exception do ShowMessage(E.ClassName + ' error raised, with message : ' + E.Message); end; end; procedure TframeRapor1.CopyGroupCalculate(ICMUserSymbolCopyGroupValue: string); begin MainDataModule.dsetGeneral.Close; MainDataModule.dsetGeneral.SQL.Clear; MainDataModule.dsetGeneral.SQL.Add ('EXEC spSetICMReportCalculateCopyGroup @ICMReportUserSymbolIDs = :ICMReportUserSymbolIDs'); MainDataModule.dsetGeneral.ParamByName('ICMReportUserSymbolIDs').Value := MainDataModule.dsetGetICMUserSymbolCopyGroupValue.Value; MainDataModule.dsetGeneral.Execute; MainDataModule.dsetGeneral.Close; end; procedure TframeRapor1.GetICMReportMaster(UserID: string; Account: string); var isCorrectSymbol: Boolean; ICMReportMasterRecNo: Integer; begin try if (NOT MainDataModule.dsetGetICMReportMaster.IsEmpty) then begin ICMReportMasterRecNo := MainDataModule.dsetGetICMReportMaster.RecNo; end; dbGridGetICMReportMaster.BeginUpdate; MainDataModule.dsetGetICMReportMaster.Active := false; MainDataModule.dsetGetICMReportMaster.SQL.Clear; MainDataModule.dsetGetICMReportMaster.SQL.Add ('EXEC spGetICMReportMaster @UserID = :UserID, @Account = :Account'); MainDataModule.dsetGetICMReportMaster.ParamByName('UserID').Value := UniMainModule.UserID; MainDataModule.dsetGetICMReportMaster.ParamByName('Account').Value := MainDataModule.dsetAccountAccount.Value; MainDataModule.dsetGetICMReportMaster.Active := true; dbGridGetICMReportMaster.EndUpdate; selectedSymbol := ''; selectedSide := ''; MainDataModule.dsetGetICMReportMaster.RecNo := ICMReportMasterRecNo; dbGridShow(TGrid.GetICMReportMaster); except on E: Exception do ShowMessage(E.ClassName + ' error raised, with message : ' + E.Message); end; end; // OnAfterLoad procedure TframeRapor1.dbGridGetICMReportMasterAfterLoad(Sender: TUniDBGrid); begin if (isCalculateCopyGroup) then begin isCalculateCopyGroup := false; GetSelectRecordDbGridByICMReportUserSymbolID (MainDataModule.dsetGetICMUserSymbolCopyGroupValue.Value, 10); end; end; // Select DBGrid Row and Get Selected Row Info procedure TframeRapor1.GetSelectRecordDbGridByICMReportUserSymbolID (ICMReportUserSymbolIDs: string; setTime: Integer); var I: Integer; currentRecNo: Integer; List: TStrings; _RecNo: Integer; JScript: string; rowInfo: string; begin if NOT MainDataModule.dsetGetICMUserSymbolCopyGroupValue.IsNull then begin dbGridGetICMReportMaster.BeginUpdate; List := TStringList.Create; ICMReportUserSymbolIDToRecNos := FindICMReportUserSymbolIDToRec (ICMReportUserSymbolIDs); JScript := CONCAT('setTimeout(function(){ console.log("setTime"); },', setTime.ToString, ');'); JScript := CONCAT(JScript, 'setTimeout(function(){ ', dbGridGetICMReportMaster.JSName, '.getSelectionModel().deselectAll()}, 50);'); with MainDataModule.dsetGetICMReportMaster do begin ExtractStrings([','], [], PChar(ICMReportUserSymbolIDToRecNos), List); for I := 0 to List.count - 1 do begin _RecNo := StrToInt(List[I]); if (I = (List.count - 1)) then begin rowInfo := CONCAT(rowInfo, GetGridInfoWithRecNo(_RecNo)); end else begin rowInfo := CONCAT(rowInfo, GetGridInfoWithRecNo(_RecNo), #13#10); end; if (_RecNo > 0) then begin _RecNo := _RecNo - 1; end; JScript := CONCAT(JScript, 'setTimeout(function(){ ', dbGridGetICMReportMaster.JSName, '.getSelectionModel().select(', dbGridGetICMReportMaster.JSName, '.getStore().data.indexOfKey(', IntToStr(_RecNo) + '), true)}, 50);'); end; memoClipboard.Lines.Clear; memoClipboard.Lines.Add(rowInfo); UniSession.SendResponse(JScript); // UniSession.AddJS(JScript); FreeAndNil(List); end; dbGridGetICMReportMaster.EndUpdate; end; end; // Get Row Info function TframeRapor1.GetGridInfoWithRecNo(RecordNo: Integer): string; var size: Integer; Symbol: string; Side: Char; Quantity: string; Price: string; str: string; currentRecNo: Integer; begin try if NOT MainDataModule.dsetGetICMReportMaster.IsEmpty then begin if (MainDataModule.dsetGetICMReportMaster.RecordCount > 0) then begin dbGridGetICMReportMaster.BeginUpdate; with MainDataModule.dsetGetICMReportMaster do begin currentRecNo := RecNo; RecNo := RecordNo; if (Trim(FindField('SideKey').AsString) = '1') then begin Side := '+'; end else begin Side := '-'; end; if (NOT FindField('Symbol').IsNull) then Symbol := FindField('Symbol').AsString; if (NOT FindField('QtyDiff').IsNull) then Quantity := FindField('QtyDiff').AsString; if (NOT FindField('AvgPxDiff').IsNull) then Price := FindField('AvgPxDiff').AsString; size := 0; if (Length(Symbol) > size) then size := Length(Symbol); if (Length(Quantity) > size) then size := Length(Quantity); if (Length(Price) > size) then size := Length(Price); size := size * 2; str := format(CONCAT('%s', SetSpace(size - Length(Symbol)), '%s', SetSpace(size - Length(Side)), '%s', SetSpace(size - Length(Quantity)), '%s'), [Symbol, Side, Quantity, Price]); str := str.Replace('.E', ''); RecNo := currentRecNo; end; dbGridGetICMReportMaster.EndUpdate; end; end; finally Result := str; end; end; When I run with the above code the grid gets stuck in Loading mode! what an I doing wrong? Thank you for your help. Best regards. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted February 19, 2019 Share Posted February 19, 2019 Hi, Sorry, better if you make a test case for this and explain how to reproduce it. Quote Link to comment Share on other sites More sharing options...
UniterYazilim Posted February 19, 2019 Author Share Posted February 19, 2019 Hi, Sample is attached. Operation: 1. Choose the LookUpComboBox record 2. Select records on dbgrid when doing step 1 3. Press the Calculate button { Calculate button actions: DBUpdate, Refresh Grid, Selected Row (selected record in step 2) } procedure TMainForm.dbGridGetICMReportMasterAfterLoad(Sender: TUniDBGrid); begin if (isCalculateCopyGroup) then begin isCalculateCopyGroup := false; // dbgrid loading mode hang when this code working. // GetSelectRecordDbGridByICMReportUserSymbolID // (dmMain.dsetGetICMUserSymbolCopyGroupValue.Value); end; end; Thanks. UniDBGridExample.zip Quote Link to comment Share on other sites More sharing options...
UniterYazilim Posted February 20, 2019 Author Share Posted February 20, 2019 On 2/18/2019 at 1:24 PM, UniterYazilim said: Hi, Thanks for your help @Sherzod. I can solve the UniDBGrid -> OnAfterLoad event by basing a condition for this example. But there are other similar situations. How can I build the callback structure for such cases? procedure TframeRapor1.dbGridGetICMReportMasterAfterLoad(Sender: TUniDBGrid); begin if (isCalculateCopyGroup) then begin isCalculateCopyGroup := false; // dbgrid loading mode hang when this below code working // UniSession.SendResponse('console.log(''1'');'); // no problem this below code working // UniSession.AddJS('console.log(''1'');'); end; end; What is the different? why dbgrid loading mode hang when use UniSession.SendResponse? thanks. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted February 20, 2019 Share Posted February 20, 2019 18 hours ago, UniterYazilim said: UniDBGridExample.zip Hi, Sorry for the late reply. I couldn't run your testcase, it seems that you are using the DevExpress component Quote Link to comment Share on other sites More sharing options...
Sherzod Posted February 20, 2019 Share Posted February 20, 2019 1 hour ago, UniterYazilim said: What is the different? why dbgrid loading mode hang when use UniSession.SendResponse? http://forums.unigui.com/index.php?/topic/1412-sendresponse-or-addjs/&do=findComment&comment=5255 Quote Link to comment Share on other sites More sharing options...
UniterYazilim Posted February 20, 2019 Author Share Posted February 20, 2019 31 minutes ago, Sherzod said: http://forums.unigui.com/index.php?/topic/1412-sendresponse-or-addjs/&do=findComment&comment=5255 Hi, Do I have trouble using "UniSession.AddJS" too much? Thank you for your help. Quote Link to comment Share on other sites More sharing options...
UniterYazilim Posted February 20, 2019 Author Share Posted February 20, 2019 1 hour ago, Sherzod said: Hi, Sorry for the late reply. I couldn't run your testcase, it seems that you are using the DevExpress component Hi, Sorry I'm use devexpress TdxMemData. I attached again and I used TFDMemTable component in this project Thanks. UniDBGridExample.zip 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.