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

📄 jfedit.pas

📁 加强RzEdit功能
💻 PAS
📖 第 1 页 / 共 4 页
字号:
                    finally
                    end;
                  end;
    JFbkDate  : begin
                  FJFDateValue := StrToDateTimeDef(inherited Text, JFErrDateTime, JFFormatSettings);
                end;  
  end;
end;

procedure TJFEdit.CMCtl3DChanged(var Message: TMessage);
begin
  inherited;
  SetEditRect;
end;

procedure TJFEdit.CMEnabledChanged(var Msg: TMessage);
begin
  inherited;
  SetEditRect;
end;

procedure TJFEdit.CMEnter(var Msg: TCMEnter);
begin
  inherited;
  try
  SetEditRect;
  except
  end;

  case FJFEditKind of
    JFbkNumeric : inherited Text := FloatToStr(FJFNumericValue);
  end;

  try
  SelectAll;
  except
  end;

  try
  StartTimer;
  except
  end;
end;

procedure TJFEdit.CMExit(var Msg: TCMExit);
begin
  inherited;
  try
    SetEditRect;
  except
  end;

  try
    case FJFEditKind of
      JFbkNumeric : inherited Text := FloatToStr(FJFNumericValue);
    end;
  except
  end;

  try
    StopTimer;
  except
  end;
end;

procedure TJFEdit.CMFontChanged(var Msg: TMessage);
begin
  inherited;
  SetEditRect;
end;

procedure TJFEdit.CMTextChanged(var Message: TMessage);
begin
  inherited;
end;

constructor TJFEdit.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FJFEdtBtn                 := TJFEdtBtn.Create(nil);
  FJFEdtBtn.Parent          := Self;
  FJFEdtBtn.Width           := 20;
  FJFEdtBtn.Visible         :=False;
  FJFEdtBtn.FButton.OnClick := ButtonClick;
  FJFEdtBtn.Button.Flat     := True;
  ResizeButton;

  FTimer := TJFEditThread.Create(Self);

  FJFSelectResult  := TJFRecList.Create;
  FJFDropDownList  := TJFRecList.Create;

  JFEditKind      := JFbkCustom;
  FJFSearchFields := TEdtSearchFields.Create(Self, TEdtSearchFieldItem);
  FJFDispFields   := TEdtDispFields.Create(Self, TEdtDispFieldItem);
  FJFExecParams   := TEdtExecParams.Create(Self, TEdtExecParamitem);
  FJFFocusMove    := True;
  FJFDecimalDigits:= 0;
  FJFMinNumeric   := 0;
  FJFMaxNumeric   := 0;
  FJFNumericLimit := False;
  FJFInputChars   := '';
  FJFNumericValue := 0;
  FJFDateValue    := Now;
  FJFMsgClear     := True;
  Font.Charset    := GB2312_CHARSET;
  Font.Size       := 11;
  FJFMultiSelect  := False;
  FJFDispFieldName:= '';
  FJFDispSeparator:= '';
  FJFBackSpaceClear := True;
  FJFListRowCount   := 10;
  FJFDDTItemID      := '';
  FJFDDTParentID    := '';
  FJFTimeVisible    := True;
  FJFSecVisible     := True;
  FInputKeys        := '';
  FJFLimitSpace     := True;
  FJFSRFocusMove    := True;
  inherited Text    := '';
  FJFDDNumSelect    := True;
  Clear;
  FrameVisible      := True;
  FJFPacketRecords  := -1;
  FJFEnterToSearch  := False;
  FJFClearDefIndex  := -1;
  FJFSearchUseLocate:= False;
end;

procedure TJFEdit.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams( Params );

  Params.Style := Params.Style or ws_ClipChildren;  // This is needed for ComboEdit functionality

  case FJFAlignment of
    taLeftJustify:
      Params.Style := ( Params.Style or es_Left ) and not es_Multiline;

    taRightJustify:
      Params.Style := ( Params.Style or es_Right ) and not es_Multiline;
  end;
  
end;

procedure TJFEdit.CreateWnd;
begin
  inherited CreateWnd;
  SetEditRect;
  
end;

