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

Control '' has no parent window

210 views
Skip to first unread message

Bill Miller

unread,
Aug 3, 2008, 2:52:36 PM8/3/08
to
Please see the method below. If Format = cvRTF then I get an AV Control ''
has no parent window but
if I use Text := Clipboard.AsText instead everything is fine. Any idea why
or any suggestions? I just need to be able to paste the clipboard to the
TRichEdit.

procedure TClipViewer.CreatePaintControl;
var
Icon: TIcon;
Format: TClipboardViewFormat;
Instance: TComponent;
begin
if csDesigning in ComponentState then
Exit;
if FSynPasSyn <> nil then
FSynPasSyn.Free;
FSynPasSyn := nil;
if FPaintControl <> nil then
FPaintControl.Free;
FPaintControl := nil;
if IsEmptyClipboard then
Exit;
Format := GetDrawFormat;
if not ValidFormat( Format ) then
Format := cvUnknown;
case Format of
cvText, cvOemText, cvUnknown, cvDefault, cvEmpty:
begin
FPaintControl := TSynEdit.Create( Self );
FSynPasSyn := TSynPasSyn.Create( Self );
with TSynEdit( FPaintControl ) do
begin
BorderStyle := bsNone;
Parent := Self;
Left := 0;
Top := 0;
ScrollBars := ssBoth;
Align := alClient;
Highlighter := FSynPasSyn;
if Format = cvOemText then
begin
ParentFont := False;
Font.Name := 'Courier New';
end;
Visible := True;
if Clipboard.HasFormat( CF_TEXT ) then
PasteFromClipboard
else if ( Format = cvText ) and Clipboard.HasFormat(
CF_COMPONENT ) then
begin
Instance := Clipboard.GetComponent( Self, Self );
try
ComponentToStrings( Instance, Lines );
finally
Instance.Free;
end;
end
else if IsEmptyClipboard then
Text := RsClipboardEmpty
else
Text := RsClipboardUnknown;
ReadOnly := True;
end;
end;
cvRTF:
begin
FPaintControl := TRichEdit.Create( Self ); // Display RTF
with TRichEdit( FPaintControl ) do
begin
BorderStyle := bsNone;
Parent := Self;
Left := 0;
Top := 0;
ScrollBars := ssBoth;
Align := alClient;
Visible := True;
if Clipboard.HasFormat( CF_RTF ) then
// Text := Clipboard.AsText;
PasteFromClipboard;
end;
end;
cvHTML:
begin
FPaintControl := THTMLViewer.Create( Self ); // Display HTML
with THTMLViewer( FPaintControl ) do
begin
Parent := Self;
Left := 0;
Top := 0;
ScrollBars := ssBoth;
Align := alClient;
if Format = cvOemText then
begin
ParentFont := False;
end;
Visible := True;
end;
end;
cvPicture, cvMetafile, cvBitmap, cvIcon:
begin
FPaintControl := TImage.Create( Self );
with TImage( FPaintControl ) do
begin
Parent := Self;
AutoSize := True;
Left := 0;
Top := 0;
Visible := True;
if Format = cvIcon then
begin
if Clipboard.HasFormat( CF_ICON ) then
begin
Icon := CreateIconFromClipboard;
try
Picture.Icon := Icon;
finally
Icon.Free;
end;
end;
end
else if ( ( Format = cvBitmap ) and Clipboard.HasFormat(
CF_BITMAP ) ) or
( ( Format = cvMetafile ) and ( Clipboard.HasFormat(
CF_METAFILEPICT ) ) or
Clipboard.HasFormat( CF_ENHMETAFILE ) ) or
( ( Format = cvPicture ) and Clipboard.HasFormat( CF_PICTURE ) )
then
Picture.Assign( Clipboard );
end;
end;
cvComponent:
begin
Instance := Clipboard.GetComponent( Self, Self );
FPaintControl := Instance;
if FPaintControl is TControl then
begin
with TControl( FPaintControl ) do
begin
Left := 1;
Top := 1;
Parent := Self;
end;
CenterControl( TControl( FPaintControl ) );
end
else
begin
FPaintControl := TSynEdit.Create( Self );
try
with TSynEdit( FPaintControl ) do
begin
BorderStyle := bsNone;
Parent := Self;
Left := 0;
Top := 0;
ScrollBars := ssBoth;
Align := alClient;
ReadOnly := True;
ComponentToStrings( Instance, Lines );
Visible := True;
end;
finally
Instance.Free;
end;
end;
end;
end;
end;

Pieter Zijlstra

unread,
Aug 3, 2008, 6:53:37 PM8/3/08
to
Bill Miller wrote:

> Please see the method below. If Format = cvRTF then I get an AV
> Control '' has no parent window but if I use Text := Clipboard.AsText
> instead everything is fine. Any idea why or any suggestions? I just
> need to be able to paste the clipboard to the TRichEdit.
>
> procedure TClipViewer.CreatePaintControl;

Does the TClipViewer have a valid Parent? And what about where
TClipViewer is placed on, does that already have a valid Parent?

TRichEdit really needs a valid window handle to a parent form, the
others don't.

--
Pieter

Bill Miller

unread,
Aug 4, 2008, 9:48:34 AM8/4/08
to
When I create the controls I set each Parent to Self... so all the controls
parents should be set including the TRichEdit , but apparently they are not
set.

Bill

Pieter Zijlstra

unread,
Aug 4, 2008, 2:59:49 PM8/4/08
to
Bill Miller wrote:

> > Does the TClipViewer have a valid Parent? And what about where
> > TClipViewer is placed on, does that already have a valid Parent?
> >
> > TRichEdit really needs a valid window handle to a parent form, the
> > others don't.
>

> When I create the controls I set each Parent to Self... so all the
> controls parents should be set including the TRichEdit , but
> apparently they are not set.

I assume you have a form where this TClipViewer is sitting on?

How and when is everything created (TForm, TClipViewer)?

--
Pieter

Bill Miller

unread,
Aug 4, 2008, 5:47:01 PM8/4/08
to
Hi Peter,

I rewrote the component taking a simpler approach and it seems to be
working.
Thank-you for your assistance.

Bill

0 new messages