Solved

Creating Visual Components at run time

Posted on 2000-02-20
6
162 Views
Last Modified: 2010-04-04
I am designing a component derived from TPanel, I wont to have an image on it (my own image component).

This is the code so far...

unit ImageContainer;

interface

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

type
  TImageContainer = class(TPanel)
  Procedure SetImage(Value : TImageExtended);
  private
  FImage : TImageExtended;
    { Private declarations }
  protected
    { Protected declarations }
  public
  constructor Create(AOwner: TComponent); override;
    { Public declarations }
  Property Image : TImageExtended Read FImage Write SetImage;
  published

    { Published declarations }
  end;

procedure Register;

implementation


constructor TImageContainer.Create(AOwner: TComponent);
Begin
    Inherited Create(AOwner);
end;

Procedure TImageContainer.SetImage(Value : TImageExtended);
Begin
     FImage := Value;
end;

procedure Register;
begin
  RegisterComponents('My Components', [TImageContainer]);
end;

end.

When I try to put this on a form and execute any methods related to the Image I get a 'Read of address 'FFFFFF' message. The image is obviously not correctly created.
How can I create it?

Want a fast answer thereby High points.
0
Comment
Question by:MrBig
6 Comments
 

Accepted Solution

by:
Aleq earned 200 total points
ID: 2539752
constructor TImageContainer.Create(AOwner: TObject);
begin
  inherited;
  FImage:=TImage.Create(Self);
  FImage.Parent:=Self; // if this makes problems, put it into CreateWND method of this class
end;

destructor TImageContainter.Destroy;
begin
  FImage.Free;
  inherited;
end;

Procedure TImageContainer.SetImage(Value : TImageExtended);
Begin
//     FImage := Value;
  FImage.Assign(Value);
end;

Hope, that's what you're asking for.



0
 
LVL 2

Expert Comment

by:PeterLarsen
ID: 2539761
Hi,

First, i dont know what TImageExtended is...

You need to create a TImage in your constructor - like this :

Type
  TImageExtended = TImage;

FImage : TImageExtended;
...
constructor TImageContainer.Create(AOwner: TComponent);
Begin
 Inherited Create(AOwner);
 FImage:=TImageExtended.create(self);
end;

I also hink you should use Assign :

Procedure TImageContainer.SetImage(Value : TImageExtended);
Begin
 FImage.Assign := Value;
end;

I have not tried this sample, but i think this is how you should write it.

Good luck
Peter
0
 
LVL 2

Expert Comment

by:PeterLarsen
ID: 2539764
Hmm, Sorry Aleq,
You where there first, but i did not see your comment.
Peter :-)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Expert Comment

by:fulvio_brasil
ID: 2539767
Hi MrBig,

Well I tried to compile your code, but you use your own TImageExtended, so I can't help you so much.

Anyway I think that you could use:
constructor TImageContainer.Create(AOwner: TComponent);
Begin
  Inherited Create(AOwner);
  FImage := TImageExtended.Create;
{or, depending you TImageExtended}
  FImage := TImageExtended.Create(AOwner);
end;

and put the line:
  Property Image : TImageExtended Read FImage Write SetImage;

after then published section of the class

0
 
LVL 2

Expert Comment

by:PeterLarsen
ID: 2539777
PeterLarsen changed the proposed answer to a comment
0
 

Author Comment

by:MrBig
ID: 2539796
Hey u all, thanks for the quick answers, you all did a good job at it but Aleq beat you to the points, it's all yours aleq, and thax again!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now