BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Control has no parent window" in Form Design Mode but works

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi VCL Components Writing
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Fri Jan 26, 2007 9:13 am    Post subject: Control has no parent window" in Form Design Mode but works Reply with quote



Is TCustomEdit desendant, with aligment, number edit, and custom paint;
and sincerely no longer I can think more forms to try to detect and to
correct the error, heres my code:

{**** TCustomEditEx *****}
constructor TCustomEditEx.Create(AOwner: TComponent);
begin
Inherited Create(AOwner);
FRangeChar := [];
FFixedChar := #0;
FFixedPos := fpLeft;
FHasSign := False;
FDecimals := 0;
FThousands := False;
FNumPadDot := False;
FValidChars := [];
FPorcent := False;
Formating := False;
_FixedChar := False;
FFixedWidth := 0;
SetAlignment(taLeftJustify);
SetRangeChars([rcNumber, rcAlpha, rcSymbol, rcExtended]);
FCanvas := TControlCanvas.Create;
TControlCanvas(FCanvas).Control := Self;
end;

procedure TCustomEditEx.CreateWnd;
var
FixedWidth: LongInt;
begin
ShowMessage('CreateWnd: Begin');
inherited CreateWnd; <-- Here is the error
WriteLog('CreateWnd: Code');
if FFixedPos = fpLeft then
FixedWidth := MakeLong(FFixedWidth, 0)
else
FixedWidth := MakeLong(0, FFixedWidth);
Perform(EM_SETMARGINS, EC_LeftMargin or EC_RightMargin, FixedWidth);
ShowMessage('CreateWnd: End');
end;

procedure TCustomEditEx.CreateParams(var params: TCreateParams);
const
Styles : Array [TAlignment] of DWORD = (ES_LEFT, ES_RIGHT, ES_CENTER
);
begin
inherited;
params.style := params.style or Styles[FAlignment];
end;

destructor TCustomEditEx.Destroy;
begin
FCanvas.Free;
inherited Destroy;
end;

The Canvas property is for internal use only:

procedure TCustomEditEx.WMPaint(var M: TMessage);
var
R: TRect;
begin
ShowMessage('WMPaint: Begin');
inherited;
if (FFixedChar <> #0) and not (csCreating in ControlState) then
begin
FCanvas.Lock;
try
FCanvas.Handle := GetDC(Handle);
try
TControlCanvas(FCanvas).UpdateTextFlags;
FCanvas.Font.Assign(Font);
if FFixedChar <> #0 then
begin
R := ClientRect;
if FFixedPos = fpLeft then
R.Right := R.Left + FCanvas.TextWidth(FFixedChar)
else
R.Left := R.Right - FCanvas.TextWidth(FFixedChar);
FCanvas.TextRect(R, R.Left, R.Top + 1, FFixedChar);
end;
finally
FCanvas.Handle := 0;
end;
finally
FCanvas.Unlock;
end;
end;
ShowMessage('WMPaint: End');
end;
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi VCL Components Writing All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.