Solved

Creating Visual Components at run time

Posted on 2000-02-20
6
161 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

19 Experts available now in Live!

Get 1:1 Help Now