Вниз
Скачать: CL | DM;

Объект (и компонент) в компоненте не редактирует Object Inspector   Найти похожие ветки 

 
GrayFace ©   (2004-03-07 11:25) [0]

Если сделать, например, property Button : TButton read FButton write FButton, то она будет изменяться в Design-Time, но не повлияет на RunTime. Если сделать объект, то при нажатии на [+] в Object Inspector"е будет "Cannot Expand". Вот код объекта:
unit RSPicContainer;

interface

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

type
 TRSPicContainer =class(TObject)
 private
   FPicture : TPicture;
   FBitmap  : TBitmap;
   FOld:boolean;
   procedure SetPicture(p:TPicture);
 public
   constructor Create;
   destructor Destroy;
   procedure PictureChanged;
   function Bitmap(w:integer=-1; h:integer=-1):TBitmap;
   function IsEmpty:boolean;
   procedure DrawTo(c:TCanvas);
   procedure ReleaseBitmap;
 published
   property Picture:TPicture read FPicture write SetPicture;
 end;

implementation

constructor TRSPicContainer.Create;
begin
 inherited Create;
 FPicture := TPicture.Create;
 FOld:=true;
end;

destructor TRSPicContainer.Destroy;
begin
 FPicture.Free;
 FBitmap.Free;
 inherited Destroy;
end;

function TRSPicContainer.Bitmap(w:integer=-1; h:integer=-1):TBitmap;
begin
 if w=-1 then w:=FPicture.Width;
 if h=-1 then h:=FPicture.Height;
 if (w<=0) or (h<=0) or (FPicture.Graphic=nil) then exit;
 if not FOld and Assigned(FBitmap) and (FBitmap.Width=w) and (FBitmap.Height=h) then
 begin
   Result:=FBitmap;
   exit;
 end else
 begin
   FBitmap.Free;
   FBitmap:=FBitmap.Create;
   FBitmap.Width:=w;
   FBitmap.Height:=h;
   FBitmap.PixelFormat:=pf24bit;
   FBitmap.HandleType:=bmDIB;
   FBitmap.Canvas.Draw(0,0,FPicture.Graphic);
   FOld:=false;
   Result:=FBitmap;
 end;
end;

procedure TRSPicContainer.DrawTo(c:TCanvas);
begin
 c.Draw(0,0,FPicture.Graphic);
end;

procedure TRSPicContainer.ReleaseBitmap;
begin
 FBitmap:=nil;
end;

procedure TRSPicContainer.SetPicture(p:TPicture);
begin
 if p=FPicture then exit;
 FPicture:=p;
 PictureChanged;
end;

procedure TRSPicContainer.PictureChanged;
begin
 FOld:=true;
end;

function TRSPicContainer.IsEmpty:boolean;
begin
 Result:=(FPicture=nil) or (FPicture.Width<=0) or (FPicture.Height<=0);
end;

end.

ЗЫ: Почему моя прощлая такая же тема была удалена?


 
Юрий Зотов ©   (2004-03-07 13:18) [1]

Давайте начнем с начала.

Вопрос номер один - почему TRSPicContainer унаследован от TObject, а не от TPersistent (скорее всего, именно это напрямую связано с появлением сообщения "Cannot Expand")?

Вопрос номер два - почему метод SetPicture написан так, что приводит к утечке памяти (вместо Assign присваивается ссылка)?

Вопрос номер три (главный) - что Вы вообще хотите получить (желательно, простыми русскими словами)?



Страницы: 1 вся ветка

Скачать: CL | DM;



Память: 0.45 MB
Время: 0.021 c
9-1062415862
Riko
2003-09-01 15:31
2004.03.28
SoundBuffer cannot be made


14-1078051680
ABLE
2004-02-29 13:48
2004.03.28
Синий экран


1-1078771406
DDA
2004-03-08 21:43
2004.03.28
Изображение на изображение с инверсией цвета


3-1077914060
LAndreyL
2004-02-27 23:34
2004.03.28
непонятная база!!!???


7-1073820337
Александр из Минска
2004-01-11 14:25
2004.03.28
Теория по сервисам




   Наверх