Changeset 268


Ignore:
Timestamp:
Jun 26, 2020, 11:16:48 AM (4 years ago)
Author:
chronos
Message:
  • Fixed: Memory leaks.
  • Fixed: TMenuItem freeing error on application termination.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/highdpi/Packages/DpiControls/UDpiControls.pas

    r267 r268  
    565565  public
    566566    NativeEdit: TEdit;
     567    destructor Destroy; override;
    567568    property SelLength: Integer read GetSelLength write SetSelLength;
    568569    property SelStart: Integer read GetSelStart write SetSelStart;
     
    11591160end;
    11601161
     1162destructor TDpiEdit.Destroy;
     1163begin
     1164  FreeAndNil(NativeEdit);
     1165  inherited;
     1166end;
     1167
    11611168function TDpiEdit.GetSelLength: Integer;
    11621169begin
     
    14001407destructor TDpiMenuItem.Destroy;
    14011408begin
    1402   FreeAndNil(NativeMenuItem);
    14031409  FreeAndNil(FItems);
    1404   inherited Destroy;
     1410  // TODO: Release menu items
     1411  //FreeAndNil(NativeMenuItem);
     1412  inherited;
    14051413end;
    14061414
     
    14541462begin
    14551463  if Assigned(NativePopupMenu) then FreeAndNil(NativePopupMenu);
    1456   inherited Destroy;
     1464  inherited;
    14571465end;
    14581466
     
    19922000begin
    19932001  Bitmap := NativeGraphicClass.Create;
    1994   Bitmap.LoadFromFile(FileName);
    1995   Width := Bitmap.Width;
    1996   Height := Bitmap.Height;
    1997   if Self is TDpiBitmap then begin
    1998     StretchDrawBitmap(TRasterImage(Bitmap), TBitmap(GetNativeGraphic));
    1999     //TBitmap(GetNativeGraphic).Canvas.StretchDraw(Bounds(0, 0,
    2000     //TBitmap(GetNativeGraphic).Width, TBitmap(GetNativeGraphic).Height), Bitmap);
    2001   end else raise Exception.Create('Unsupported class ' + Self.ClassName);
    2002   FreeAndNil(Bitmap);
     2002  try
     2003    Bitmap.LoadFromFile(FileName);
     2004    Width := Bitmap.Width;
     2005    Height := Bitmap.Height;
     2006    if Self is TDpiBitmap then begin
     2007      StretchDrawBitmap(TRasterImage(Bitmap), TBitmap(GetNativeGraphic));
     2008      //TBitmap(GetNativeGraphic).Canvas.StretchDraw(Bounds(0, 0,
     2009      //TBitmap(GetNativeGraphic).Width, TBitmap(GetNativeGraphic).Height), Bitmap);
     2010    end else raise Exception.Create('Unsupported class ' + Self.ClassName);
     2011  finally
     2012    FreeAndNil(Bitmap);
     2013  end;
    20032014end;
    20042015
     
    20082019begin
    20092020  Bitmap := NativeGraphicClass.Create;
    2010   Bitmap.Width := Width;
    2011   Bitmap.Height := Height;
    2012   if Self is TDpiBitmap then begin
    2013     if Bitmap is TRasterImage then
    2014       (Bitmap as TRasterImage).Canvas.StretchDraw(Bounds(0, 0, Bitmap.Width, Bitmap.Height), TBitmap(GetNativeGraphic))
    2015       else raise Exception.Create('Expected TRasterImage but got ' + Bitmap.ClassName);
    2016   end else raise Exception.Create('Unsupported class ' + Self.ClassName);
    2017   Bitmap.SaveToFile(FileName);
    2018   FreeAndNil(Bitmap);
     2021  try
     2022    Bitmap.Width := Width;
     2023    Bitmap.Height := Height;
     2024    if Self is TDpiBitmap then begin
     2025      if Bitmap is TRasterImage then
     2026        (Bitmap as TRasterImage).Canvas.StretchDraw(Bounds(0, 0, Bitmap.Width, Bitmap.Height), TBitmap(GetNativeGraphic))
     2027        else raise Exception.Create('Expected TRasterImage but got ' + Bitmap.ClassName);
     2028    end else raise Exception.Create('Unsupported class ' + Self.ClassName);
     2029    Bitmap.SaveToFile(FileName);
     2030  finally
     2031    FreeAndNil(Bitmap);
     2032  end;
    20192033end;
    20202034
Note: See TracChangeset for help on using the changeset viewer.