DelphiDabbler Code Snippets Database

Snippet Selection

The following snippets from the Code Snippets Database have been requested.

JPEGPixelFormatToPixelFormat

Converts and returns the given TJPEGPixelFormat format value to the equivalent TPixelFormat value.

function JPEGPixelFormatToPixelFormat(APixelFormat: JPEG.TJPEGPixelFormat):
  Graphics.TPixelFormat;
begin
  case APixelFormat of
    JPEG.jf8bit:
      Result := Graphics.pf8bit;
    JPEG.jf24bit:
      Result := Graphics.pf24bit;
  else
    raise SysUtils.Exception.Create('Unexpected TJPEGPixelFormat value');
  end;
end;

SimplifyFraction

Simplifies the fraction with numerator Num and denominator Denom to its lowest terms. If the fraction is already in its lowest terms then Num and Denom are left unchanged.

procedure SimplifyFraction(var Num, Denom: Int64);
var
  CommonFactor: Int64;  // greatest common factor of Num and Denom
begin
  Assert(Denom <> 0);
  CommonFactor := Abs(GCD(Num, Denom));
  Num := Num div CommonFactor;
  Denom := Denom div CommonFactor;
end;

VariantIsObject

Checks if a the variant V contains an object.

function VariantIsObject(const V: Variant): Boolean;
begin
  Result := Variants.VarIsType(V, varDispatch)
    or Variants.VarIsType(V, varUnknown);
end;

View the whole database.

Go to the DelphiDabbler website.