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

📄 locate.pas

📁 产品信息系统!关于产品基础信息的系统!功能强大!
💻 PAS
📖 第 1 页 / 共 3 页
字号:
   CancelBtn.visible:= True;
   CancelBtn.Top:= NextButton.Top;
   CancelBtn.Left:= FieldsGroup.Left + FieldsGroup.Width - CancelBtn.Width - 1;
   CancelBtn.Height:= (screen.pixelsperinch * 27) div 96;
end;

Function TLocateDlg.GetFieldNameFromTitle(fieldTitle: string): string;
var i: integer;
begin
   result:= '';

   with DataSet do begin
      { Give priority to non-calculated fields of the same name, if they exist }
      for i:= 0 to fieldCount-1 do begin
	 if wwisNonPhysicalField(fields[i]) then continue;
	 if strReplaceChar(fields[i].displayLabel,'~',' ')=strReplaceChar(fieldTitle,'~',' ') then begin
	    result:= fields[i].FieldName;
	    exit;
	 end
      end;

      for i:= 0 to fieldCount-1 do begin
	 if not wwisNonPhysicalField(fields[i]) then continue;
	 if strReplaceChar(fields[i].displayLabel,'~', ' ')=strReplaceChar(fieldTitle,'~', ' ') then begin
	    result:= fields[i].FieldName;
	    exit;
	 end
      end
   end;
end;

Function TLocateDlg.FindMatch(FromBeginning: boolean): boolean;
var
   MatchType: TwwLocateMatchType;
   curFieldName: string;
//   curField: TField;
//   keyValue: string;
//   caseSens: boolean;
begin
   result:= false;
   if ExactMatchBtn.Checked then
      MatchType:= mtExactmatch
   else if PartialMatchStartBtn.Checked then
      MatchType:= mtPartialMatchStart
   else MatchType:= mtPartialMatchAny;

   curFieldName:= getfieldNameFromTitle(FieldNameComboBox.text);
   if curFieldName='' then exit;

{   if (FromBeginning or TwwLocateDialog(DlgComponent).UseLocateMethod) and (MatchType in [mtExactMatch, mtPartialMatchStart]) then begin
     curField:= Dataset.fieldbyname(curFieldName);
     caseSens:= (caseSensitiveCheckbox.State<> cbUnchecked);
     keyValue:= SearchValue.text;
     if (curField.dataType<>ftMemo) then
     begin
        if caseSens then begin
           if (MatchType=mtExactMatch) then result:= DataSet.Locate(curFieldName, KeyValue, [])
           else result:= DataSet.Locate(curFieldName, KeyValue, [loPartialKey]);
        end
        else begin
           if (MatchType=mtExactMatch) then result:= DataSet.Locate(curFieldName, KeyValue, [loCaseInsensitive])
           else result:= DataSet.Locate(curFieldName, KeyValue, [loPartialKey, loCaseInsensitive]);
        end;
     end;
     exit;
   end;
}
   result:= wwFindMatch(FromBeginning, DataSet, curFieldName,
	searchValue.text, matchType, CaseSensitiveCheckbox.State<> cbUnchecked,
        (DlgComponent as TwwLocateDialog).UseLocateMethod);
end;

procedure TLocateDlg.FindFirst(Sender: TObject);
begin
   if not FindMatch(True) then begin
      MessageDlg(wwInternational.UserMessages.LocateNoMatches,
	 mtInformation, [mbok], 0);
   end
//   else if (DlgComponent as TwwLocateDialog).CloseOnMatch then
   else if (ldoCloseOnMatch in (DlgComponent as TwwLocateDialog).Options) then
      ModalResult:= mrOK;
end;

procedure TLocateDlg.FindNextBtnClick(Sender: TObject);
begin
   if not FindMatch(False) then begin
      MessageDlg(wwInternational.UserMessages.LocateNoMoreMatches,
	   mtInformation, [mbok], 0);
   end
   else if (ldoCloseOnMatch in (DlgComponent as TwwLocateDialog).Options) then
//   else if (DlgComponent as TwwLocateDialog).CloseOnMatch then
      ModalResult:= mrOK;
end;


procedure TLocateDlg.BitBtn1KeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
   if (key = VK_ESCAPE) then
      ModalResult := mrCancel;
end;

function TwwLocateDialog.Execute: boolean;
var
   field: TField;
   i: integer;
