#1 2017-01-22 15:41:15

jbroussia
Member
From: France
Registered: 2011-04-09
Posts: 74

Problem with TSQLTableJSON.step

Hi ab,

While trying to use step through MultiFieldsValues records, I get an exception I can't make my mind around.
For ex. just playing with Sample 04, the following code raises an exception after the Step line...

procedure TForm1.btnTestClick(Sender: TObject);
var
  aSampleRecord: TSQLSampleRecord;
  s: RawUTF8;
begin
  with Database.MultiFieldValues(TSQLSampleRecord, 'Name,Question', 'ID >= ?', [1]) do begin
    try
      while Step(FALSE, @aSampleRecord) do begin
        s := Format('Name: %s; Question: %s', [aSampleRecord.Name, aSampleRecord.Question]);
        QuestionMemo.Lines.Add(s);
      end;
    finally
      Free;
    end;
  end;
end;

-> Project Project04Client.exe raised exception class EVariantBadVarTypeError with message 'Invalid variant type'.

I have no idea what I'm doing wrong, it's just a copy/paste from the documentation :-\
(Delphi 2010)

Offline

#2 2017-01-22 21:47:08

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,242
Website

Re: Problem with TSQLTableJSON.step

aSampleRecord is not a variant...

Offline

#3 2017-01-23 09:10:27

jbroussia
Member
From: France
Registered: 2011-04-09
Posts: 74

Re: Problem with TSQLTableJSON.step

Should not work on Sundays. My mind was so blurry... neutral

Offline

#4 2017-01-23 10:43:36

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,242
Website

Re: Problem with TSQLTableJSON.step

For filling a TSQLSampleRecord instance (which is the recommended way, since using a variant is slower and less safe), consider using TSQLSampleRecord.CreateAndFillPrepare.
As documented.

Offline

#5 2017-01-25 11:23:28

jbroussia
Member
From: France
Registered: 2011-04-09
Posts: 74

Re: Problem with TSQLTableJSON.step

That's what I was using before, and what got me confused when I tried MultiFieldValues: I forgot to change the variable type ! (so ashamed)

Offline

Board footer

Powered by FluxBB