Where is wrong ?

I try to make a component .
I load a bmp to PicFrom . All is OK .
But when I try to delete the bmp from PicFrom I still have TBitmap in PicFrom How can I fix that ?
This is my code . Compile and try that .

unit GNSlide;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TGNSlide = class(TGraphicControl)
  private
    { Private declarations }
    FPicFrom:TPicture;
    FPicTo:TPicture;
    picT:TBitmap;
    procedure PictureFrom(Pic:TPicture);
    procedure PictureTo(Pic:TPicture);
    procedure changePicFrom(Sender : TObject);
    procedure changesize(Sender : TObject);
  protected
    { Protected declarations }
    function CanAutoSize(var NewWidth, NewHeight: Integer): Boolean; override;
  public
    { Public declarations }
    constructor Create(AOwner : TComponent); override;
    destructor Destroy; override;
    procedure Paint; override;
  published
    { Published declarations }
    property PicFrom : TPicture read FPicFrom write PictureFrom;
    property PicTo : TPicture read FPicTo write PictureTo;
    property Autosize ;
  end;

procedure Register;

implementation

constructor TGNSlide.Create(AOwner : TComponent);
begin
  inherited Create(AOwner);
  FPicFrom := TPicture.Create;
  FPicTo := TPicture.Create;

  Height:=105;
  Width:=105;

  FPicFrom.OnChange := changePicFrom;
  Canvas.OnChanging:= changesize;
end;

function TGNSlide.CanAutoSize(var NewWidth, NewHeight: Integer): Boolean;
begin
  Result := True ;
  if not (csDesigning in ComponentState) or (PicFrom.Width > 0) and
    (PicFrom.Height > 0) then
  begin
    if Align in [alNone, alLeft, alRight] then
      NewWidth := PicFrom.Width;
    if Align in [alNone, alTop, alBottom] then
      NewHeight := PicFrom.Height;
  end;

end;


procedure TGNSlide.Paint;
begin
  Canvas.Draw(0,0,picT);
end;

procedure TGNSlide.PictureFrom(Pic:TPicture);
begin
 FPicFrom.Assign(Pic);
end;

procedure TGNSlide.PictureTo(Pic:TPicture);
begin
 FPicTo.Assign(Pic);
end;

procedure TGNSlide.changePicFrom(Sender : TObject);
begin
 Width:=FPicFrom.Width;
 Height:=FPicFrom.Height;

  picT := TBitmap.Create;
  picT.Canvas.Brush.Color := clBlack;
  picT.Width := Width;
  picT.Height := Height;

 if AutoSize and (PicFrom.Width > 0) and (PicFrom.Height > 0) then
 SetBounds(Left, Top, PicFrom.Width, PicFrom.Height);
 picT.Assign(FPicFrom.Bitmap);

end;

procedure TGNSlide.changesize(Sender:TObject);
begin
 if Width>PicFrom.Width then Width:=PicFrom.Width;
 if Height>PicFrom.Height then Height:=PicFrom.Height;
end;

destructor TGNSlide.Destroy;
begin
  FPicFrom.Free;
  FPicTo.Free;
  picT.Free;
  inherited Destroy;
end;

procedure Register;
begin
  RegisterComponents('Nick', [TGNSlide]);
end;

end.
LVL 9
ginsonicAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PeterLarsenCommented:
I dont see where and how you delete the bmp.
Is it in designtime you have the problem ??
0
ginsonicAuthor Commented:
In design time , yes .
0
ginsonicAuthor Commented:
I select PicFrom from ObjectInspector , delete TBitmap , but when I press enter object inspector return TBitmap and not None .
In this time , the component don't display the initial bitmap ( the bitmap is erased from it , but object inspector report that the bitmap is still there ( in PicFrom ) .
0
PeterLarsenCommented:
Try this :

TGNSlide = class(TGraphicControl)
private
{ Private declarations }
FPicFrom:TPicture;
FPicTo:TPicture;
picT: tpicture; // change to Tpicture

....

procedure TGNSlide.Paint;
begin
 Canvas.Draw(0,0,PicFrom.Graphic); //use graphic
end;

...

procedure TGNSlide.changePicFrom(Sender : TObject);
begin
Width:=FPicFrom.Width;
Height:=FPicFrom.Height;

//Move this to the components constructor - otherwise you //create a new instance every time the picture is changed.
// picT := TPicture.Create;
// picT.Canvas.Brush.Color := clBlack;
// picT.Width := Width;
// picT.Height := Height;

if AutoSize and (PicFrom.Width > 0) and (PicFrom.Height > 0) then
SetBounds(Left, Top, PicFrom.Width, PicFrom.Height);
picT.Assign(FPicFrom);
end;

...

good luck
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ginsonicAuthor Commented:
Thx , man !
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.