📄 wwidlg.pas
字号:
if (ASelected<>Nil) and (Aselected.count=0) then Aselected:=Nil; {Read field list from Table }
if ASelected <>Nil then wwDBGrid1.selected:= ASelected
else ReadFromTableComponent(wwDBGrid1.selected, ADataSet);
PictureMaskFromField:= APictureMaskFromField;
CallingComponent:= AComponent;
tempControl:= wwGetPictureControl(AComponent);
TempPictureMasks:= wwGetPictureMasks(TempControl);
if TempPictureMasks<>nil then
wwDBGrid1.PictureMasks.assign(TempPictureMasks);
tempControl:= wwGetControlTypeControl(AComponent);
TempControlType:= wwGetControlType(tempControl);
if TempControlType<>nil then
wwDBGrid1.ControlType.assign(TempControlType);
wwDBGrid1.useTFields:= AUseTFields;
wwDBGrid1.Options:= AGridOptions;
if (dgMultiSelect in wwDBGrid1.options) then
wwDBGrid1.multiSelectOptions:= [msoAutoUnselect, msoShiftSelect];
wwDBGrid1.Color:= AGridColor;
wwDBGrid1.TitleAlignment:= AGridTitleAlignment;
ThisDataSet:= ADataSet;
if (ASelected<>Nil) and AUseTFields then wwDataSetUpdateFieldProperties(ADataSet, ASelected);
Options:= AOptions;
MaxWidth:= AMaxWidth;
MaxHeight:= AMaxHeight;
wwIncrementalSearch1.CharCase:= ACharCase;
FSearchText:= ASearchText;
if (opFixFirstColumn in AOptions) then begin
wwDBGrid1.FixedCols:= 1;
end
else begin
wwDBGrid1.FixedCols:= 0;
end;
FUserButton1Click:= AUserButton1Click;
FUserButton2Click:= AUserButton2Click;
FOnInitDialog:= AOnInitDialog;
FOnCloseDialog:= AOnCloseDialog;
FOnSortChange:= AOnSortChange;
UserButton1.caption:= AUserButton1Caption;
UserButton2.caption:= AUserButton2Caption;
TempResult := ShowModal = IDOK;
finally
dataSource1.DataSet:= Nil;
Free;
Result:= TempResult;
end;
end;
function TwwLookupDialog.GetPrimaryDataSet: TDataSet;
begin
result := LookupTable;
end;
Function TwwLookupDialog.Execute: boolean;
begin
Result:= False;
if (FlookupTable=Nil) then begin
MessageDlg('You must define a lookupTable.', mtWarning, [mbok], 0);
exit;
end;
if (not LookupTable.active) then
begin
MessageDlg('Search Table is not active.', mtWarning, [mbok], 0);
exit;
end;
result:= ExecuteWWLookupDlg(Screen.ActiveForm, self, FSelected, LookupTable, Options, GridOptions,
GridColor, GridTitleAlignment, FCaption, FMaxWidth, FMaxHeight, FCharCase,
FUserButton1Caption, FUserButton2Caption,
FUserButton1Click, FUserButton2Click, FOnInitDialog,
FOnCloseDialog, FOnSortChange, '', UseTFields,
FPictureMaskFromField);
end;
Function TwwCustomLookupDialog.Execute: boolean;
{ procedure wwGotoCurrent(SyncDS, SyncToDS: TDataSet);
var KeyFields: string;
begin
for i := 0 to
end;}
var
tempLookupTable: TDataSet;
begin
Result:= False;
if (FlookupTable=Nil) then begin
if self is TwwLookupDialog then begin
MessageDlg('You must define a lookupTable.', mtWarning, [mbok], 0);
exit;
end
else begin
tempLookupTable:= FSyncTable;
if tempLookupTable=nil then
begin
MessageDlg('You must define a searchTable.', mtWarning, [mbok], 0);
exit;
end;
result:= ExecuteWWLookupDlg(Screen.ActiveForm, self, FSelected, TempLookupTable, Options, GridOptions,
GridColor, GridTitleAlignment, FCaption, FMaxWidth, FMaxHeight, FCharCase,
FUserButton1Caption, FUserButton2Caption,
FUserButton1Click, FUserButton2Click, FOnInitDialog,
FOnCloseDialog, FOnSortChange, '', UseTFields,
FPictureMaskFromField);
exit;
end
end
else tempLookupTable:= FLookupTable as TDataSet;
if (FSyncTable<>Nil) and (FSyncTable=FLookupTable) then begin
MessageDlg('Your SearchTable and ShadowSearchTable must reference two' +
' distinct TDataSet objects, but each must reference the same ' +
'physical table.',
mtWarning, [mbok], 0);
exit;
end;
{ 5/28/97}
if (FSyncTable<>Nil) and not (FSyncTable is TDataSet) then begin
MessageDlg('The SearchDialog requires TDataSet objects',
mtWarning, [mbok], 0);
exit;
end;
{ 12/9/99 - Put if clause first }
if (FSyncTable<>Nil) and (FSyncTable<>tempLookupTable) then
begin
if not wwEqualStr(wwGetDatabaseName(FSyncTable),wwGetDatabaseName(tempLookupTable)) or
not wwEqualStr(wwGetTableName(FSyncTable),wwGetTableName(tempLookupTable)) then
begin
MessageDlg('Your SearchTable and ShadowSearchTable must reference two' +
' distinct TDataSet objects, and each must reference the same ' +
'physical table.',
mtWarning, [mbok], 0);
exit;
end;
end;
if (tempLookuptable is TTable) and
(TTable(tempLookupTable).database=Nil) then
begin
MessageDlg('Unable to open search or lookup table.',
mtWarning, [mbok], 0);
exit;
end;
if (not tempLookupTable.active) or
((FSyncTable<>Nil) and (not FSyncTable.active)) then
begin
MessageDlg('Search Table is not active.', mtWarning, [mbok], 0);
exit;
end;
if FSyncTable<>Nil then begin
if (tempLookupTable is TwwTable) then begin
if TTable(tempLookupTable).database.isSQLBased and TwwTable(tempLookupTable).SyncSQLByRange then
begin
if FSyncTable is TwwTable then
TwwTable(tempLookupTable).syncSQLTable(TwwTable(FSyncTable));
end
else if TwwTable(tempLookupTable).NarrowSearch then TTable(tempLookupTable).CancelRange;
end;
try
if (FSyncTable<>tempLookupTable) then
begin
if (FSyncTable is TTable) and (tempLookupTable is TTable) then
TTable(tempLookupTable).gotoCurrent(TTable(FSyncTable))
else DoSyncDataSets(tempLookupTable, FSyncTable);
// tempLookupTable.gotoCurrent(FSyncTable)
end;
// if (FSyncTable<>tempLookupTable) then wwGotoCurrent(tempLookupTable, FSyncTable);
except
end;
end;
if FSyncTable = tempLookupTable then begin
result:= ExecuteWWLookupDlg(Screen.ActiveForm, self, Nil, tempLookupTable, Options, GridOptions,
GridColor, GridTitleAlignment, FCaption, FMaxWidth, FMaxHeight, FCharCase,
FUserButton1Caption, FUserButton2Caption,
FUserButton1Click, FUserButton2Click, FOnInitDialog,
FOnCloseDialog, FOnSortChange, '', UseTFields, FPictureMaskFromField)
end
else result:= ExecuteWWLookupDlg(Screen.ActiveForm, self, FSelected, tempLookupTable, Options, GridOptions,
GridColor, GridTitleAlignment, FCaption, FMaxWidth, FMaxHeight, FCharCase,
FUserButton1Caption, FUserButton2Caption,
FUserButton1Click, FUserButton2Click, FOnInitDialog,
FOnCloseDialog, FOnSortChange, '', UseTFields,
FPictureMaskFromField);
if result then begin
if FSyncTable<>Nil then begin
if FSyncTable is TwwTable then begin
if (TwwTable(FSyncTable).database.isSqlBased) and (TwwTable(FSyncTable).SyncSQLByRange) then
if TempLookupTable is TwwTable then
TwwTable(FSyncTable).SyncSQLTable(TTable(tempLookupTable));
end;
If not (tempLookupTable.eof and tempLookupTable.bof) then
begin
if (FSyncTable is TTable) and (tempLookupTable is TTable) then
TTable(FSyncTable).gotoCurrent(TTable(tempLookupTable))
else DoSyncDataSets(FSyncTable, tempLookupTable);
end
end;
end
end;
function TwwCustomLookupDialog.GetSelectedFields: TStrings;
begin
result:= FSelected;
end;
procedure TwwCustomLookupDialog.SetSelectedFields(sel : TStrings);
begin
FSelected.assign(sel);
end;
procedure TwwCustomLookupDialog.SetLookupTable(sel : TDataSet);
begin
FLookupTable:= sel;
end;
procedure TwwCustomLookupDialog.SetWWLookupTable(sel : TDataSet);
begin
FLookupTable:= sel as TDataSet
end;
procedure TwwCustomLookupDialog.SetSyncTable(sel : TDataSet);
begin
FSyncTable:= sel;
end;
Function TwwCustomLookupDialog.GetSyncTable: TDataSet;
begin
result:= FSyncTable;
end;
Function TwwCustomLookupDialog.GetLookupTable: TDataSet;
begin
result:= FLookupTable;
end;
Function TwwCustomLookupDialog.GetWWLookupTable: TDataSet;
begin
result:= FLookupTable as TDataSet;
end;
procedure TwwCustomLookupDialog.SetOptions(sel: TwwDBLookupDlgOptions);
begin
FOptions:= sel;
end;
procedure TwwCustomLookupDialog.SetGridOptions(sel: TwwDBGridOptions);
begin
FGridOptions:= sel;
end;
procedure TwwLookupDlg.writeStatusInfo;
var recNumber, recCount: longint;
tempTableName: string;
begin
if Showing then Update; { Fixes canvas font }
with (DataSource1) do begin
if not (dataset is TTable) then exit;
with (dataSet as TTable) do begin
// if isSequencable then begin
if isSequenced then begin
UpdateCursorPos;
if dbiGetSeqNo(Handle, recNumber)<>0 then exit;
if dbiGetRecordCount(Handle, recCount)<>0 then exit;
tempTableName:= tableName;
strStripTrailing(temptableName, [' ']);
StatusHeader.sections[0]:= tempTableName;
StatusHeader.sections[1]:=
wwInternational.SearchDialog.StatusRecLabel + ' ' +
inttostr(recNumber) + ' ' +
wwInternational.SearchDialog.StatusOfLabel + ' ' +
inttostr(recCount);
end
end
end
end;
procedure TwwLookupDlg.Activate;
begin
if not initialized then
begin
if wwIncrementalSearch1.visible then wwIncrementalSearch1.SetFocus;
WriteStatusInfo;
initialized:= True;
if (FSearchText<>'') then
wwIncrementalSearch1.text:= FSearchText;
if wwIncrementalSearch1.text<>'' then
begin
{ 9/19/97 - If show match text then have control update text }
if wwIncrementalSearch1.ShowmatchText then
wwIncrementalSearch1.FindValue
else
wwIncrementalSearch1.selStart:= length(wwIncrementalSearch1.text);
end
end;
inherited Activate;
end;
procedure TwwLookupDlg.UpdateSearchField;
begin
if (not wwdbgrid1.useTFields) then begin
if (not (DataSource1.dataset is TTable)) or ((DataSource1.dataset as TTable).IndexFieldCount=0) then
begin
if wwdbgrid1.fieldcount>0 then
wwIncrementalSearch1.SearchField:= wwdbgrid1.fields[0].FieldName;
end;
end
end;
{ 11/10/97 - AdjustcolumnstoIndex modifed to support virtual data sets}
procedure TwwLookupDlg.AdjustColumnsToIndex;
var i: integer;
foundIndexField: boolean;
curIndex: integer;
index: integer;
TempIndexFields: TList;
{$ifdef wwDelphi3Up}
TempSearchField: string;
IndexDefs: TIndexDefs;
PropInfo: PPropInfo;
apos, idx: integer;
{$endif}
curField: TField;
DataSet: TDataSet;
{$ifdef wwDelphi3Up}
function GetIndexName: string;
begin
PropInfo:= Typinfo.GetPropInfo(DataSource1.DataSet.ClassInfo,'IndexName');
if PropInfo<>Nil then Result:= GetStrProp(DataSource1.DataSet, PropInfo);
end;
{$endif}
begin
UpdateSearchField;
if (DataSource1=Nil) or (DataSource1.DataSet=Nil) then exit;
DataSet:= DataSource1.dataset;
if not (wwIsClass(dataset.classType, 'TTable') or
wwIsClass(dataset.classType, 'TClientDataSet')) and
(Typinfo.GetPropInfo(DataSet.ClassInfo,'IndexDefs')=Nil) and
not wwKeyCombo1.UseAllFields(ThisDataSet) then exit;
foundIndexField:= false;
wwIncrementalSearch1.setSearchField('');
curIndex:= 0;
{ Move grid columns to match index }
if DataSet is TTable then
begin
TempIndexFields:= TList.create;
for i:= 0 to (dataset as TTable).indexFieldCount-1 do
TempIndexFields.add((dataset as TTable).indexFields[i]);
end
else if wwIsClass(dataset.classType, 'TClientDataSet') then
begin
TempIndexFields:= TList.create;
TempSearchField:= wwGetFieldNameFromTitle(DataSet, wwKeyCombo1.text);
TempIndexFields.Add(Dataset.FindField(TempSearchField));
end
else begin
PropInfo:= Typinfo.GetPropInfo(DataSource1.DataSet.ClassInfo,'IndexDefs');
if (PropInfo<>Nil) and not wwKeyCombo1.UseAllFields(ThisDataSet) then
begin
IndexDefs:= TIndexDefs(GetOrdProp(DataSource1.DataSet, PropInfo));
TempIndexFields:= TList.create;
idx:= IndexDefs.indexof(GetIndexName);
if idx>=0 then begin
APos:= 1;
repeat
TempSearchField:= strGetToken(IndexDefs.items[idx].fields, ';', APos);
if DataSource1.dataset.FindField(TempSearchField)<>Nil then
TempIndexFields.add(DataSource1.dataset.FindField(TempSearchField));
until APos<=0;
end
end
else begin
TempIndexFields:= TList.create;
TempSearchField:= wwGetFieldNameFromTitle(DataSet, wwKeyCombo1.text);
TempIndexFields.Add(Dataset.FindField(TempSearchField));
end;
end;
Dataset.DisableControls;
{ reset column sizes back to starting size }
if TempIndexFields.count>0 then
if wwDBGrid1.useTFields then
wwDataSetUpdateFieldProperties(dataSet, wwdbgrid1.selected);
if wwDBGrid1.useTFields then begin
for i:= 0 to TempIndexFields.Count-1 do begin
curField:= TField(TempIndexFields[i]);
if curfield=nil then continue; { 8/24/98 }
if curfield.visible then begin
if not (opDisableReorderColumns in Options) then
curField.index:= curIndex;
if not foundIndexfield then begin
wwIncrementalSearch1.setSearchField(curfield.fieldName);
foundIndexField:= True;
end;
inc(curIndex);
end;
end
end
else begin
for i:= 0 to TempIndexFields.Count-1 do begin
curField:= TField(TempIndexFields[i]);
if curfield=nil then continue; { 8/24/98 }
if wwFindSelected(wwDBGrid1.Selected, curfield.FieldName, Index) then
begin
{ 11/4/97 - Use i instead of 0}
if not (opDisableReorderColumns in Options) then begin
wwdbgrid1.Selected.Insert(i, wwDBGrid1.selected[Index]);
wwdbgrid1.Selected.Delete(Index+1);
end;
if not foundIndexfield then begin
wwIncrementalSearch1.setSearchField(curfield.fieldName);
foundIndexField:= True;
end;
end
end;
wwDBGrid1.ApplySelected;
end;
Dataset.EnableControls;
TempIndexFields.free;
end;
procedure TwwLookupDlg.wwKeyCombo1Change(Sender: TObject);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -