bdn.borland.com

Article #28366: Unofficial WebSnap Fixes Page 2

Unofficial WebSnap Bug Fixes Page 2

By Corbin Dunn cdunn@nospam.borland.com
Remove the nospam. from my email address when mailing me

In general, applying these fixes require you to rebuild some of the VCL. The easiest way to do this, is to go to Tools | Environment Options and from the Library tab add $(DELPHI)\Source\Internet to your Library Path. Or, you can copy the patches files to your current project directory and do a build all. These will only fix applications that are built without runtime packages.

These fixes are unofficial, are not supported by Borland, and are to be used at your own risk.

Quick Jumps:
The OnValidate events of an Adapter and AdapterField don't get called on a regular adapter when an Action for that Adapter is executed.
Required property of AdapterField not working when the user inputs nothing into the field
Using the TDataSetAdapterImageField with Bitmaps in a database BLOB field will always give an "Invalid bitmap" error when trying to view the image.

Required property of AdapterField not working when the user inputs nothing into the field.

The fix for this problem is to modify the following function in WebAdapt.pas as follows:

function TAdapterUpdateField.ImplCheckValueChange(
  AActionRequest: IActionRequest; AFieldIndex: Integer): Boolean;
var
  FieldValue: IActionFieldValue;
  I: Integer;
  Value: Variant;
begin
  // Test single value
  with GetActionFieldValues(AActionRequest) do
    FieldValue := Values[AFieldIndex];
  if GetValueCount = ConvertValueCount(FieldValue) then
  begin
    Result := False;
    if IsMultiValueField then
      for I := 0 to FieldValue.ValueCount do
      begin
        try
          if ConvertValues(FieldValue, I) <> GetValues(I) then
            Result := True;
        except
          Result := True;
        end;
        if Result then break;
      end
    else
    // Corbin - Add the Required check as a fix.
      Value := GetValue;
      if VarIsEmpty(Value) then
      begin  // I added the "or Required" on the line below
        if (ConvertValue(FieldValue) <> '') or Required then
          Result := True
      end
      else
        try
          if ConvertValue(FieldValue) <> Value then
            Result := True;
        except
          Result := True;
        end;
  end
  else
    Result := False;
end;

The OnValidate events of an Adapter and AdapterField don't get called on a regular adapter when an Action for that Adapter is executed.

The fix for this problem is to modify the following function in WebAdapt.pas as follows:

procedure TCustomAdapterAction.ImplExecuteActionRequest(AActionRequest: IActionRequest;
  AActionResponse: IActionResponse);
var
  S: TStrings;
begin
  // corbin - make sure the adapter updates its records before calling the OnExecute event
  Adapter.UpdateRecords; // Add this line before the rest
  // ....
Or, you can call (YourAdapterName).UpdateRecords as the first thing in your OnExecute event of the AdapterAction.

Using the TDataSetAdapterImageField with Bitmaps in a database BLOB field will always give an "Invalid bitmap" error when trying to view the image.

The fix for this problem is to modify the following function in DBAdaptImg.pas as follows. Goto line 238 (in RenderAdapterImage):

          else if (Bytes[0] = Ord('B')) and   { Do not localize}
                   (Bytes[1] = Ord('M')) then // Windows bitmap  { Do not localize}
          {$IFDEF MSWINDOWS}
          begin // added begin
            ContentStream.Seek(0, soFromBeginning); // Missing in update pack 2 - corbin - go back over the start of the bytes before converting
            ConvertBitmapToJpeg
          end // added end
          {$ENDIF MSWINDOWS}
I missed adding the seek back over BM before converting the bitmap to a jpeg.

Last Modified: 25-FEB-02