begin
   result:= True;
   with TLocateDlg.create(Application) do
   try
      if (DataSource=Nil) or (DataSource.dataSet=Nil) or
	 (not DataSource.dataSet.active) then begin
	 MessageDlg('DataSource does not reference an active DataSet', mtError, [mbok], 0);
	 exit;
      end;
      DlgComponent:= Self;
      field:= DataSource.DataSet.findField(SearchField);
      FieldNameComboBox.items.clear;
      if SortFields = fsSortByFieldNo then
	 FieldNameComboBox.sorted:= False;

      if DefaultButton = dbFindFirst then begin
	 FirstButton.Default:= True;
	 NextButton.Default:= False;
      end
      else begin
	 FirstButton.Default:= False;
	 NextButton.Default:= True;
      end;

      with DataSource.DataSet do begin
	 for i:= 0 to fieldCount-1 do begin
{            if not fields[i].calculated then begin}
	       if (fields[i].dataType = ftBlob) or (fields[i].dataType=ftGraphic) or
		  (fields[i].dataType = ftVarBytes) or (fields[i].dataType=ftBytes) then
		  continue;
	       if (FFieldSelection = fsAllFields) or (fields[i].visible) then
		  FieldNameComboBox.items.add(strReplaceChar(fields[i].DisplayLabel, '~',' '));
{            end}
	 end
      end;
      if field<>Nil then begin
	 SearchValue.Text:= fieldValue;
	 FieldNameCombobox.itemIndex:=
	    FieldNameComboBox.items.indexOf(strReplaceChar(Field.displayLabel, '~',' '));
      end
      else SearchValue.text:= '';

      DataSet:= dataSource.DataSet;
      caseSensitiveCheckBox.checked:= caseSensitive;
      case matchType of
	 mtExactMatch: ExactMatchBtn.checked:= True;
	 mtPartialMatchStart: PartialMatchStartBtn.checked:= True;
	 mtPartialMatchAny: PartialMatchAnyBtn.checked:= True;
      end;

      Caption:=  self.Caption;
      Result := ShowModal = IDOK;

      { Use user selections from dialog to update this component }
      if ExactMatchBtn.Checked then
	 MatchType:= mtExactmatch
      else if PartialMatchStartBtn.Checked then
	 MatchType:= mtPartialMatchStart
      else MatchType:= mtPartialMatchAny;
      caseSensitive:= caseSensitiveCheckBox.checked;
      fieldValue:= SearchValue.Text;
      SearchField:= getfieldNameFromTitle(FieldNameComboBox.text);

   finally
      Free;
   end

end;

constructor TwwLocateDialog.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  MatchType:= mtPartialMatchStart;
  caseSensitive:= False;
  SortFields:= fsSortByFieldName;
  Caption:=  'Locate Field Value';
  FDefaultButton:= dbFindNext;
  FFieldSelection:= fsAllFields;
  FDataLink:= TDataLink.create;
  FShowMessages:= True;
  FOptions:= [ldoCloseOnMatch];
//  FCloseOnMatch:= True;

end;

destructor TwwLocatedialog.Destroy;
begin
  FDataLink.free;
  inherited destroy;
end;

procedure TwwLocateDialog.SetDataSource(value : TDataSource);
begin
   FDataLink.dataSource:= value;
end;

Function TwwLocateDialog.getDataSource: TDataSource;
begin
   Result:= FdataLink.dataSource;
end;

function TwwLocateDialog.FindPrior: boolean;
begin
   result:= False;
end;

function TwwLocateDialog.FindFirst: boolean;
begin
   result:= False;
   if (dataSource=Nil) or (datasource.dataset=Nil) or (not datasource.dataset.active) then
   begin
      MessageDlg('DataSource does not refer to an active table!', mtWarning, [mbok], 0);
      exit;
   end;
   if FieldValue='' then begin
      DefaultButton:= dbFindFirst;
      result:= execute;
   end
   else begin
      result:= wwFindMatch(True, DataSource.DataSet, SearchField, FieldValue,
	matchType, caseSensitive, UseLocateMethod);
      if (not result) and FShowMessages then
	 MessageDlg(wwInternational.UserMessages.LocateNoMoreMatches,
	   mtInformation, [mbok], 0);
   end
end;

