Topic: combobox.sqlvalue with multiple values without sql query?

Does anyone knows if it is possible to retrieve multiple values for the property "SqlValue" of a combobox like so or do I have to write an SQL query?

Possible or not?  I already know this syntax does not work but I cannot find any documentation about this property:

if Form.Statuslist.sqlValue in ('2', '13') then .... do something

2 (edited by pavlenko.vladimir.v 2023-06-06 21:48:06)

Re: combobox.sqlvalue with multiple values without sql query?

http://myvisualdatabase.com/forum/misc.php?action=pun_attachment&item=9551&download=0...

Post's attachments

Attachment icon 2023-06-07_02-40-30.png 124.13 kb, 54 downloads since 2023-06-06 

Re: combobox.sqlvalue with multiple values without sql query?

That is not exactly what I am looking for, this is data aggregation within a combobox.
I am writing a script to check if a combobox sqlvalue is either X or Y to change its display according to what is found. I know I can write a sql query to get the "sqlvalue in the range I want but I was wondering if the "SqlValue" property could retrieve multiple values or if it is always a unique value.

Re: combobox.sqlvalue with multiple values without sql query?

Hi,
Would using the combobox 'multi-select' option give you what you want?
Derek.

Post's attachments

Attachment icon multichoice combobox.zip 444.22 kb, 162 downloads since 2023-06-07 

5 (edited by tcoton 2023-06-07 16:22:08)

Re: combobox.sqlvalue with multiple values without sql query?

I may express myself wrongly, let me reformulate.

I have a table with ids that are associated to a status.
This status is displayed via a combobox.
According to the status displayed or chosen, a script changes something in the project, like disabling an object or checking automatically a checkbox.
Some other status could lead to the same action.
Instead of writing complex SQL queries that I can write, I want to know if I can associate multiple values to the object property "SqlValue" in the script tab like in the attached example.

In this project, selecting a color changes the panel below it. The last 2 choices should both change to purple, not red but it does not with current script.

procedure Form1_ComboBox1_OnChange (Sender: TObject);
begin
if form1.ComboBox1.sqlValue='2' then
form1.Panel1.Color:= clGreen;
if form1.ComboBox1.sqlValue='3' then
form1.Panel1.Color:= clTeal;

// I would like to combine both sqlvalue = so it would be like a sqlExecute(select status.id from status where id=4 or id=5) .... or where id in('4','5')

{if form1.ComboBox1.sqlValue='4' then    // same color as below
form1.Panel1.Color:= clRed;
if form1.ComboBox1.sqlValue='5' then    // same color as above
form1.Panel1.Color:= clRed; }

if form1.ComboBox1.sqlValue='4 or 5' then    // either choice = same color
form1.Panel1.Color:= clPurple;
end;
Post's attachments

Attachment icon object.sqlvalue.multiple.zip 335.93 kb, 126 downloads since 2023-06-07 

Re: combobox.sqlvalue with multiple values without sql query?

Hi,
So, something like this?
Derek.

Post's attachments

Attachment icon tcoton1.zip 336.54 kb, 141 downloads since 2023-06-07 

Re: combobox.sqlvalue with multiple values without sql query?

That's it, thanks Derek.

So, the object.SqlValue property can only accept a unique value but it is good to see that we can place a "or" in between them one way or another! smile


if (form1.combobox1.sqlvalue = '4') or (form1.combobox1.sqlvalue = '5') then form1.panel1.color := clpurple;

Re: combobox.sqlvalue with multiple values without sql query?

procedure Form1_ComboBox1_OnChange (Sender: TObject);
var
arr: array[0..2] of string = ['1','3','5'];
i: integer;
begin
  for i := 0 to length(arr) - 1 do
    if form1.ComboBox1.sqlValue = arr[i] then
    begin
    form1.panel1.color := clpurple;
    break;
    end else form1.panel1.color := clBtnFace;
end;

Re: combobox.sqlvalue with multiple values without sql query?

Thanks Sparrow for the geek version of it, it does the same but it takes longer to write than the version from Derek wink

Re: combobox.sqlvalue with multiple values without sql query?

Hi TCoton, Hi Sparrow,
Another option could be to take a more 'data driven' approach and use some sort of 'configuration' table to determine what gets shown / hidden, what color is selected for a panel, what text is shown etc etc depending on the value that is selected from a combobox. 
It's not always suitable (depending on the type of project you are working on) but does mean that nothing is hard-coded and so can offer flexibility.
Maybe it can give you some ideas.
Derek.

Post's attachments

Attachment icon tcoton2.zip 337.15 kb, 149 downloads since 2023-06-07 

Re: combobox.sqlvalue with multiple values without sql query?

Looks like a brilliant idea, I love configuration tables, I already use one. It does not apply to this very case but could prove useful.

Thanks Derek!!