⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scurredit.pas

📁 Alpha Controls 5.40,delphi上的alpha开发源码控件包。没有密码。5.40版的最新版。
💻 PAS
📖 第 1 页 / 共 2 页
字号:
end;

procedure TsCustomNumEdit.Clear;
begin
  Text := '';
end;

procedure TsCustomNumEdit.DataChanged;
var
  EditFormat : string;
begin
  if EditMask = '' then begin
    EditFormat := '0';
    if FDecimalPlaces > 0 then EditFormat := EditFormat + '.' + MakeStr('#', FDecimalPlaces);
    EditText := FormatFloat(EditFormat, FValue);
  end;
end;

function TsCustomNumEdit.CheckValue(NewValue: Extended; RaiseOnError: Boolean): Extended;
begin
  Result := NewValue;
  if (FMaxValue <> FMinValue) then begin
    if (FMaxValue > FMinValue) then begin
      if NewValue < FMinValue
        then Result := FMinValue
        else if NewValue > FMaxValue then Result := FMaxValue;
    end
    else begin
      if FMaxValue = 0 then begin
        if NewValue < FMinValue then Result := FMinValue;
      end
      else if FMinValue = 0 then begin
        if NewValue > FMaxValue then Result := FMaxValue;
      end;
    end;
  end;
end;

procedure TsCustomNumEdit.CheckRange;
begin
  if not (csDesigning in ComponentState) and CheckOnExit then
    CheckValue(StrToFloat(TextToValText(EditText)), True);
end;

procedure TsCustomNumEdit.UpdateData;
var
  s : string;
  Minus : integer;
