📄 jvdblookupcomboedit.pas
字号:
procedure TJvDBLookupComboEdit.SetDataSource(Value: TDataSource);
begin
if not (FDataLink.DataSourceFixed and (csLoading in ComponentState)) then
FDataLink.DataSource := Value;
if Value <> nil then
Value.FreeNotification(Self);
end;
function TJvDBLookupComboEdit.GetDataField: string;
begin
Result := FDataLink.FieldName;
end;
procedure TJvDBLookupComboEdit.SetDataField(const Value: string);
begin
if not (csDesigning in ComponentState) then
ResetMaxLength;
FDataLink.FieldName := Value;
end;
function TJvDBLookupComboEdit.GetReadOnly: Boolean;
begin
Result := FDataLink.ReadOnly or inherited GetReadOnly;
end;
procedure TJvDBLookupComboEdit.SetReadOnly(Value: Boolean);
begin
inherited SetReadOnly(Value);
FDataLink.ReadOnly := Value;
end;
function TJvDBLookupComboEdit.GetCanvas: TCanvas;
begin
Result := FCanvas;
end;
function TJvDBLookupComboEdit.GetField: TField;
begin
Result := FDataLink.Field;
end;
procedure TJvDBLookupComboEdit.ActiveChange(Sender: TObject);
begin
ResetMaxLength;
end;
procedure TJvDBLookupComboEdit.DataChange(Sender: TObject);
begin
if FDataLink.Field <> nil then
begin
//if FAlignment <> FDataLink.Field.Alignment then
//begin
// EditText := ''; {forces update}
// FAlignment := FDataLink.Field.Alignment;
//end;
EditMask := FDataLink.Field.EditMask;
if not (csDesigning in ComponentState) then
if (FDataLink.Field.DataType in [ftString, ftWideString]) and (MaxLength = 0) then
MaxLength := FDataLink.Field.Size;
if FFocused and FDataLink.CanModify then
Text := FDataLink.Field.Text
else
begin
EditText := FDataLink.Field.DisplayText;
if FDataLink.Editing then //and FDataLink.FModified || fmodified is private in parent of fdatalink
Modified := True;
end;
end
else
begin
//FAlignment := taLeftJustify;
EditMask := '';
if csDesigning in ComponentState then
EditText := Name
else
EditText := '';
end;
end;
procedure TJvDBLookupComboEdit.EditingChange(Sender: TObject);
begin
//ReadOnly := not FDataLink.Editing;
end;
procedure TJvDBLookupComboEdit.UpdateData(Sender: TObject);
begin
ValidateEdit;
FDataLink.Field.Text := Text;
end;
procedure TJvDBLookupComboEdit.WMUndo(var Msg: TMessage);
begin
FDataLink.Edit;
inherited;
end;
procedure TJvDBLookupComboEdit.WMPaste(var Msg: TMessage);
begin
FDataLink.Edit;
inherited;
end;
procedure TJvDBLookupComboEdit.WMCut(var Msg: TMessage);
begin
FDataLink.Edit;
inherited;
end;
procedure TJvDBLookupComboEdit.DoEnter;
begin
SetFocused(True);
inherited DoEnter;
if SysLocale.FarEast and FDataLink.CanModify then
inherited ReadOnly := False;
end;
procedure TJvDBLookupComboEdit.DoExit;
begin
try
FDataLink.UpdateRecord;
except
SelectAll;
SetFocus;
raise;
end;
SetFocused(False);
CheckCursor;
inherited DoExit;
end;
procedure TJvDBLookupComboEdit.WMPaint(var Msg: TWMPaint);
const
AlignStyle: array [Boolean, TAlignment] of DWORD =
((WS_EX_LEFT, WS_EX_RIGHT, WS_EX_LEFT),
(WS_EX_RIGHT, WS_EX_LEFT, WS_EX_LEFT));
var
Left: Integer;
Margins: TPoint;
R: TRect;
DC: HDC;
PS: TPaintStruct;
S: string;
AAlignment: TAlignment;
ExStyle: DWORD;
begin
if csDestroying in ComponentState then
Exit;
AAlignment := Alignment; //FAlignment;
if UseRightToLeftAlignment then
ChangeBiDiModeAlignment(AAlignment);
if ((AAlignment = taLeftJustify) or FFocused) and
not (csPaintCopy in ControlState) then
begin
if SysLocale.MiddleEast and HandleAllocated and (IsRightToLeft) then
begin { This keeps the right aligned text, right aligned }
ExStyle := DWORD(GetWindowLong(Handle, GWL_EXSTYLE)) and (not WS_EX_RIGHT) and
(not WS_EX_RTLREADING) and (not WS_EX_LEFTSCROLLBAR);
if UseRightToLeftReading then
ExStyle := ExStyle or WS_EX_RTLREADING;
if UseRightToLeftScrollbar then
ExStyle := ExStyle or WS_EX_LEFTSCROLLBAR;
ExStyle := ExStyle or
AlignStyle[UseRightToLeftAlignment, AAlignment];
if DWORD(GetWindowLong(Handle, GWL_EXSTYLE)) <> ExStyle then
SetWindowLong(Handle, GWL_EXSTYLE, ExStyle);
end;
inherited;
Exit;
end;
{ Since edit controls do not handle justification unless multi-line (and
then only poorly) we will draw right and center justify manually unless
the edit has the focus. }
DC := Msg.DC;
if DC = 0 then
DC := BeginPaint(Handle, PS);
FCanvas.Handle := DC;
try
FCanvas.Font := Font;
with FCanvas do
begin
R := ClientRect;
if not (NewStyleControls and Ctl3D) and (BorderStyle = bsSingle) then
begin
Brush.Color := clWindowFrame;
FrameRect(R);
InflateRect(R, -1, -1);
end;
Brush.Color := Color;
if not Enabled then
Font.Color := clGrayText;
if (csPaintCopy in ControlState) and (FDataLink.Field <> nil) then
begin
S := FDataLink.Field.DisplayText;
case CharCase of
ecUpperCase:
S := AnsiUpperCase(S);
ecLowerCase:
S := AnsiLowerCase(S);
end;
end
else
S := EditText;
if PasswordChar <> #0 then
FillChar(S[1], Length(S), PasswordChar);
Margins := GetTextMargins;
case AAlignment of
taLeftJustify:
Left := Margins.X;
taRightJustify:
Left := ClientWidth - TextWidth(S) - Margins.X - 1;
else
Left := (ClientWidth - TextWidth(S)) div 2;
end;
if SysLocale.MiddleEast then
UpdateTextFlags;
TextRect(R, Left, Margins.Y, S);
end;
finally
FCanvas.Handle := 0;
if Msg.DC = 0 then
EndPaint(Handle, PS);
end;
end;
procedure TJvDBLookupComboEdit.CMGetDataLink(var Msg: TMessage);
begin
Msg.Result := Integer(FDataLink);
end;
function TJvDBLookupComboEdit.GetTextMargins: TPoint;
var
DC: HDC;
SaveFont: HFont;
I: Integer;
SysMetrics, Metrics: TTextMetric;
begin
if NewStyleControls then
begin
if BorderStyle = bsNone then
I := 0
else
if Ctl3D then
I := 1
else
I := 2;
Result.X := SendMessage(Handle, EM_GETMARGINS, 0, 0) and $0000FFFF + I;
Result.Y := I;
end
else
begin
if BorderStyle = bsNone then
I := 0
else
begin
DC := GetDC(HWND_DESKTOP);
GetTextMetrics(DC, SysMetrics);
SaveFont := SelectObject(DC, Font.Handle);
GetTextMetrics(DC, Metrics);
SelectObject(DC, SaveFont);
ReleaseDC(HWND_DESKTOP, DC);
I := SysMetrics.tmHeight;
if I > Metrics.tmHeight then
I := Metrics.tmHeight;
I := I div 4;
end;
Result.X := I;
Result.Y := I;
end;
end;
function TJvDBLookupComboEdit.ExecuteAction(Action: TBasicAction): Boolean;
begin
Result := inherited ExecuteAction(Action) or (FDataLink <> nil) and
FDataLink.ExecuteAction(Action);
end;
function TJvDBLookupComboEdit.UpdateAction(Action: TBasicAction): Boolean;
begin
Result := inherited UpdateAction(Action) or (FDataLink <> nil) and
FDataLink.UpdateAction(Action);
end;
{$IFDEF UNITVERSIONING}
initialization
RegisterUnitVersion(HInstance, UnitVersioning);
finalization
UnregisterUnitVersion(HInstance);
{$ENDIF UNITVERSIONING}
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -