Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

create a TFrame at runtime

966 views
Skip to first unread message

Bernhard Egger

unread,
May 24, 2000, 3:00:00 AM5/24/00
to
Hi,

does anybody know how to create and insert frames at runtime ?

I would like to insert a frame in a panel, but I always get the runtime
error 'EInvalidOperation: Element 'MyFrame' has no superior window'
(this error message is translated from German, so it may differ a little
bit)

Setting the frame's visibility to false and set MyFrame.Parent := Panel
after the Create-call doesn't work either.

Any suggestions ?

Regards,
Bernhard


Igor Ivanov

unread,
May 24, 2000, 3:00:00 AM5/24/00
to
>Any suggestions ?
Show the code.

Bernhard Egger

unread,
May 24, 2000, 3:00:00 AM5/24/00
to
Igor Ivanov wrote:
> Show the code.

I thought it would be clear.

...
type
TFMain = class(TForm)
...
Panel : TPanel;
...

...
uses UMyFrame;
...
procedure TFMain.Button1Click(Sender: TObject);
var f: TFrame;
begin
f := TMyFrame.Create(Panel);
f.Parent := Panel;
end;
...

Ok, that's it.
Any ideas why it does not work ?

Regards,
Bernhard

Igor Ivanov

unread,
May 24, 2000, 3:00:00 AM5/24/00
to
>type
> TFMain = class(TForm)
> ...
> Panel : TPanel;

>uses UMyFrame;
>...
>procedure TFMain.Button1Click(Sender: TObject);
>var f: TFrame;
>begin
> f := TMyFrame.Create(Panel);


> f.Parent := Panel;
>end;


>Any ideas why it does not work ?


No. It works for me:

TFrame4 = class(TFrame)
private
{ Private declarations }
public
{ Public declarations }
end;
TForm1 = class(TForm)
Panel1: TPanel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

procedure TForm1.Button1Click(Sender: TObject);
var
f: TFrame4;
begin
f := TFrame4.Create(Panel1);
f.Parent := Panel1;
end;

The error is elsewhere.

Bernhard Egger

unread,
May 24, 2000, 3:00:00 AM5/24/00
to
Ok, I got it.

Place a TListBox on your frame. It still works.
Then edit the Items property and enter some strings. Now
you'll get first an EInvalidOperation exception as described
before and then a EReadError 'Error reading ListBox1.Items.Strings:
element MyFrame has no superior window'

Why does a listbox need a window handle to read its strings ?!?


Regards,
Bernhard

Renate Schaaf

unread,
May 24, 2000, 3:00:00 AM5/24/00
to
In article <392BABBE...@gmx.net>, Bernhard Egger wrote:
> f := TMyFrame.Create(Panel);
> f.Parent := Panel;
>
Try whether this works any better:

f := TMyFrame.Create(self);
f.Parent := Panel;

Frames stream in the child controls on creation from their dfm-file.
VCL streaming assumes owners which are either forms or frames. So a
TPanel as an owner might mess it up.

Renate


Igor Ivanov

unread,
May 24, 2000, 3:00:00 AM5/24/00
to
> TPanel as an owner might mess it up.

I don't think so and BTW I tested the code I posted where I left it exactly
as it was. However, I always set the form as the owner. Besides that, In
Bernhardt's code there's no direct way to reference the frame because f is
local, which also looks strange.

Renate Schaaf

unread,
May 24, 2000, 3:00:00 AM5/24/00
to
Igor,

I trusted that you had tried the code, but you didn't seem to have any
controls on your frame. Anyway, you are right, there's something else
in the code. I just tried it any which way, and couldn't get it to bomb
either.

Renate


Igor Ivanov

unread,
May 24, 2000, 3:00:00 AM5/24/00
to
>Place a TListBox on your frame. It still works.
>Then edit the Items property and enter some strings. Now
>you'll get first an EInvalidOperation exception as described
>before and then a EReadError 'Error reading ListBox1.Items.Strings:
>element MyFrame has no superior window'
>Same thing happens if you place any component with a non-empty TStrings
>property on the frame.

I understand you mean placing TListBox at design time and editing Items at
design time. Well, I tried (I entered 2 strings) and it still works fine. I
suspect that you are withholding from us something else, like in your first
e-mail. In order to save everybody's time, boil down your problem to the
smallest compilable piece of code and then post it. And there's a big chance
that while doing it you will even find the error yourself.

Renate Schaaf

unread,
May 24, 2000, 3:00:00 AM5/24/00
to
In article <392C6219...@gmx.net>, Bernhard Egger wrote:
> Place a TListBox on your frame. It still works.
> Then edit the Items property and enter some strings. Now
> you'll get first an EInvalidOperation exception as described
> before and then a EReadError 'Error reading ListBox1.Items.Strings:
> element MyFrame has no superior window'
>

That's what you said, and that's what I tried. Do you have the updated
version of D5? They might have changed some frames stuff. Your error
must be happening while the frame's dfm file is being read. You could
step into the frame's constructor in the VCL (check debug dcu's under
compiler options) and find out exactly where it happens.

Renate


Bernhard Egger

unread,
May 25, 2000, 3:00:00 AM5/25/00
to
Renate Schaaf wrote:

>I just tried it any which way, and couldn't get it to bomb either.
>
> Renate
>

Try this:


Place a TListBox on your frame. It still works.
Then edit the Items property and enter some strings. Now
you'll get first an EInvalidOperation exception as described
before and then a EReadError 'Error reading ListBox1.Items.Strings:
element MyFrame has no superior window'

Same thing happens if you place any component with a non-empty TStrings
property on the frame.

Bernhard


Mike Orriss (TeamB)

unread,
May 25, 2000, 3:00:00 AM5/25/00
to
In article <392BCDC0...@gmx.net>, Bernhard Egger wrote:
> Why does a listbox need a window handle to read its strings ?!?
>

Because the TListBox is a thin wrapper around the Windows object and the
latter actually holds the strings.


Mike Orriss (TeamB)
(Unless stated otherwise, my replies relate to Delphi 4.03/5.00)
(Unsolicited e-mail replies will most likely be ignored)


Bernhard Egger

unread,
May 26, 2000, 3:00:00 AM5/26/00
to
I started with a new project, created a new frame, placed (at design time) a listbox

with items and...it worked! Then I traced into the code and found that in one case

the compiler eliminated the symbols WndParent and Style in
Classes.WinControl.CreateWnd in line 4: 'if (WndParent...' but not
in my (buggy) case. But I did NOT recompile the VCL, I have only to
directories containing the compiled files: delphi5\lib and
delphi5\lib\debug.
Anyway, after deleting all non-vital files of the project (dsm, dof,
cfg) and all dcu's, it works ! I don't know why, but who cares...

Thanx for you help,
Bernhard

0 new messages