function TwwLocateDialog.FindNext: boolean;
begin
   result:= False;
   if (dataSource=Nil) or (datasource.dataset=Nil) or (not datasource.dataset.active) then
   begin
      MessageDlg('DataSource does not refer to an active table!', mtWarning, [mbok], 0);
      exit;
   end;
   if FieldValue='' then begin
      DefaultButton:= dbFindNext;
      result:= execute;
   end
   else begin
      result:= wwFindMatch(False, DataSource.DataSet, SearchField, FieldValue,
	 matchType, caseSensitive, UseLocateMethod);
      if (not result) and FShowMessages then
	 MessageDlg(wwInternational.UserMessages.LocateNoMoreMatches,
	   mtInformation, [mbok], 0);
   end

end;

procedure TLocateDlg.FieldNameComboBoxChange(Sender: TObject);
var Dlg: TwwLocateDialog;
begin
   Dlg:= DlgComponent as TwwLocateDialog;

   // 6/15/02 
   if not (ldoPreserveSearchText in Dlg.Options) then
       SearchValue.Text:= '';
   if not FieldNameComboBox.DroppedDown then SearchValue.setFocus;
   if DlgComponent=nil then exit;
   if Assigned(TwwLocateDialog(DlgComponent).FOnSelectField) then
      TwwLocateDialog(DlgComponent).FOnSelectField(self, FieldNameComboBox.text);
end;

procedure TLocateDlg.FieldNameComboBoxEnter(Sender: TObject);
begin
   NextButton.default:= False;
end;

procedure TLocateDlg.FieldNameComboBoxExit(Sender: TObject);
begin
   NextButton.default:= True;
end;

procedure TLocateDlg.FieldNameComboBoxKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
   if (Key=VK_Return) and FieldNameComboBox.DroppedDown then
   begin
      FieldNameComboBox.DroppedDown := False;
      SearchValue.setFocus;
   end
end;

procedure TLocateDlg.FormShow(Sender: TObject);
var Dlg: TwwLocateDialog;
begin
   ApplyIntl;
   Dlg:= DlgComponent as TwwLocateDialog;
   if not (ldoCloseOnMatch in Dlg.Options) then
   begin
      if CancelBtn is TBitBtn then
      begin
         TBitBtn(CancelBtn).Glyph.Assign(nil);
         TBitBtn(CancelBtn).Margin:=-1;
      end
   end;
   Dlg.Form:= self;

   if {True or }(ldoCaseSensitiveBelow in Dlg.Options) then
   begin
      ExactMatchBtn.Top      := 16;
      PartialMatchStartBtn.Top   := 34;
      PartialMatchAnyBtn.Top   := 52;
      Panel1.Top         := 72;
      CaseSensitiveCheckBox.Top := 75;
   end;

   Dlg.DoInitDialog;
end;

Procedure TwwLocateDialog.DoInitDialog;
begin
  if Assigned(FOnInitDialog) then OnInitDialog(Form);
end;

procedure TLocateDlg.ApplyIntl;
begin
   Font.Style:= wwInternational.DialogFontStyle;
   with wwInternational.LocateDialog do begin
      FieldValueGroup.caption:= FieldValueLabel;
      SearchTypeGroup.caption:= SearchTypeLabel;
      CaseSensitiveCheckbox.caption:= CaseSensitiveLabel;
      ExactMatchBtn.caption:= MatchExactLabel;
      PartialMatchStartBtn.caption:= MatchStartLabel;
      PartialMatchAnyBtn.caption:= MatchAnyLabel;
      FieldsGroup.caption:= FieldsLabel;
      FirstButton.caption:= BtnFirst;
      NextButton.caption:= BtnNext;
      if ldoCloseOnMatch in (DlgComponent as TwwLocateDialog).Options then
        CancelBtn.caption:= BtnCancel
      else
        CancelBtn.caption:= BtnClose;

      SearchValue.Hint:= FieldValueHint;
      CaseSensitiveCheckbox.Hint:= CaseSensitiveHint;
      ExactMatchBtn.Hint:= MatchExactHint;
      PartialMatchStartBtn.Hint:= MatchStartHint;
      PartialMatchAnyBtn.Hint:= MatchAnyHint;
      FirstButton.Hint:= BtnFirstHint;
      NextButton.Hint:= BtnNextHint;
      FieldNameComboBox.Hint:= FieldNameHint;
   end;
end;

function TwwLocateDialog.GetPrimaryDataSet: TDataSet;
begin
  result := nil;
  if DataSource <> nil then
    result := DataSource.DataSet;
end;

procedure TLocateDlg.FormCreate(Sender: TObject);
begin

end;

end.

⌨️ 快捷键说明

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