Jump to content

Does UniGui have a DB aware lookup combo ?


david_navigator

Recommended Posts

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 ?)

Link to comment
Share on other sites

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;

 

Screenshot_2.jpg

Link to comment
Share on other sites

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
 


 

Link to comment
Share on other sites

 

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

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...