jahlxx Posted August 21, 2018 Share Posted August 21, 2018 Hi. I use tunidblookupcombobox in many forms, and some forms can have many tunidblookupcomboboxes. I have the datasets and datasources for tunidblookupcomboboxes in a separated datamodule, and use them in all the forms I need. Now, in the on show of one form I check for every listsource if its open or not. Id is not open, I open it, and is already open I refresh. If I have only a couple of tunidblookupcomboboxes, there is no problem, but if I have 10 or 15 tunidblookupcomboboxes, this causes a delay in showing forms, and I'd like to know wich is the better way for doing this. Everithing works ok, the delay is my problem. Any idea will be wellcome. Thanks. Link to comment Share on other sites More sharing options...
jahlxx Posted August 23, 2018 Author Share Posted August 23, 2018 No idea? I've been making some tests, and doing this way, almost works fine: - Initially, the listsource is not active - In the onenter event of the dblookupcombobox, I check if the list source is closed. if yes, open it. With these 2 steps, the delay in showing forms are decreased, as expected. But now, when I set a keyvalur to the combobox, it appears as blank, until I enter on it (this is logical) Any idea? I need this please. Thanks. Link to comment Share on other sites More sharing options...
eduardosuruagy Posted August 23, 2018 Share Posted August 23, 2018 I also need this, because I use forms in tabs and when I open a customer registry and add a new one I would like in the order form that is already open, when the user clicks to select a client it fills in with the new one. Link to comment Share on other sites More sharing options...
Wilton Ergon Posted September 4, 2018 Share Posted September 4, 2018 the use of many loockup in a form is not recommended nor in the desktop environment on the web, the delay will be even greater. I prefer to work with external search for these fields with a button that opens a search form, so each table is only queried when needed. my main query already returns me in addition to the fields of the table, also the fields of the auxiliary tables, so when I search the registers, I already search the same sql, the data of the auxiliary tables. in summary, even though I have tens of fields that require external search, my form only has 1 select in its opening. Link to comment Share on other sites More sharing options...
jahlxx Posted September 4, 2018 Author Share Posted September 4, 2018 As workaround, I don't open the listsources at form show event. I'm testing to open them on demand. I'm testing to open the list source in the onenter event of the lookup, and now the form is shown quickly. The only problem is that before show the form I set values to the lookups, for example myfield.keyvalue := '3'; With this, the keyvalue is set ok, and when enter in the lookup, the values of the fields are shown ok, as expected. The only problem is that the form is shown with the lookups text set to blank, even when I set the keyvalue. I hope you understand to me. When set keyvalue, text is still blank. That's my problem. Any idea? Thanks. Link to comment Share on other sites More sharing options...
Oliver Morsch Posted September 4, 2018 Share Posted September 4, 2018 Make it like wilton_rad explained. I do the same. Link to comment Share on other sites More sharing options...
jahlxx Posted September 4, 2018 Author Share Posted September 4, 2018 Yes. I used to do this in that way, but the application is more usable for the users using lookups. I'll try to test more ways. Link to comment Share on other sites More sharing options...
jahlxx Posted September 4, 2018 Author Share Posted September 4, 2018 right now, meanwhile I test other options, is there any way to set keyvalue and have text too? as commented before, when set keyvalue of the field, the text property is blank. thanks. Link to comment Share on other sites More sharing options...
picyka Posted September 4, 2018 Share Posted September 4, 2018 Hello, I had to modify the component to get it on demand automatically, it was not very elegant but it works. it would be interesting if this works automatically, without typing anything. Link to comment Share on other sites More sharing options...
jahlxx Posted September 4, 2018 Author Share Posted September 4, 2018 Hello, I had to modify the component to get it on demand automatically, it was not very elegant but it works. it would be interesting if this works automatically, without typing anything. share? Link to comment Share on other sites More sharing options...
picyka Posted September 4, 2018 Share Posted September 4, 2018 I can yes, I am not with him here at the moment the night I post, you will need to modify it because I usu TMS Aurelius. Link to comment Share on other sites More sharing options...
mierlp Posted September 5, 2018 Share Posted September 5, 2018 Hi Witon The first part i understand, but what do you mean with the second part below...do you have a example. I also have 1 till 5 dblookupcombox on a form...i replaced the with the same solution clicking a button which opens a form display the content of that table. For now i have a 1 datamodules which contains all queries only for lookup use. When i need a lookup table then i refer to this datamodule and query. my main query already returns me in addition to the fields of the table, also the fields of the auxiliary tables, so when I search the registers, I already search the same sql, the data of the auxiliary tables. in summary, even though I have tens of fields that require external search, my form only has 1 select in its opening. Link to comment Share on other sites More sharing options...
Wilton Ergon Posted September 5, 2018 Share Posted September 5, 2018 my query master in form. (form only 1 query) select tab.field1, tab.field2, tabaux1.auxfield1, -> field read only =false in listfields tabaux2.auxfield2 -> field read only =false in listfields from tab inner join tabaux1 on tab.idf1=tabaux1.idf1 inner join tabaux2 on tab.idf2=tabaux2.idf2 in form link field auxfield1 in tunidbedit with readonly place a button next to the tuniedit in button, call a search form on return, set the query value to field auxfield1 set query value in fiedl tab.idf1 obs. not every query component allows joins, and use it to write data. I use sdac and it works. in this example when applying the post method in the query, only the idf1 will be saved in tab Link to comment Share on other sites More sharing options...
jahlxx Posted September 5, 2018 Author Share Posted September 5, 2018 as commented before, I use to do like this in vcl apps, but with lookups, the user experience is better. I have changed for the lookups, and set remotequery to true. with this, the form is shown very fast Link to comment Share on other sites More sharing options...
picyka Posted September 7, 2018 Share Posted September 7, 2018 Attached. unit uniDBLookupComboBoxObject; interface uses System.SysUtils, System.Classes, Vcl.Controls, Vcl.Forms, Data.DB, uniGUIBaseClasses, uniGUIClasses, uniMultiItem, uniComboBox, uniDBComboBox, uniDBLookupComboBox, Aurelius.Bind.Dataset, System.Variants, devsul.model.search, Aurelius.Criteria.Linq, Aurelius.Criteria.Base; type TUniDBLookupComboBoxObject = class(TUniDBLookupComboBox) private { Private declarations } FRequired: Boolean; FListSource, FDataSet: TAureliusDataset; FCriteriaListSource: TCriteria; FListValues: TStringList; procedure ExecuteSearch; protected { Protected declarations } FOldUniTriggerEvent: TUniTriggerEvent; FSearch: TSearch; procedure DoSetRemoteValue(AIndex: Integer; Value: string); override; procedure MyTriggerEvent(Sender: TUniCustomComboBox; AButtonId: Integer); procedure LoadCompleted; override; procedure _RemoteQuery(const QueryString: string; Result: TStrings); procedure _GetKeyValue(const Value: string; var KeyValue: Variant); public { Public declarations } constructor Create(AOwner: TComponent); override; destructor Destroy; override; procedure SetSearch(Search: TSearch); published { Published declarations } property Required: Boolean read FRequired write FRequired default False; end; procedure Register; implementation uses view.search.default, uniGUIApplication, Winapi.Windows; procedure Register; begin RegisterComponents('UniGUI Extension', [TUniDBLookupComboBoxObject]); end; { TUniDBLookupComboBoxObject } constructor TUniDBLookupComboBoxObject.Create(AOwner: TComponent); begin inherited Create(AOwner); end; destructor TUniDBLookupComboBoxObject.Destroy; begin if Assigned(Self.FSearch) then Self.FSearch.Free; if Assigned(Self.FListValues) then Self.FListValues.Free; if Assigned(Self.FCriteriaListSource) then Self.FCriteriaListSource.Free; inherited Destroy; end; procedure TUniDBLookupComboBoxObject.DoSetRemoteValue(AIndex: Integer; Value: string); begin inherited; if (VarIsNull(Self.KeyValue)) and (Assigned(Self.FDataSet)) then Self.FDataSet.EntityFieldByName(String(Self.DataField)).AsObject := nil; end; procedure TUniDBLookupComboBoxObject.ExecuteSearch; begin with TuniFormSearch.Create(UniApplication) do begin try ConfigureSearch(Self.FSearch); ShowModal; if ModalResult = mrOk then begin if Assigned(Selected) then begin Self.FListSource.Close; Self.FListSource.SetSourceObject(Selected); Self.FListSource.Open; if Assigned(Self.FDataSet) then Self.FDataSet.EntityFieldByName(String(Self.DataField)).AsObject := Selected; if Assigned(Self.OnSelect) then Self.OnSelect(Self); end; end; finally Free; end; Self.SetFocus; end; end; procedure TUniDBLookupComboBoxObject.LoadCompleted; begin if Self.Required then Self.ClientEvents.UniEvents.Values['beforeInit'] := 'function beforeInit(sender, config){Ext.apply(sender,{allowBlank:false,msgTarget : ''side''});}'; if Self.Triggers.Count = 0 then begin with Self.Triggers.Add do begin IconCls := 'x-form-search-trigger'; HandleClicks := True; Visible := True; end; end else begin Self.Triggers[0].IconCls := 'x-form-search-trigger'; Self.Triggers[0].HandleClicks := True; Self.Triggers[0].Visible := True; end; Self.FOldUniTriggerEvent := Self.OnTriggerEvent; OnTriggerEvent := Self.MyTriggerEvent; if Self.RemoteQuery then begin FListValues := TStringList.Create; Self.OnRemoteQuery := Self._RemoteQuery; Self.OnGetKeyValue := Self._GetKeyValue; end; inherited; end; procedure TUniDBLookupComboBoxObject.MyTriggerEvent(Sender: TUniCustomComboBox; AButtonId: Integer); begin if AButtonId = 0 then Self.ExecuteSearch; if Assigned(Self.FOldUniTriggerEvent) then Self.FOldUniTriggerEvent(Sender, AButtonId); end; procedure TUniDBLookupComboBoxObject._GetKeyValue(const Value: string; var KeyValue: Variant); var lObj: TObject; lIndex : Integer; begin KeyValue := Null; lObj := nil; if not Value.IsEmpty and not Self.FListSource.IsEmpty then begin if FListValues.Count = 0 then lObj := Self.FListSource.InternalList.Item(0) else begin lIndex := FListValues.IndexOf(Value); if lIndex <> -1 then lObj := Self.FListSource.InternalList.Item(lIndex); end; if Assigned(lObj) then KeyValue := Integer(lObj); end; end; procedure TUniDBLookupComboBoxObject._RemoteQuery(const QueryString: string; Result: TStrings); var lListFields: TStringList; i: Integer; lCriterion: TLinqExpression; lCustomCriteria: TCriteria; lStrListValue: String; begin if (Self.FCriteriaListSource <> nil) and (Trim(Self.Text) <> Trim(QueryString)) then begin lListFields := nil; try lListFields := TStringList.Create; lListFields.Text := Self.ListField.Replace(';', sLineBreak); lCustomCriteria := Self.FCriteriaListSource.Clone; lCriterion := Linq[lListFields[0]].Upper.Like(UpperCase(VarToStr(QueryString)) + '%'); lListFields.Delete(0); for i := 0 to lListFields.Count - 1 do if Self.FListSource.FieldByName(lListFields).Tag = 0 then lCriterion := lCriterion or (Linq[lListFields].Upper.Like('%' + UpperCase(VarToStr(QueryString)) + '%')); lCustomCriteria.Where(lCriterion); Self.FListSource.Close; Self.FListSource.SetSourceCriteria(lCustomCriteria, 25); Self.FListSource.Open; lListFields.Text := Self.ListField.Replace(';', sLineBreak); Self.FListValues.Clear; while not Self.FListSource.Eof do begin lStrListValue := EmptyStr; for i := 0 to lListFields.Count - 1 do begin if i = 0 then begin if Self.FListSource.FieldByName(lListFields).AsString <> '' then lStrListValue := Self.FListSource.FieldByName(lListFields).AsString end else begin if Self.FListSource.FieldByName(lListFields).AsString <> '' then lStrListValue := lStrListValue + ' - ' + Self.FListSource.FieldByName(lListFields).AsString; end; end; if not lStrListValue.IsEmpty then begin Result.Add(lStrListValue); Self.FListValues.Add(lStrListValue); end; Self.FListSource.Next; end; finally lListFields.Free; lCriterion := nil; end; end; end; procedure TUniDBLookupComboBoxObject.SetSearch(Search: TSearch); var lObject: TObject; begin Self.FSearch := Search; Self.FListSource := TAureliusDataset(Self.ListSource.Dataset); Self.FDataSet := TAureliusDataset(Self.DataSource.Dataset); Self.FCriteriaListSource := Search.Criteria.Clone; lObject := Self.FDataSet.EntityFieldByName(String(Self.DataField)).AsObject; if Assigned(lObject) then begin Self.FListSource.Close; Self.FListSource.SetSourceObject(lObject); Self.FListSource.Open; Self.KeyValue := Integer(lObject); Self.UpdateText; end; end; end. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now