RTC Forums
April 28, 2024, 11:26:53 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: AV with Unsupported Variant Type  (Read 4240 times)
zsleo
RTC Expired
*
Posts: 80


« on: November 20, 2012, 07:49:56 AM »

Delphi XE; MS SQL; RTC SDK v4.49

I have an MS SQL DB with ADO Connector and doing RTC Dataset "select".

At the Delphi level the data type being retrieved is "Variant array of Byte".

In rtcDB.pas I have placed the a "try...except...end" around line "rtcDS.Value[fldname]:=field.Value;" in the procedure "DelphiDataSetToRtc" as a short term fix.

Question: is there a fix for the problem?

TIA

Zane
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #1 on: November 20, 2012, 08:44:28 AM »

Hi Zane.

Can you pin-point where exactly the AV is happening?

If it is reproducible, you should be able to get a Call Stack while running the Client in Delphi debug mode.

Best Regards,
Danijel Tkalcec
Logged
zsleo
RTC Expired
*
Posts: 80


« Reply #2 on: November 20, 2012, 09:28:48 AM »

Danijel

The MS SQL field is " [InitVector] varbinary(100) NULL,"

The AV is server side in rtcDB.pas where I have marked it with "<<====="

Code:
procedure DelphiDataSetToRtc(DelphiDS:TDataSet; rtcDS:TRtcDataSet; ClearFieldDefs:boolean=True);
  var
    fdef:TFieldDef;
    flds:integer;
    fldname:string;
    field:TField;
    fstream:TStream;
  begin
  if ClearFieldDefs then
    begin
    rtcDS.Clear;
    for flds:=0 to DelphiDS.FieldDefs.Count-1 do
      begin
      fdef:=DelphiDS.FieldDefs.Items[flds];
      fldname:=fdef.Name;

      field:=DelphiDS.FindField(fldname);
      if assigned(field) then
        if field.FieldKind=fkData then
          rtcDS.SetField(fldname,
                         RTC_DB2FIELD_TYPE(fdef.DataType),
                         fdef.Size,
                         fdef.Required);
      end;
    end;

  DelphiDS.First;
  while not DelphiDS.EOF do
    begin
    rtcDS.Append;
    for flds:=0 to rtcDS.FieldCount-1 do
      begin
      fldname:=rtcDS.FieldName[flds];
      field:=DelphiDS.FindField(fldname);
      if assigned(field) then
        if (field.FieldKind=fkData) and not field.IsNull then
          if field.isBlob then
            begin
            fstream:=DelphiDS.CreateBlobStream(field,bmRead);
            try
              if {$IFNDEF FPC} TBlobField(field).GraphicHeader and {$ENDIF}
                ( (field.DataType = ftGraphic) or
                  (field.DataType = ftTypedBinary) ) then
                RtcSkipGraphicFieldHeader(fstream);
              rtcDS.NewByteStream(fldname).CopyFrom(fstream,fstream.Size-fstream.Position);
            finally
              fstream.Free;
              end;
            end
          else
          try
            rtcDS.Value[fldname]:=field.Value; <<<=========== HERE @ line 665 in my version
          Except
          end;
      end;
    DelphiDS.Next;
    end;
  end;


Regards

Zane
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #3 on: November 20, 2012, 10:30:30 AM »

Hi Zane,

Are you using Debug DCUs?

The line you are pointing out might be where the AV is getting out, but unless it is a result of a bug in Delphi itself (compiler or the DB.pas unit), it would be raised somewhere inside the "rtcInfo.pas" unit and NOT inside the "rtcDB.pas" unit, because the rtcDS.Value[] assignment is actually a method call into the "rtcInfo.pas" unit, which is receiving the Variant result of the "field.Value" property as a parameter.

Anyway ... there is no automatic conversion from a Variant byte array type to a RTC Value object, so the solution to your problem is to make your own copy of the "DelphiDataSetToRTC" function and write the code needed to make the conversion and assign it to the RTC field by using "asByteArray" (in RTC SDK v6.x), "asByteStream" or some other natively supported type by the RTC SDK. The assignment to the Value[] property is only a short-cut, which works for simple types but not for complex types like byte arrays.

Best Regards,
Danijel Tkalcec
Logged
zsleo
RTC Expired
*
Posts: 80


« Reply #4 on: November 21, 2012, 12:52:24 AM »

Thanks,

I will extend the interface as you suggest to cater from this data type.

Regards

Zane
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.024 seconds with 16 queries.