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

📄 newabelsoft.pas

📁 delphi写的对学习delphi初级入门的数据编程很有用。是用用来查找硬盘mp3文件
💻 PAS
📖 第 1 页 / 共 5 页
字号:
begin
  if not (Key in ['0'..'9','-','/',#8]) then Key:=#0;
end;


{TDBDateEdit}

constructor TDBDateEdit.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FDataLink := TFieldDataLink.Create;
  FDataLink.Control := Self;
  FDataLink.OnDataChange := DataChange;
  FDataLink.OnUpdateData := UpdateData;
  OnKeyPress:=OnEditKeyPress;
  OnDropDown:=OnBtnClick;
end;

destructor TDBDateEdit.Destroy;
begin
  FDataLink.Free;
  inherited Destroy;
end;

procedure TDBDateEdit.UpdateData(Sender: TObject);
begin
  FDataLink.Field.AsDateTime := FDate;
end;

procedure TDBDateEdit.DataChange(Sender: TObject);
begin
  if FDataLink.Field <> nil then
  begin
    if FDataLink.Field.AsVariant = null then
      Self.Text:=''
    else begin
      FDate:=FDataLink.Field.AsDateTime;
      Self.Text:=DateToStr(FDate);
    end;
  end
  else begin
    if csDesigning in ComponentState then
      Self.Text := Name
    else Self.Text := '';
  end;
end;

function TDBDateEdit.GetDataField: string;
begin
  Result := FDataLink.FieldName;
end;

function TDBDateEdit.GetDataSource: TDataSource;
begin
  Result := FDataLink.DataSource;
end;

procedure TDBDateEdit.SetDataField(const Value: string);
begin
  FDataLink.FieldName := Value;
end;

procedure TDBDateEdit.SetDataSource(Value: TDataSource);
begin
  FDataLink.DataSource := Value;
  if Value <> nil then Value.FreeNotification(Self);
end;

procedure TDBDateEdit.CMExit(var Message: TCMExit);
var
  strDate:string;
begin
  strDate:=Self.Text;
  try
    StrToDate(strDate);
  except
    Text:='';
    strDate:='';
  end;

  if FDataLink <> nil then
  begin
    if FDataLink.Active then
    begin
      if FDataLink.DataSet.State in [dsBrowse] then
      begin
        if FDataLink.DataSet.Eof then
          FDataLink.DataSet.Append
        else
          FDataLink.DataSet.Edit;
      end;
      if strDate='' then
      begin
        FDataLink.Field.AsVariant:=Null;
        FDate:=0;
      end
      else begin
        FDate:=StrToDate(strDate);
        FDataLink.Field.AsDateTime:=FDate;
      end;
    end;
  end;
  inherited;
end;

procedure TDBDateEdit.OnEditKeyPress(Sender: TObject; var Key: Char);
begin
  if not (Key in ['0'..'9','-','/',#8]) then Key:=#0;
end;

procedure TDBDateEdit.OnBtnClick(Sender:TObject);
var
  ScrPoint:Tpoint;
begin
  ScrPoint:=GetClientOrigin;
 // GetDateShow(ScrPoint.x,ScrPoint.y,Height,Self);
end;

{TSelectKeyID}

constructor TSelectKeyID.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FKeyType:=0;
  FIntKeyID:=0;
  FStrKeyID:='';
  Style:=csOwnerDrawFixed;
  OnDrawItem:=OnShowSelect;
end;

destructor TSelectKeyID.Destroy;
begin
  inherited Destroy;
end;

procedure TSelectKeyID.SetShowSelect(Value:string);
begin
  FShowSelect:=Value;
  Items.Clear;
  Items.Add(Value);
  ItemIndex:=0;
end;

procedure TSelectKeyID.OnShowSelect(Control: TWinControl; Index: Integer;
              Rect: TRect; State: TOwnerDrawState);
begin
  with Canvas do
  begin
    if odComboBoxEdit	in State then
    begin
      FillRect(Rect);
      TextOut(Rect.Left+2,Rect.Top+1,FShowSelect);
    end;
  end;
end;

procedure TSelectKeyID.SetIntKeyID(Value:integer);
begin
  FIntKeyID:=value;
  if Assigned(FOnIDChange) then FOnIDChange(Self);
end;

procedure TSelectKeyID.SetStrKeyID(Value:string);
begin
  FStrKeyID:=value;
  if Assigned(FOnIDChange) then FOnIDChange(Self);
end;

{TKeyIDCombo}

constructor TKeyIDCombo.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  Style:=csDropDownList;
  KeyIDList:=TStringList.Create;
  FKeyType:=0;
  FIntKeyID:=0;
  FStrKeyID:='';
end;

destructor TKeyIDCombo.Destroy;
begin
  inherited Destroy;
  KeyIDList.Destroy;
end;

procedure TKeyIDCombo.SetIntKeyID(Value:integer);
var
  i:Integer;
begin
  for i:=0 to KeyIDList.Count-1 do
  begin
    if StrToInt(Trim(KeyIDList.Strings[i]))=Value then
    begin
      ItemIndex:=i;
      break;
    end;
  end;
end;

procedure TKeyIDCombo.SetStrKeyID(Value:string);
var
  i:Integer;
begin
  for i:=0 to KeyIDList.Count-1 do
  begin
    if Trim(KeyIDList.Strings[i])=Value then
    begin
      ItemIndex:=i;
      break;
    end;
  end;
end;

function  TKeyIDCombo.ReadIntKeyID(var Value:integer):Boolean;
var
  i:Integer;
begin
  Result:=False;
  if ItemIndex>=0 then
  begin
    try
      Value:=StrToInt(Trim(KeyIDList.Strings[ItemIndex]));
    except
      exit;
    end;
  end;
  Result:=True;
end;

function  TKeyIDCombo.ReadStrKeyID(var Value:string):Boolean;
var
  i:Integer;
begin
  Result:=False;
  if ItemIndex>=0 then
  begin
    try
      Value:=Trim(KeyIDList.Strings[ItemIndex]);
    except
      exit;
    end;
  end;
  Result:=True;
end;
//////////////////////////////////////////
{TTrayIcon}
//////////////////////////////////////////
constructor TTrayIcon.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  SettingMDIForm := True;
  FIconVisible := True;      // Visible by default
  FEnabled := True;          // Enabled by default
  FShowHint := True;         // Show hint by default
  SettingPreview := False;

  // Use the TaskbarCreated message available from Win98/IE4+
  WM_TASKBARCREATED := RegisterWindowMessage('TaskbarCreated');

  FIcon := TIcon.Create;
  IconData.cbSize := SizeOf(TNotifyIconDataEx);
  // IconData.wnd points to procedure to receive callback messages from the icon
  IconData.wnd := AllocateHWnd(HandleIconMessage);
  // Add an id for the tray icon
  IconData.uId := 1;
  // We want icon, message handling, and tooltips by default
  IconData.uFlags := NIF_ICON + NIF_MESSAGE + NIF_TIP;
  // Message to send to IconData.wnd when event occurs
  IconData.uCallbackMessage := WM_TRAYNOTIFY;

  FWindowHandle := GetWindowLong(IconData.wnd, GWL_HWNDPARENT);

  CycleTimer := TTimer.Create(Self);
  CycleTimer.Enabled := False;
  CycleTimer.Interval := FCycleInterval;
  CycleTimer.OnTimer := TimerCycle;

  { Assign a default icon if Icon property is empty. This will assign
    an icon to the component when it is created for the very first time.
    When the user assigns another icon it will not be overwritten next
    time the project loads. HOWEVER, if the user has decided explicitly
    to have no icon a default icon will be inserted regardless.
    I figured this was a tolerable price to pay. }
  if (csDesigning in ComponentState) then
    if FIcon.Handle = 0 then
      if LoadDefaultIcon then
        FIcon.Handle := LoadIcon(0, IDI_WINLOGO);
  { It is tempting to assign the application's icon (Application.Icon)
    as a default icon. The problem is there's no Application instance
    at design time. Or is there? Yes there is: the Delphi editor!
    Application.Icon is the icon found in delphi32.exe. How to use:
      FIcon.Assign(Application.Icon); }

  // Set hook(s)
  if not (csDesigning in ComponentState) then
  begin
    HookApp;                 // Hook into the app.'s message handling
    if Owner is TWinControl then
      HookForm;              // Hook into the main form's message handling
  end;
end;


destructor TTrayIcon.Destroy;
begin
  SetIconVisible(False);     // Remove the icon from the tray
  SetDesignPreview(False);   // Remove any DesignPreview icon
  FIcon.Free;                // Free the icon
  DeallocateHWnd(IconData.Wnd);   // Free the tray window
  CycleTimer.Free;
  // It is important to unhook any hooked processes
  if not (csDesigning in ComponentState) then
  begin
    UnhookApp;
    if Owner is TWinControl then
      UnhookForm;
  end;
  inherited Destroy;
end;


procedure TTrayIcon.Loaded;
{ This method is called when all properties of the component have been
  initialized. The method SetIconVisible must be called here, after the
  tray icon (FIcon) has loaded itself. Otherwise, the tray icon will
  be blank (no icon image). }
begin
  inherited Loaded;	     // Always call inherited Loaded first
  if Owner is TWinControl then
    if (FStartMinimized) and not (csDesigning in ComponentState) then
    begin
      Application.ShowMainForm := False;
      ShowWindow(Application.Handle, SW_HIDE);
    end;
  ModifyIcon;
  SetIconVisible(FIconVisible);
end;


function TTrayIcon.LoadDefaultIcon: Boolean;
{ This method is called to determine whether to assign a default
  icon to the component. Descendant classes (like TextTrayIcon) can
  override the method to change this behavior. }
begin
  Result := True;
end;


procedure TTrayIcon.Notification(AComponent: TComponent;
  Operation: TOperation);
begin
  inherited Notification(AComponent, Operation);
  { Check if either the imagelist or the popup menu is about
    to be deleted }
  if (AComponent = IconList) and (Operation = opRemove) then
  begin
    FIconList := nil;
    IconList := nil;
  end;
  if (AComponent = PopupMenu) and (Operation = opRemove) then
  begin
    FPopupMenu := nil;
    PopupMenu := nil;
  end;
end;


{ For MinimizeToTray to work, we need to know when the form is minimized
  (happens when either the application or the main form minimizes).
  The straight-forward way is to make TTrayIcon trap the
  Application.OnMinimize event. However, if you also make use of this
  event in the application, the OnMinimize code used by TTrayIcon
  is discarded.
  The solution is to hook into the app.'s message handling (via HookApp).
  You can then catch any message that goes through the app. and still
  use the OnMinimize event. }

procedure TTrayIcon.HookApp;
begin
  // Hook the application
  OldAppProc := Pointer(GetWindowLong(Application.Handle, GWL_WNDPROC));
  NewAppProc := MakeObjectInstance(HookAppProc);
  SetWindowLong(Application.Handle, GWL_WNDPROC, LongInt(NewAppProc));
end;


procedure TTrayIcon.UnhookApp;
begin
  if Assigned(OldAppProc) then
    SetWindowLong(Application.Handle, GWL_WNDPROC, LongInt(OldAppProc));
  if Assigned(NewAppProc) then
    FreeObjectInstance(NewAppProc);
  NewAppProc := nil;
  OldAppProc := nil;
end;


{ All app. messages pass through HookAppProc. You can override the
  messages by not passing them along to Windows (via CallWindowProc). }

procedure TTrayIcon.HookAppProc(var Msg: TMessage);
begin
  case Msg.Msg of

    WM_SIZE:
      // Handle MinimizeToTray by capturing app's minimize events
      if Msg.wParam = SIZE_MINIMIZED then
      begin
        if FMinimizeToTray then
          DoMinimizeToTray;
        { You could insert a call to a custom minimize event here, but it
          would behave exactly like Application.OnMinimize, so I see no
          need for it. }
      end;

    WM_WINDOWPOSCHANGED: begin
      { Handle MDI forms (MDI children cause app. to be redisplayed on
        taskbar. We hide it again. This may cause a quick flicker (?)). }
      if SettingMDIForm then
        if Application.MainForm <> nil then
        begin
          if Application.MainForm.FormStyle = fsMDIForm then
            if FStartMinimized then
              ShowWindow(Application.Handle, SW_HIDE);
          SettingMDIForm := False;   // So we only do this once
        end;
    end;

  end;

  { Show the tray icon if the taskbar has been re-created after an
    Explorer crash. }
  if Msg.Msg = WM_TASKBARCREATED then
    if FIconVisible then
      ShowIcon;

  // Pass the message on
  Msg.Result := CallWindowProc(OldAppProc, Application.Handle,
                Msg.Msg, Msg.wParam, Msg.lParam);
end;


{ You can hook into the main form (or any other window) just as easily
  as hooking into the app., allowing you to handle any message that
  window processes.

⌨️ 快捷键说明

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