#1 Re: mORMot 1 » How to get Set variable? » 2011-08-03 08:44:36

One more question, how I can find all rows with some "enum" property if I have "set" field in database?

For example:

TTest = (tOne, tTwo, tThree, tFour, tFive);
TTestSet = Set of TTest;

T_Test = class(TSQLRecord)
private
  ...
  fTestSet: TTestSet;
published
   ...
  property TestSet: TTestSet read fTestSet write fTestSet;
end; 

procedure Smth(aTest: TTest);
var
  lJSON: TSQLTableJSON;
begin
  lJSON := Client.List([T_Test], 'T_Test.ID', 'T_Test.TestSet LIKE "' + aTest + '"'); // what should I write in SQLWhere?
end;

Or I need to delete "wrong" rows after I get lJSON ?

#2 Re: mORMot 1 » How to get Set variable? » 2011-07-28 13:02:12

It's working! I'm so stupid)) Thanks a lot!

#3 Re: mORMot 1 » How to get Set variable? » 2011-07-28 09:49:48

I tried to do like you say before start topic, but there was "Invalid typecast" errors in TSetInvType(lInvInteger) and Integer(lInvType).
Thanks, I think my function is satisfy me.

#4 Re: mORMot 1 » How to get Set variable? » 2011-07-28 07:03:44

Yes, I know. But I think you have a function for "Integer->Set" transformation in framework.
Something like that, but universal

function IntegerToSetInvType(I: Integer): TSetInvType;
var
  Index: Integer;
begin
  Result := [];
  Index := 0;
  while (I <> 0) do
  begin
    if ((Byte(I) and 1) = 1) then
      Result := Result + [TInvType(Index)];
    Inc(Index);
    I := I shr 1;
  end;
end;
var
  lInvType: TSetInvType;
begin
... 
lInvType := IntegerToSetInvType(aJSONTable.GetAsInteger(I, FieldIndex)); 

#5 mORMot 1 » How to get Set variable? » 2011-07-27 15:04:22

jora
Replies: 8

Hello, I have some variable of set type (TSetInv = Set of TInv) in my base, and I can't get this variable from TSQLTableJSON field, can you help me?

Board footer

Powered by FluxBB