Solved

Creating Visual Components at run time

Posted on 2000-02-20
6
163 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Best Firemonkey component pack 1 101
Delphi - replicating a form 8 72
Printing problem 2 91
Delphi IDE crash without error message ... 7 89
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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

785 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