Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2004.03.28;
Скачать: 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 вся ветка

Текущий архив: 2004.03.28;
Скачать: CL | DM;

Наверх




Память: 0.47 MB
Время: 0.041 c
14-1078222247
Goida
2004-03-02 13:10
2004.03.28
А что такое ИМХО???


3-1077529794
Бульбаш
2004-02-23 12:49
2004.03.28
Как погасить курсор в поле?


3-1077631946
T{}r(l-l
2004-02-24 17:12
2004.03.28
Несовместимость типов


6-1073621638
Hooch
2004-01-09 07:13
2004.03.28
Outlook Express


1-1078965622
Chlavik
2004-03-11 03:40
2004.03.28
При Application.Minimize оставляем одно окно в OnTop