Solved

New Component

Posted on 1998-10-30
2
164 Views
Last Modified: 2010-04-06
Hi all

i've a problem with creating a new component:
I want to write a ComboBox that filles in all avaible
fonts automatical. her's what I done:

unit FontComboBox;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TFontComboBox = class(TComboBox)
  private
    { Private declarations }
  protected
    { Protected declarations }
  public
    constructor Create(AOwner: TComponent);override;
    { Public declarations }
  published
    procedure UpdateFonts;
    { Published declarations }
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Eigene', [TFontComboBox]);
end;

constructor TFontComboBox.Create(AOwner: TComponent);
begin
Inherited Create(AOwner);
UpdateFonts;
end;

procedure TFontComboBox.UpdateFonts;
var
Index: integer;
begin
Clear; <-- Error here
For Index:=0 to Screen.Fonts.Count-1 do
    Items.Add(Screen.Fonts[Index]);
end;
end.

But everytime I create my new component in desgin-time
(I mean by dragging it on a form) or manipulating the items-property at runtime, I get the error-mesage:" Control '' has no parent window"

What's wrong?

regards
rene
0
Comment
Question by:rene100
2 Comments
 
LVL 5

Accepted Solution

by:
inter earned 100 total points
Comment Utility
The problem is that the inherited Create cannot create the owner windows before exiting the FontCombos Create to solve the problem

1 - Remove UpdateFonts from your Create Method
2 - add the following to your protected declerations

protected
  procedure CreateWnd;override;

3 - add the following to your unit body

procedure TFontComboBox.CreateWnd;
begin
  inherited CreateWnd;
  UpdateFonts;
end;

regards, igor
0
 
LVL 2

Author Comment

by:rene100
Comment Utility
Ok, it works fine
Thanks a lot!

regards
rene
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
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…

772 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

12 Experts available now in Live!

Get 1:1 Help Now