1

I have come across a rather funny issue. I have a form with its Fill set to Gradient.

On Windows, IOS and OSX, the gradient is drawn as it should be. But on Android, the colors are wrong. Any ideas?

object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 480
  ClientWidth = 640
  Fill.Kind = Gradient
  Fill.Gradient.Points = <
    item
      Color = xFFFFC600
      Offset = 0.000000000000000000
    end
    item
      Color = xFFFFF100
      Offset = 1.000000000000000000
    end>
  Fill.Gradient.StartPosition.Y = 0.500000000000000000
  Fill.Gradient.StopPosition.X = 1.000000000000000000
  Fill.Gradient.StopPosition.Y = 0.500000000000000000
  FormFactor.Width = 320
  FormFactor.Height = 480
  FormFactor.Devices = [Desktop]
  DesignerMasterStyle = 0
  object Button1: TButton
    Position.X = 8.000000000000000000
    Position.Y = 8.000000000000000000
    TabOrder = 0
    Text = 'Button1'
  end
end

Windows: Windows Screenshot

OSX: OSX Screenshot

IOS: IOS Screenshot

Android: Android Screenshot

iMan Biglari
  • 4,674
  • 1
  • 38
  • 83

1 Answers1

1

You are using Delphi, right? Because, I have never seen that syntax used in a Pascal based language, nor was I able to get your code running under Delphi 10 Seattle. Was it created by a code-generator?

I have, however, written up the gradient you were trying to get using Delphi 10 Seattle and Firemonkey. It works and looks the same on every device, even on Android:

procedure TForm1.FormPaint(Sender: TObject; Canvas: TCanvas;
  const ARect: TRectF);
var
  locGradient: TGradient;

begin
  with Canvas do begin
    BeginScene;

    // Create and initialize the gradient object
    locGradient := TGradient.Create;
    with locGradient do begin
      Color   := $FFFFC600;
      Color1  := $FFFFF100;

      StartPosition .Y  := 0.5;

      StopPosition  .X  := 1;
      StopPosition  .Y  := 0.5;
    end;

    // Assign the created gradient object to the fill property of the canvas
    with Fill do begin
      Kind      := TBrushKind.Gradient;
      Gradient  := locGradient;
    end;

    // Create a rectangle which represents the gradient
    FillRect( ARect,  0, 0, AllCorners, 1.0 );

    EndScene;
  end;

  FreeAndNIL( locGradient );
end;

This doesn't necessarily answer your question as to why your colour values are messed up on Android only using your code, but then again, your code doesn't seem to follow the common Delphi syntax convention.

  • That's the source code of my form. You shouldn't have to write one line of code... Just open your form file and replace it with what I have provided – iMan Biglari Mar 03 '16 at 12:52
  • Ah, I see. That's very enlightening! I've got your code running the way you explained, under Delphi 10 Seattle and Delphi XE8. It works just fine on my end - the colours are displayed correctly on my Android device. I am using a **Motorola G 2nd Generation** running **Android 5.0.2**. My Delphi XE 8 Android SDK is configured to use the **Android SDK 24.0.2 32 bit**. What Android and Android SDK version are you using? –  Mar 03 '16 at 15:44
  • @Renpai. You seriously have never looked at .dfm code before!? How long have you been programming in Delphi? – Freddie Bell Mar 15 '16 at 09:41