destructor TJFEdit.Destroy;
begin
  FJFSearchFields.Free;
  FJFDispFields.Free;
  FJFExecParams.Free;

  FJFSelectResult.Free;
  FJFDropDownList.Free;

  FTimer.Terminate;
  inherited Destroy;
end;

function TJFEdit.GetButtonFlat: Boolean;
begin
  Result := FJFEdtBtn.Button.Flat;
end;

function TJFEdit.GetButtonVisible: Boolean;
begin
  Result := FJFEdtBtn.Visible;
end;


function TJFEdit.GetSelText: string;
begin
  Result := inherited GetSelText;
  SetEditRect;
end;

procedure TJFEdit.ResizeButton;
begin
  FJFEdtBtn.Top    := 0;
  FJFEdtBtn.Left   := Width - FJFEdtBtn.Width;
  FJFEdtBtn.Height := Height;
  if Ctl3D then
  begin
    FJFEdtBtn.Left   := FJFEdtBtn.Left - 3;
    FJFEdtBtn.Height := FJFEdtBtn.Height - 3;
  end
  else
  begin
    FJFEdtBtn.Top    := 1;
    FJFEdtBtn.Left   := FJFEdtBtn.Left - 1;
    FJFEdtBtn.Height := FJFEdtBtn.Height - 2;
  end;  

  SetEditRect;
  Invalidate;
end;

procedure TJFEdit.SetButtonFlat(const Value: Boolean);
begin
  if FJFEdtBtn.Button.Flat <> Value then
  begin
    FJFEdtBtn.Button.Flat := Value;
  end;  
end;

procedure TJFEdit.SetButtonVisible(const Value: Boolean);
begin
  if FJFEdtBtn.Visible <> Value then
  begin
    case FJFEditKind of
       JFbkDropDown,
       JFbkDropDownTree,
       JFbkDate,
       JFbkSearch: FJFEdtBtn.Visible := True;
    else
       FJFEdtBtn.Visible := Value;
    end;
    SetEditRect;
  end;  
end;


procedure TJFEdit.SetJFDispFields(const Value: TEdtDispFields);
begin
  JFDispFields.Assign(Value);
end;

procedure TJFEdit.SetEditRect;
begin
  if csDesigning in ComponentState then
    Exit;
     

  if not JFButtonVisible then
  begin
    PostMessage( Handle, em_SetMargins, ec_LeftMargin, 0 );
    PostMessage( Handle, em_SetMargins, ec_RightMargin, 0 );
  end
  else
  begin
    PostMessage( Handle, em_SetMargins, ec_LeftMargin, 0 );
    PostMessage( Handle, em_SetMargins, ec_RightMargin, MakeLong( 0, FJFEdtBtn.Width + 2 ) );
  end;    
end;

procedure TJFEdit.SetJFRemoteServer(const Value: TCustomRemoteServer);
begin
  FJFRemoteServer := Value;
end;

procedure TJFEdit.SetJFAlignment(const Value: TLeftRight);
begin
  if FJFAlignment <> Value then
  begin
    FJFAlignment := Value;
    RecreateWnd;
  end;  

  
end;

procedure TJFEdit.SetJFEditKind(const Value: TJFButtonKind);
begin
  if (FJFEditKind = JFbkDate) and (Value <> JFbkDate) then
    inherited EditMask := '';
    
  FJFEditKind := Value;
  FJFEdtBtn.FButton.Glyph.Assign(GetBtnEdtGlyph(FJFEditKind));
  FJFEdtBtn.FButton.NumGlyphs := 1;
  case FJFEditKind of
    JFbkDropDown,
    JFbkDropDownTree,
    JFbkDate,
    JFbkSearch: JFButtonVisible := True
  end;

  SetDateTimeMask;
  
  Clear;
  Change;

end;

{ TJFEditBtn }


procedure TJFEdit.SetJFExecParams(const Value: TEdtExecParams);
begin
  JFExecParams.Assign(Value);
end;

procedure TJFEdit.SetJFSQLText(const Value: String);
begin
  FJFSQLText := Value;
end;

procedure TJFEdit.SetOnButtonClick(const Value: TNotifyEvent);
begin
  FOnButtonClick := Value;
end;

procedure TJFEdit.SetJFSearchFields(const Value: TEdtSearchFields);
begin
  JFSearchFields.Assign(Value);
end;

