Ok, despite it being Friday I'll have another go... :)
My guess is that your TNewPanel when you use it isn't on a form, and
thus the "control has no parent window" message when you call AddText.
So try setting Parent first.
But if, as Alistair suggested, your TNewPanel is a TCustomControl, you
can just override the paint method. In that case your code might be
something like:
TNewPanel = class(TCustomControl)
protected
procedure Paint; override;
end;
procedure TNewPanel.Paint;
var LRect: TRect;
begin
inherited Paint;
LRect := Rect(0, 0, Width, Height);
DrawText(Canvas.Handle, PChar(Caption), Length(Caption), LRect, 0);
end;
and you would use it like this:
with TNewPanel.Create(Self) do begin
Width := 100;
Height := 100;
Caption := 'blah';
Parent := Self;
end;
Is that what you wanted, or have I made a fool of myself again? :)
Cheers,
Carl Reynolds Ph: +64-9-4154790
CJN Technologies Ltd. Fax: +64-9-4154791
[EMAIL PROTECTED] DDI: +64-9-4154795
PO Box 302-278, North Harbour, Auckland, New Zealand
12 Piermark Drive, North Harbour Estate, Auckland, NZ
Visit our website at http://www.cjntech.co.nz/
> -----Original Message-----
> From: Jeremy Coulter [SMTP:[EMAIL PROTECTED]]
> Sent: Friday, August 27, 1999 3:04 PM
> To: Multiple recipients of list delphi
> Subject: RE: [DUG]: Control Has No Window...agh
>
> Ok, NOW I am confused !!
>
> I have my TWinControl decendant, and I want to draw some text on it as
> a
> spec. point.
> BUT I have the following code, BUT it still tells me the "control ''
> has no
> parent window"
>
> What have I done wrong....?
>
> procedure TNewPanel.AddText(fCaption:string);
> var
> fRect:TRect;
> fdc:HDC;
> begin
> fdc:=getdc(self.canvas.Handle);
> fRect:= rect(10,10,100,100);
> DrawText(fdc, PChar(fCaption), -1, fRect, 1);
> releasedc(self.canvas.Handle,fDc);
> end;
>
> > -----Original Message-----
> > From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]]On
> > Behalf Of Carl Reynolds
> > Sent: Friday, August 27, 1999 14:52
> > To: Multiple recipients of list delphi
> > Subject: RE: [DUG]: Control Has No Window...agh
> >
> >
> > Actually, if JeremyWin has a canvas, this will do:
> >
> > DrawText(JeremyWin.canvas.handle,........
> >
> > But it was still a better suggestion than what I suggested:
> >
> > >Er, the Handle property of TWinControl. :)
> >
> > Bollocks, it must be a Friday...
> >
> > Carl Reynolds Ph: +64-9-4154790
> > CJN Technologies Ltd. Fax: +64-9-4154791
> > [EMAIL PROTECTED] DDI: +64-9-4154795
> > PO Box 302-278, North Harbour, Auckland, New Zealand
> > 12 Piermark Drive, North Harbour Estate, Auckland, NZ
> > Visit our website at http://www.cjntech.co.nz/
> >
> > > -----Original Message-----
> > > From: Alistair George [SMTP:[EMAIL PROTECTED]]
> > > Sent: Friday, August 27, 1999 2:27 PM
> > > To: Multiple recipients of list delphi
> > > Subject: RE: [DUG]: Control Has No Window...agh
> > >
> > > > I have created a control based on a TWinControl.
> > > > I want to use DrawText procedure, BUT I need a handle.
> > > Doesnt:
> > > var hdc:integer;
> > > begin
> > > hDC := GetDC(JeremyWin.canvas.handle);
> > > DrawText(hDC,........
> > >
> ----------------------------------------------------------------------
> > > -----
> > > New Zealand Delphi Users group - Delphi List -
> > > [EMAIL PROTECTED]
> > > Website: http://www.delphi.org.nz
> >
>
>
> ----------------------------------------------------------------------
> -----
> New Zealand Delphi Users group - Delphi List -
> [EMAIL PROTECTED]
> Website: http://www.delphi.org.nz
application/ms-tnef