function cBoxCheck(a, b, c, d, e, f, g, h, i, j: Boolean): Integer;
var
x: Integer;
begin
x:= 0;
if a then x:= x + 1;
if b then x:= x + 5;
if c then x:= x + 9;
if d then x:= x + 13;
if e then x:= x + 17;
if f then x:= x + 21;
if g then x:= x + 25;
if h then x:= x + 29;
if i then x:= x + 33;
if j then x:= x + 37;
result:= x;
end;怎么从返回的结果里得知具体是由哪几个数相加得来的,求求大侠帮帮忙。
var
x: Integer;
begin
x:= 0;
if a then x:= x + 1;
if b then x:= x + 5;
if c then x:= x + 9;
if d then x:= x + 13;
if e then x:= x + 17;
if f then x:= x + 21;
if g then x:= x + 25;
if h then x:= x + 29;
if i then x:= x + 33;
if j then x:= x + 37;
result:= x;
end;怎么从返回的结果里得知具体是由哪几个数相加得来的,求求大侠帮帮忙。
b、d为true,其他为false,result = 18
a、e为true,其他为false, result 也 = 18
就楼主的代码来说,结果为10只可能a、c为true,其他false。不过其他的结果未必能逆推出唯一的组合,象7楼举的反例。
function cBoxCheck(a, b, c, d, e, f, g, h, i, j: Boolean): String;
var
x: String;
begin
x:= '';
if a then x:= x + '0';
if b then x:= x + '1';
if c then x:= x + '2';
if d then x:= x + '3';
if e then x:= x + '4';
if f then x:= x + '5';
if g then x:= x + '6';
if h then x:= x + '7';
if i then x:= x + '8';
if j then x:= x + '9';
result:= x;
end;uses StrUtils;
procedure TFrmFind.cBoxSet(x: String; a, b, c, d, e, f, g, h, i, j: TCheckBox);
begin
if AnsiContainsStr(x, '0') then a.Checked:= True;
if AnsiContainsStr(x, '1') then b.Checked:= True;
if AnsiContainsStr(x, '2') then c.Checked:= True;
if AnsiContainsStr(x, '3') then d.Checked:= True;
if AnsiContainsStr(x, '4') then e.Checked:= True;
if AnsiContainsStr(x, '5') then f.Checked:= True;
if AnsiContainsStr(x, '6') then g.Checked:= True;
if AnsiContainsStr(x, '7') then h.Checked:= True;
if AnsiContainsStr(x, '8') then i.Checked:= True;
if AnsiContainsStr(x, '9') then j.Checked:= True;
end;
比如 f为true,其他false,此时x=21,按照cBoxSet推出来的则是b、c为true,其他false,能对吗?:)