david_navigator Posted July 16, 2020 Posted July 16, 2020 I'm experimenting on converting a VCL project to UNIGui. One component that the VCL project frequently uses is a Woll2WollDBComboBox. This component has a strings property, which store a name | value pair as Displayed Value | Stored Value. The stored value is referenced by the database field and the Displayed Value is displayed to the user. e. g If the strings property contains Quote | 0 Confirmed | 1 Delivered | 2 Then the linked database field would be an integer, storing 0,1 or 2 but the control would, for example, display Quote to the user. I can't see any similar UniGUI control, so before I either write one or change the design of the original VCL app, I thought I'd just check that there isn't already a control that works like this (or maybe someone else has thought of a simple workaround ?) Quote
david_navigator Posted July 16, 2020 Author Posted July 16, 2020 20 minutes ago, x11 said: TUniDBLookupComboBox? That seems to use a Table rather than a string list for the lookup, but I guess that's not too difficult to create a table to do the same. Quote
x11 Posted July 16, 2020 Posted July 16, 2020 Excuse me. I did not quite understand what exactly needs to be done. You can use TUniDBLookupComboBox to use without reference to TDataSet. You can fill it yourself comboStateRemote.RemoteQuery := True; comboStateRemote.RemoteQueryRetainingResult := True; ... ... ... procedure TFormMobile1.comboStateRemoteQuery(const QueryString: string; Result: TStrings); begin comboOnRemoteQuery(UniQuery1, 'STATE', QueryString, Result); end; procedure comboOnRemoteQuery(q: TUniQuery; const sTable, QueryString: string; var Result: TStrings); Var n: integer; begin q.Close; q.SQL.Text := 'SELECT ID, NAME FROM ' + sTable + ' WHERE UPPER(NAME) CONTAINING(UPPER(:NAME)) AND DELETED IS DISTINCT FROM 1'; if (QueryString.Length <= 2) and (QueryString <> '*') then exit; if (QueryString = '*') or (QueryString = '[null]') then q.Params[0].AsString := '' else q.Params[0].AsString := QueryString; q.Open; if q.RecordCount = 0 then begin Result.Add(constEmptyRes); exit; end; n := 0; q.First; while not q.Eof do begin Result.Add(q.FieldByName('name').AsString); q.Next; inc(n); if N > 100 then Break; end; end; Get key value procedure TFormMobile1.comboStateGetKeyValue(const Value: string; var KeyValue: Variant); begin if UniQuery1.Active then KeyValue := q.Lookup('name', Value, 'ID'); end; Quote
david_navigator Posted July 16, 2020 Author Posted July 16, 2020 Thanks. That's a big help, but I'm still not quite getting it to work (but getting close). I've set the both of these properties RemoteQuery := True; RemoteQueryRetainingResult := True; and very simply written procedure TDFEqlist.UniDBLookupComboBox2RemoteQuery(const QueryString: string; Result: TStrings); begin Result.add('Quote=0'); Result.add('Confirmed=1'); Result.add('Delivered=2'); end; procedure TDFEqlist.UniDBLookupComboBox2GetKeyValue(const Value: string; var KeyValue: Variant); Var charArray : Array[0..0] of Char; begin charArray[0] := '='; KeyValue := Value.Split(charArray)[1] end; and the record pointed to by the DataField property has a value of 1, but the control doesn't display anything until I click on the dropdown, when it displays Quote=0 Confirmed=1 Delivered=2 Rather than just Quote Confirmed Delivered I've also set the Mode property to umNameValue but that didn't seem to make a difference. Will carry on playing, but if you can see what I've done wrong, I'd appreciate some more help. Thanks David Quote
Wilton Ergon Posted July 16, 2020 Posted July 16, 2020 yes, you will need a query, but you don't necessarily need to have a table in the bank for that. you can simulate a table like this sample qry.sql.text :='SELECT ''QUOTE'' DESCRIPTION,0 ID UNION SELECT ''Confirmed'' DESCRIPTION,1 ID UNION SELECT ''DELIVERED'' DESCRIPTION,2 ID' LINK datasource with tunidbloockupcombobox Quote
david_navigator Posted July 17, 2020 Author Posted July 17, 2020 17 hours ago, wilton_rad said: yes, you will need a query, but you don't necessarily need to have a table in the bank for that. you can simulate a table like this sample qry.sql.text :='SELECT ''QUOTE'' DESCRIPTION,0 ID UNION SELECT ''Confirmed'' DESCRIPTION,1 ID UNION SELECT ''DELIVERED'' DESCRIPTION,2 ID' LINK datasource with tunidbloockupcombobox Thanks. All working now Quote
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.