Solved

Creating Visual Components at run time

Posted on 2000-02-20
6
168 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month5 days, 21 hours left to enroll

626 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