begin
  s := Text;
  if pos('-', s) = 1 then begin
    Delete(s, 1, 1);
    Minus := -1
  end
  else Minus := 1;
  FValue := CheckValue(StrToFloat(TextToValText('0'+s)), False) * Minus;
  Exit;
  Text := DelChars(Text, #13);
  Text := DelChars(Text, #10);
  FValue := CheckValue(StrToFloat(TextToValText('0'+Text)), False);
end;

function TsCustomNumEdit.GetValue: Extended;
begin
  if not (csDesigning in ComponentState) then
    try
      UpdateData;
    except
      FValue := FMinValue;
    end;
  Result := FValue;
end;

procedure TsCustomNumEdit.SetValue(AValue: Extended);
begin
  FValue := CheckValue(AValue, False);
  DataChanged;
  SkinData.Invalidate;
end;

function TsCustomNumEdit.GetAsInteger: Longint;
begin
  Result := Trunc(Value);
end;

procedure TsCustomNumEdit.SetMinValue(AValue: Extended);
begin
  if FMinValue <> AValue then begin
    FMinValue := AValue;
    Value := FValue;
  end;
end;

procedure TsCustomNumEdit.SetMaxValue(AValue: Extended);
begin
  if FMaxValue <> AValue then begin
    FMaxValue := AValue;
    Value := FValue;
  end;
end;

function TsCustomNumEdit.GetText: string;
begin
  Result := inherited Text;
  Result := DelChars(Result, #13);
  Result := DelChars(Result, #10);
end;

function TsCustomNumEdit.TextToValText(const AValue: string): string;
begin
  Result := DelRSpace(AValue);
  if DecimalSeparator <> ThousandSeparator then Result := DelChars(Result, ThousandSeparator);
  if (DecimalSeparator <> '.') and (ThousandSeparator <> '.') then Result := ReplaceStr(Result, '.', DecimalSeparator);
  if (DecimalSeparator <> ',') and (ThousandSeparator <> ',') then Result := ReplaceStr(Result, ',', DecimalSeparator);
  if Result = '' then Result := '0' else if Result = '-' then Result := '-0';
end;

procedure TsCustomNumEdit.SetText(const AValue: string);
begin
  if not (csReading in ComponentState) then begin
    FValue := CheckValue(StrToFloat(TextToValText(AValue)), False);
    DataChanged;
    SkinData.Invalidate;
  end;
end;

procedure TsCustomNumEdit.ReformatEditText;
var
  S: string;
  IsEmpty: Boolean;
  OldLen, SelStart, SelStop: Integer;
begin
  FFormatting := True;
  try
    S := inherited Text;
    OldLen := Length(S);
    IsEmpty := (OldLen = 0) or (S = '-');
    if HandleAllocated then GetSel(SelStart, SelStop);
    if not IsEmpty then S := TextToValText(S);
    S := FormatFloatStr(S, Pos(',', DisplayFormat) > 0);
    inherited Text := S;
    if HandleAllocated and (GetFocus = Handle) and not (csDesigning in ComponentState) then begin
      Inc(SelStart, Length(S) - OldLen);
      SetCursor(SelStart);
    end;
  finally
    FFormatting := False;
  end;
end;

procedure TsCustomNumEdit.Change;
begin
  if not FFormatting then begin
    if FFormatOnEditing and FFocused then ReformatEditText;
    inherited Change;
  end;
end;

procedure TsCustomNumEdit.WMPaste(var Message: TMessage);
var
  S: string;
begin
  S := EditText;
  try
    inherited;
    UpdateData;
  except
    EditText := S;
    SelectAll;
    if CanFocus then SetFocus;
    if BeepOnError then MessageBeep(0);
  end;
end;

procedure TsCustomNumEdit.CMEnter(var Message: TCMEnter);
begin
  SetFocused(True);
  if FFormatOnEditing then ReformatEditText;
  inherited;
end;

procedure TsCustomNumEdit.CMExit(var Message: TCMExit);
begin
  try
    CheckRange;
    UpdateData;
  except
    SelectAll;
    if CanFocus then SetFocus;
    raise;
  end;
  SetFocused(False);
  SetCursor(0);
  DoExit;
end;

procedure TsCustomNumEdit.PopupWindowShow;
begin
  if Assigned(FPopupWindow) then Exit;
  FadingForbidden := True;
  FPopupWindow := TsCalcForm.Create(Self);
  TsCalcForm(FPopupWindow).Position := poDefault;
  if TsCalcForm(FPopupWindow).sDragBar1 <> nil then TsCalcForm(FPopupWindow).sDragBar1.Visible := False;

  TsCalcForm(FPopupWindow).Height := TsCalcForm(FPopupWindow).Height - 24;
  TsCalcForm(FPopupWindow).FPrecision := 16;
  TsCalcForm(FPopupWindow).FEditor := Self;
  TsCalcForm(FPopupWindow).SetText(Text); 
  TsCalcForm(FPopupWindow).OnClose := CalcWindowClose;           //KJS
  inherited;
  FadingForbidden := False;
end;

procedure TsCustomNumEdit.CalcWindowClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
  Inherited;
  FPopupWindow := nil;
end;

procedure TsCustomNumEdit.PaintText;
var
  R : TRect;
  s : string;
  al : TAlignment;
begin
  SkinData.FCacheBMP.Canvas.Font.Assign(Font);
  R := Rect(3, 2, Width - 3 - Button.Width, Height - 3);
  if IsActive then al := taLeftJustify else al := Alignment;
  if PasswordChar = #0 then
    WriteTextEx(SkinData.FCacheBMP.Canvas, PChar(DisplayText), True, R, DT_TOP {or DT_SINGLELINE or DT_WORDBREAK} or GetStringFlags(Self, al) or DT_NOPREFIX,
              SkinData, ControlIsActive(SkinData))
  else begin
    SetLength(s, Length(EditText));
    FillChar(s[1], Length(s), PasswordChar);
    WriteTextEx(SkinData.FCacheBMP.Canvas, PChar(s), True, R, DT_TOP or DT_SINGLELINE or DT_WORDBREAK or GetStringFlags(Self, al) or DT_NOPREFIX,
              SkinData, ControlIsActive(SkinData));
  end;
end;

(* v4.50
procedure TsCustomNumEdit.WMPaint(var Message: TWMPaint);
var
  DC, SavedDC : hdc;
  PS : TPaintStruct;
  R : TRect;
begin
  inherited; 
  if not (SkinData.Skinned or Focused) then begin
    BeginPaint(Handle, PS);
    DC := GetWindowDC(Handle);
    SavedDC := SaveDC(DC);
    try
      SkinData.InitCacheBmp;


      FillDC(SkinData.FCacheBmp.Canvas.Handle, Rect(0, 0, Width, Height), ColorToRGB(Color));
      SkinData.FCacheBmp.Canvas.Font.Assign(Font);
      R := Rect(4, 4, Width - 4 - Button.Width, Height - 3);

      WriteText(SkinData.FCacheBMP.Canvas, PChar(DisplayText), True, R, DT_TOP or DT_SINGLELINE or DT_WORDBREAK or GetStringFlags(Self, Alignment));
      BitBlt(DC, 2, 2, Width - 4 - Button.Width, Height - 3, SkinData.FCacheBmp.Canvas.Handle, 2, 2, SRCCOPY);
      {$IFDEF DYNAMICCACHE} FreeAndNil(SkinData.FCacheBmp) {$ENDIF}
    finally
      RestoreDC(DC, SavedDC);
      ReleaseDC(Handle, DC);
      EndPaint(Handle, PS);
    end;
  end;
end;*)

{ TsCalcEdit }

constructor TsCalcEdit.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FDefBmpName := 'BTN_CALC';
  Button.Parent := nil;
  GlyphMode.AssignDefaultBitmap;
  Button.Parent := Self;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -