📄 jvdbcontrols.pas
字号:
if (FDataLink <> nil) and (FDataLink.Field <> nil) and
(FDataLink.Field is TFloatField) then
Precision := TFloatField(FDataLink.Field).Precision;
if FPopup <> nil then
SetupPopupCalculator(FPopup, Precision, BeepOnError);
end;
procedure TJvDBCalcEdit.PopupDropDown(DisableEdit: Boolean);
begin
{if not ReadOnly then} // checked in FDataLink.Edit via CanModify
if AlwaysShowPopup or FDataLink.Edit then
inherited PopupDropDown(DisableEdit);
end;
function TJvDBCalcEdit.EditCanModify: Boolean;
begin
Result := FDataLink.Edit;
end;
function TJvDBCalcEdit.GetDisplayText: string;
var
E: Extended;
begin
if (csPaintCopy in ControlState) and (FDataLink.Field <> nil) then
begin
if FDataLink.Field.IsNull then
E := 0.0
else
if FDataLink.Field.DataType in [ftSmallint, ftInteger, ftWord] then
E := FDataLink.Field.AsInteger
else
if FDataLink.Field.DataType = ftBoolean then
E := Ord(FDataLink.Field.AsBoolean)
else
if FDataLink.Field is TLargeintField then
E := TLargeintField(FDataLink.Field).AsLargeInt
else
E := FDataLink.Field.AsFloat;
if FDataLink.Field.IsNull then
Result := ''
else
Result := FormatDisplayText(E);
end
else
begin
if FDataLink.Field = nil then
begin
if csDesigning in ComponentState then
Result := Format('(%s)', [Name])
else
Result := '';
end
else
//Polaris Result := inherited GetDisplayText;
if FDataLink.Field.IsNull then
Result := ''
else
Result := inherited GetDisplayText;
//Polaris
end;
end;
procedure TJvDBCalcEdit.Reset;
begin
FDataLink.Reset;
inherited Reset;
end;
procedure TJvDBCalcEdit.Change;
begin
if not Formatting then
FDataLink.Modified;
inherited Change;
end;
procedure TJvDBCalcEdit.SetText(const AValue: string);
begin
if not ReadOnly then
inherited SetText(AValue);
end;
//Polaris
procedure TJvDBCalcEdit.DataChanged;
begin
inherited;
if Assigned(FDataLink) and Assigned(FDataLink.Field) {and DecimalPlaceRound} then
begin
EditText := DisplayText;
try
if EditText <> '' then
if (StrToFloat(TextToValText(EditText)) = 0) and ZeroEmpty then
EditText := '';
except
end;
end;
end;
//Polaris
function TJvDBCalcEdit.GetDataSource: TDataSource;
begin
Result := FDataLink.DataSource;
end;
procedure TJvDBCalcEdit.SetDataSource(Value: TDataSource);
begin
if FDataLink.DataSource <> Value then
begin
if not (FDataLink.DataSourceFixed and (csLoading in ComponentState)) then
FDataLink.DataSource := Value;
if Value <> nil then
Value.FreeNotification(Self);
UpdateFieldParams;
end;
end;
function TJvDBCalcEdit.GetDataField: string;
begin
Result := FDataLink.FieldName;
end;
procedure TJvDBCalcEdit.SetDataField(const Value: string);
begin
if FDataLink.FieldName <> Value then
begin
FDataLink.FieldName := Value;
UpdateFieldParams;
end;
end;
procedure TJvDBCalcEdit.SetDefaultParams(Value: Boolean);
begin
if DefaultParams <> Value then
begin
FDefaultParams := Value;
if FDefaultParams then
UpdateFieldParams;
end;
end;
procedure TJvDBCalcEdit.UpdateFieldParams;
begin
if FDataLink.Field <> nil then
begin
if FDataLink.Field is TNumericField then
begin
if TNumericField(FDataLink.Field).DisplayFormat <> '' then
DisplayFormat := TNumericField(FDataLink.Field).DisplayFormat;
Alignment := TNumericField(FDataLink.Field).Alignment;
end;
if FDataLink.Field is TLargeintField then
begin
MaxValue := TLargeintField(FDataLink.Field).MaxValue;
MinValue := TLargeintField(FDataLink.Field).MinValue;
DecimalPlaces := 0;
if DisplayFormat = '' then
DisplayFormat := ',#';
end
else
if FDataLink.Field is TIntegerField then
begin
MaxValue := TIntegerField(FDataLink.Field).MaxValue;
MinValue := TIntegerField(FDataLink.Field).MinValue;
DecimalPlaces := 0;
if DisplayFormat = '' then
DisplayFormat := ',#';
end
else
if FDataLink.Field is TBCDField then
begin
MaxValue := TBCDField(FDataLink.Field).MaxValue;
MinValue := TBCDField(FDataLink.Field).MinValue;
end
else
if FDataLink.Field is TFloatField then
begin
MaxValue := TFloatField(FDataLink.Field).MaxValue;
MinValue := TFloatField(FDataLink.Field).MinValue;
//Polaris DecimalPlaces := TFloatField(FDataLink.Field).Precision;
DecimalPlaces := Min(DecimalPlaces, TFloatField(FDataLink.Field).Precision);
end
else
if FDataLink.Field is TBooleanField then
begin
MinValue := 0;
MaxValue := 1;
DecimalPlaces := 0;
if DisplayFormat = '' then
DisplayFormat := ',#';
end;
end;
UpdatePopup;
end;
function TJvDBCalcEdit.GetReadOnly: Boolean;
begin
Result := FDataLink.ReadOnly;
end;
procedure TJvDBCalcEdit.SetReadOnly(Value: Boolean);
begin
FDataLink.ReadOnly := Value;
end;
function TJvDBCalcEdit.GetField: TField;
begin
Result := FDataLink.Field;
end;
procedure TJvDBCalcEdit.DataChange(Sender: TObject);
begin
if FDefaultParams then
UpdateFieldParams;
if FDataLink.Field <> nil then
begin
if FDataLink.Field.IsNull then
begin
Self.Value := 0.0;
EditText := '';
end
else
if FDataLink.Field.DataType in [ftSmallint, ftInteger, ftWord] then
Self.AsInteger := FDataLink.Field.AsInteger
else
if FDataLink.Field.DataType = ftBoolean then
Self.AsInteger := Ord(FDataLink.Field.AsBoolean)
else
if FDataLink.Field is TLargeintField then
Self.Value := TLargeintField(FDataLink.Field).AsLargeInt
else
Self.Value := FDataLink.Field.AsFloat;
DataChanged;
end
else
begin
if csDesigning in ComponentState then
begin
Self.Value := 0;
EditText := Format('(%s)', [Name]);
end
else
Self.Value := 0;
end;
end;
procedure TJvDBCalcEdit.EditingChange(Sender: TObject);
begin
inherited ReadOnly := not FDataLink.Editing;
end;
procedure TJvDBCalcEdit.UpdateFieldData(Sender: TObject);
begin
inherited UpdateData;
//Polaris if (Value = 0) and ZeroEmpty then FDataLink.Field.Clear
if (Trim(Text) = '') and FEmptyIsNull then
FDataLink.Field.Clear
//if (Value = 0) and ZeroEmpty then
// FDataLink.Field.Clear
else
if FDataLink.Field.DataType in [ftSmallint, ftInteger, ftWord] then
FDataLink.Field.AsInteger := Self.AsInteger
else
if FDataLink.Field.DataType = ftBoolean then
FDataLink.Field.AsBoolean := Boolean(Self.AsInteger)
else
FDataLink.Field.AsFloat := Self.Value;
end;
procedure TJvDBCalcEdit.CMGetDataLink(var Msg: TMessage);
begin
Msg.Result := Integer(FDataLink);
end;
procedure TJvDBCalcEdit.AcceptValue(const Value: Variant);
begin
if VarIsNull(Value) or VarIsEmpty(Value) then
FDataLink.Field.Clear
else
FDataLink.Field.Value := CheckValue(Value, False);
DoChange;
end;
procedure TJvDBCalcEdit.WMPaste(var Msg: TMessage);
begin
FDataLink.Edit;
inherited;
end;
procedure TJvDBCalcEdit.WMCut(var Msg: TMessage);
begin
FDataLink.Edit;
inherited;
end;
// Polaris
procedure TJvDBCalcEdit.DoExit;
begin
if Modified then
try
CheckRange;
FDataLink.UpdateRecord;
except
SelectAll;
if CanFocus then
SetFocus;
raise;
end;
inherited DoExit;
end;
function TJvDBCalcEdit.UseRightToLeftAlignment: Boolean;
begin
Result := DBUseRightToLeftAlignment(Self, Field);
end;
function TJvDBCalcEdit.ExecuteAction(Action: TBasicAction): Boolean;
begin
Result := inherited ExecuteAction(Action) or (FDataLink <> nil) and
FDataLink.ExecuteAction(Action);
end;
function TJvDBCalcEdit.UpdateAction(Action: TBasicAction): Boolean;
begin
Result := inherited UpdateAction(Action) or (FDataLink <> nil) and
FDataLink.UpdateAction(Action);
end;
//=== { TJvStatusDataLink } ==================================================
type
TJvStatusDataLink = class(TDataLink)
private
FLabel: TJvDBStatusLabel;
protected
procedure ActiveChanged; override;
procedure EditingChanged; override;
procedure DataSetChanged; override;
procedure DataSetScrolled(Distance: Integer); override;
procedure LayoutChanged; override;
public
constructor Create(ALabel: TJvDBStatusLabel);
destructor Destroy; override;
end;
constructor TJvStatusDataLink.Create(ALabel: TJvDBStatusLabel);
begin
inherited Create;
FLabel := ALabel;
end;
destructor TJvStatusDataLink.Destroy;
begin
FLabel := nil;
inherited Destroy;
end;
procedure TJvStatusDataLink.ActiveChanged;
begin
DataSetChanged;
end;
procedure TJvStatusDataLink.DataSetScrolled(Distance: Integer);
begin
if (FLabel <> nil) and (FLabel.Style = lsRecordNo) then
FLabel.UpdateStatus;
end;
procedure TJvStatusDataLink.EditingChanged;
begin
if (FLabel <> nil) and (FLabel.Style <> lsRecordSize) then
FLabel.UpdateStatus;
end;
procedure TJvStatusDataLink.DataSetChanged;
begin
if FLabel <> nil then
FLabel.UpdateData;
end;
procedure TJvStatusDataLink.LayoutChanged;
begin
if (FLabel <> nil) and (FLabel.Style <> lsRecordSize) then
DataSetChanged; { ??? }
end;
//=== { TJvDBStatusLabel } ===================================================
const
GlyphSpacing = 2;
GlyphColumns = 7;
constructor TJvDBStatusLabel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ShadowSize := 0;
Layout := tlCenter;
ControlStyle := ControlStyle - [csSetCaption , csReplicatable];
FRecordCount := -1;
FRecordNo := -1;
ShowAccelChar := False;
FDataSetName := '';
FDataLink := TJvStatusDataLink.Create(Self);
FStyle := lsState;
GlyphAlign := glGlyphLeft;
FEditColor := clRed;
FCaptions := TStringList.Create;
FCaptions.OnChange := CaptionsChanged;
FGlyph := TBitmap.Create;
FGlyph.Handle := LoadBitmap(HInstance, 'JvDBStatusLabelSTATES');
Caption := '';
end;
destructor TJvDBStatusLabel.Destroy;
begin
FreeAndNil(FDataLink);
//DisposeStr(FDataSetName);
FCaptions.OnChange := nil;
FreeAndNil(FCaptions);
FreeAndNil(FCell);
FreeAndNil(FGlyph);
inherited Destroy;
end;
procedure TJvDBStatusLabel.Loaded;
begin
inherited Loaded;
UpdateData;
end;
function TJvDBStatusLabel.GetDefaultFontColor: TColor;
begin
if (FStyle = lsState) and (FDataLink <> nil) and
(GetDatasetState in [dsEdit, dsInsert]) then
Result := FEditColor
else
Result := inherited GetDefaultFontColor;
end;
function TJvDBStatusLabel.GetLabelCaption: string;
begin
if (csDesigning in ComponentState) and ((FStyle = lsState) or
(FDataLink = nil) or not FDataLink.Active) then
Result := Format('(%s)', [Name])
else
if (FDataLink = nil) or (DataSource = nil) then
Result := ''
else
begin
case FStyle of
lsState:
if FShowOptions in [doCaption, doBoth] then
begin
if DataSetName = '' then
Result := GetCaption(DataSource.State)
else
Result := Format('%s: %s', [DataSetName, GetCaption(DataSource.State)]);
end
else { doGlyph }
Result := '';
lsRecordNo:
if FDataLink.Active then
begin
if FRecordNo >= 0 then
begin
if FRecordCount >= 0 then
Result := Format('%d:%d', [FRecordNo, FRecordCount])
else
Result := IntToStr(FRecordNo);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -