Guest
|
Posted: Fri Jan 26, 2007 9:13 am Post subject: Control has no parent window" in Form Design Mode but works |
|
|
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; |
|