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;
> 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
> > 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
I rewrote the component taking a simpler approach and it seems to be
working.
Thank-you for your assistance.
Bill