procedure TJFEdit.WMCut(var Msg: TWMCut);
begin
  inherited;
end;

procedure TJFEdit.WMPAINT(var Message: TMessage);
begin
  inherited;
  //SetEditRect;
end;

procedure TJFEdit.WMPaste(var Msg: TWMPaste);
begin
  case FJFEditKind of
    JFbkNumeric    : Exit;
    JFbkFilterChar : Exit;
    JFbkSearch     : Exit;
  end;  
  inherited;
end;

procedure TJFEdit.WMSize(var Msg: TWMSize);
begin
  inherited;
  ResizeButton;
end;


procedure TJFEdit.KeyDown(var Key: Word; Shift: TShiftState);
begin
  try
    if Shift <> [] then
    begin
      Exit;
    end;
   
    if FJFFocusMove then
    begin
      case Key of
        VK_DOWN,
        VK_RETURN : begin
                      if Assigned(GetParentForm(Self)) then
                      begin
                        Key := 0;
                        PostMessage(GetParentForm(Self).Handle,WM_NEXTDLGCTL, 0, 0);

                      end;
                    end;
        VK_UP : begin
                  if Assigned(GetParentForm(Self)) then
                  begin
                    Key := 0;
                    PostMessage(GetParentForm(Self).Handle,WM_NEXTDLGCTL, 1, 0);

                  end;
                end;  
      end;
    end;
  finally
    inherited;
  end;
end;

procedure TJFEdit.KeyPress(var Key: Char);
var
  iLoop : Integer;
  iPos  : Integer;
begin
  if (Key = #32) then
  begin
    if ((FJFEditKind = JFbkNumeric) or
       (FJFEditKind = JFbkDate) or
       (FJFEditKind = JFbkDropDown) or
       (FJFEditKind = JFbkDropDownTree) or
       (FJFEditKind = JFbkSearch)) and JFButtonVisible then
    begin
      Key := #0;
      ShowSelect(Key);
      Exit;
    end;
  end;

  if (FJFLimitSpace) and (Key = #32) then
  begin
    Key := #0;
    Exit;
  end;  
  
  inherited;

  if (Key = #8) and ReadOnly and FJFBackspaceClear then
  begin
    Key := #0;
    Clear;
  end;  

  case FJFEditKind of
    JFbkSearch : begin
                   if (Ord(Key) >= 33) and (Ord(Key) <= 126) and (ReadOnly = True) then
                   begin
                     ShowSelect(Key);
                     Key := #0;
                     Exit;
                   end;   
                 end;
    JFbkNumeric: begin
                   if not (Key in ['0'..'9', #8, '.', '-']) then
                   begin
                     Key := #0;
                     Exit; 
                   end;

                   if Key = #8 then
                     Exit;

                   if (Key = '-')  and (Pos('-', inherited Text) > 0) then
                   begin
                     Key := #0;
                     Exit;
                   end;   

                   if (Key = '.') and ((FJFDecimalDigits = 0) or (Pos('.', inherited Text) > 0)) then
                   begin
                     Key := #0;
                     Exit; 
                   end;

                   if Key = '.' then
                   begin
                     iPos := Length(inherited Text) - SelStart;

                     if iPos > FJFDecimalDigits then
                     begin
                       Key := #0;
                     end;  
                     Exit;
                   end;

                   if Key = '-' then
                   begin
                     if SelStart <> 0 then
                     begin
                       Key := #0;
                       Exit;
                     end;  
                   end;    

                   iPos := Pos('.', inherited Text);

                   if iPos > 0 then
                   begin
                     if SelLength = 0 then
                     begin
                       if SelStart >= iPos then
                       begin
                         if Length(Copy(inherited Text, iPos + 1, Length(inherited Text))) >= FJFDecimalDigits then
                         begin
                           Key := #0;
                           Exit;
                         end;  
                       end;  
                     end;    
                   end;    
                 end;
    JFbkFilterChar : begin
                       if Key = #8 then
                         Exit;
                         
                       if FJFFilterChars <> '' then
                       begin
                         for iLoop := 1 to Length(FJFFilterChars) do
                         begin
                           if Ord(Key) = Ord(FJFFilterChars[iLoop]) then
                           begin

⌨️ 快捷键说明

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