📄 wwcommon.pas
字号:
parts: TStrings;
i,j:integer;
{$ifdef win32}
fromLinks, toLinks, fromlink, tolink: string;
fpos, tpos: integer;
{$endif}
begin
otherfield := nil;
if (not curfield.calculated) then begin {Check LookupField value}
{$ifdef win32}
links:= TStringlist.create;
fromLinks:= curField.KeyFields;
toLinks:= curField.LookupKeyFields;
fpos:= 1; tpos:= 1;
while True do begin
fromLink:= strGetToken(fromlinks, ';', fpos);
toLink:= strGetToken(tolinks, ';', tpos);
if (fromLink='') or (toLink='') then break;
links.add(fromLink );
links.add(toLink);
end;
foundvalue := SyncLookupTable(Dataset,curfield.lookupdataset,links, AMethod);
if foundvalue then
otherfield := curfield.lookupdataset.fieldbyname(curfield.lookupresultfield);
{$endif}
end
else begin {Check Linked field value}
if (inLookupCalcLink) or (wwGetLookupTables(curField.dataset)=nil) then begin
result := nil;
exit;
end;
links:= TStringlist.create;
lookuplinks := wwDataSetGetLinks(Dataset,curfield.fieldname);
strBreakApart(lookuplinks, ';', links);
lookuptable := nil;
foundTable := false;
lookupfields := wwGetLookupFields(Dataset);
lookuptables := wwGetLookupTables(Dataset);
mylookuplinks := wwGetLookupLinks(Dataset);
parts:= TStringList.create;
for i:= 0 to lookupfields.count-1 do begin
strbreakApart(lookupfields.Strings[i], ';', parts);
if wwEqualStr(parts[0],curField.FieldName) then begin {7/24/97 - Check field }
for j:= 0 to lookuptables.count-1 do begin
lookupTable:= TwwTable(lookuptables.items[j]);
if isSameTable(lookuptable, parts) then
begin
foundtable:= (lowercase(mylookuplinks.strings[i])=
lowercase(lookupTable.CalcLookupLinks));
if foundtable then break;
end
end;
if foundtable then break;
end
end;
if foundtable then begin
inLookupCalcLink := true;
foundvalue := SyncLookupTable(Dataset,lookuptable,links, AMethod);
inLookupCalcLink := false;
if foundvalue then
otherfield := lookuptable.fieldbyname(wwDataSetGetDisplayField(Dataset,curfield.fieldname));
end;
parts.free;
end;
links.free;
result := otherfield;
end;
Function wwSetLookupField(dataSet: TDataSet; LinkedField: TField): boolean;
var links, parts: TStrings;
i,j: integer;
foundTable: Boolean;
lookupTable: TwwTable;
lookupFields, lookupLinks: TStrings;
lookupTables: TList;
Function getTablePrefix(tableName: string): string;
var APos: integer;
begin
APos:= 1;
result:= strGetToken(tableName, '.', APos);
end;
Function ignoreExtension(parts: TStrings): boolean;
begin
if parts.count>5 then begin
result:= (parts[parts.count-1]='N');
end
else result:= False;
end;
Function isSameTable(lookupTable: TwwTable; parts: TStrings): boolean;
begin
if ignoreExtension(parts) then
begin
result:=
(lookupTable.databaseName=parts[1]) and
(lookupTable.tableName=GetTablePrefix(parts[2]));
end
else begin
result:=
(lookupTable.databaseName=parts[1]) and
(lookupTable.tableName=parts[2]);
end
end;
{$ifdef win32}
Function PerformLookup: boolean; { 11/14/97}
begin
with LinkedField do begin
if LookupDataset is TTable then begin
result:= (LookupDataSet as TTable).FindKey([dataSet.FieldByName(KeyFields).asString]);
end
else begin
result:= LookupDataset.Locate(LookupKeyFields, dataSet.FieldByName(KeyFields).asString, [])
end
end
end;
{$endif}
begin
result:= False;
{$ifdef win32}
with LinkedField do begin
if Lookup then begin
if PerformLookup then
begin
if LookupDataSet.FieldByName(LookupResultField).asString<>linkedField.asString then
begin
LookupDataSet.edit;
LookupDataSet.FieldByName(LookupResultField).asString:= linkedField.asString;
result:= True;
end
end;
exit;
end
end;
{$endif}
if wwGetLookupFields(dataSet)=nil then exit;
parts:= TStringList.create;
links:= TStringList.create;
lookupTable:= nil; { Make compiler happy}
LookupLinks:= wwGetLookupLinks(dataSet);
LookupFields:= wwGetLookupFields(dataSet);
LookupTables:= wwGetLookupTables(dataset);
try
for i:= 0 to LookupFields.count-1 do begin
strbreakApart(LookupFields.Strings[i], ';', parts);
if not wwEqualStr(linkedField.fieldname, parts[0]) then continue;
{ Find corresponding table }
foundTable:= false;
for j:= 0 to LookupTables.count-1 do begin
lookupTable:= TwwTable(lookupTables.items[j]);
if isSameTable(lookupTable, parts) then
begin
foundTable:= (lowercase(LookupLinks.strings[i])=
lowercase(lookupTable.CalcLookupLinks));
if foundTable then break;
end
end;
if not foundTable then break;
strBreakApart(LookupLinks[i], ';', links);
with DataSet do begin
if LookupTable.readOnly then begin
LookupTAble.active:= False;
LookupTable.readonly:=False;
LookupTAble.active:= True;
end;
LookupTable.inLookupLink:= True; { Faster performance with inlookuplink }
result:= wwDoLookupTable(lookupTable, DataSet, links);
LookupTable.inLookupLink:= False;
if result and (LookupTable.FieldByName(parts[3]).asString<>linkedField.asString) then
begin
LookupTable.edit;
LookupTable.FieldByName(parts[3]).asString:= linkedField.asString;
{ LookupTable.post;} {7/4/97}
end
end;
end
finally
parts.free;
links.free;
end;
end;
procedure wwDataSetDoOnCalcFields(dataSet: TDataSet;
FLookupFields, FLookupLinks: TStrings;
lookupTables: TList);
var links, parts: TStrings;
i,j: integer;
fieldName: wwSmallString;
indexFields: string;
foundTable: Boolean;
lookupTable: TwwTable;
res: boolean;
Function getTablePrefix(tableName: string): string;
var APos: integer;
begin
APos:= 1;
result:= strGetToken(tableName, '.', APos);
end;
Function ignoreExtension(parts: TStrings): boolean;
begin
if parts.count>5 then begin
result:= (parts[parts.count-1]='N');
end
else result:= False;
end;
Function isSameTable(lookupTable: TwwTable; parts: TStrings): boolean;
begin
if ignoreExtension(parts) then
begin
result:=
(lookupTable.databaseName=parts[1]) and
(lookupTable.tableName=GetTablePrefix(parts[2]));
end
else begin
result:=
(lookupTable.databaseName=parts[1]) and
(lookupTable.tableName=parts[2]);
end
end;
begin
parts:= TStringList.create;
links:= TStringList.create;
lookupTable:= nil; { Make compiler happy}
{ upToDate keeps track if lookuptable needs to do a findKey }
for i:= 0 to LookupTables.count-1 do begin
lookupTable:= TwwTable(lookupTables.items[i]);
lookuptable.upToDate:= False;
end;
for i:= 0 to FLookupfields.count-1 do begin
strbreakApart(FLookupFields.Strings[i], ';', parts);
{ Find corresponding table }
foundTable:= false;
for j:= 0 to LookupTables.count-1 do begin
lookupTable:= TwwTable(lookupTables.items[j]);
if isSameTable(lookupTable, parts) then
begin
foundTable:= (lowercase(FLookupLinks.strings[i])=
lowercase(lookupTable.CalcLookupLinks));
if foundTable then break;
end
end;
{ Table not found so create it }
if not foundTable then begin
lookupTable:= TwwTable.create(dataSet);
try { In case unable to open table }
lookupTable.databaseName:= parts[1];
if ignoreExtension(parts) then lookupTable.tableName:= getTablePrefix(parts[2])
else lookupTable.tableName:= parts[2];
if parts.count>5 then begin
indexFields:= parts[5];
for j:= 6 to parts.count-2 do indexFields:= indexFields + ';' + parts[j];
lookupTable.indexName:= lookupTable.FieldsToIndex(indexFields);
end
else lookupTable.indexName:= parts[4]; { Set index name}
lookupTable.readOnly:= True; { Don't require write access }
lookupTable.active:= True;
except
continue; { Skip this lookup since table not found }
end;
lookupTables.add(lookupTable);
lookupTable.upToDate:= False;
lookupTable.CalcLookupLinks:= FLookupLinks.strings[i];
end
else if not lookupTable.active then
lookupTable.active:= True; { Force table to be active }
fieldName:= parts[3];
strBreakApart(FLookupLinks[i], ';', links);
{ Master Link field is gone, hide dependent field }
for j:= 0 to ((links.count-1) div 2) do begin
if not wwDataSetIsValidfield(dataSet, links[j*2]) then begin
dataset.fieldByName(parts[0]).visible:= False;
parts.free;
links.free;
exit;
end
end;
res:= False;
with DataSet do begin
if not LookupTable.UpToDate then begin
LookupTable.inLookupLink:= True; {12/4/96 }
res:= wwDoLookupTable(lookupTable, DataSet, links);
LookupTable.inLookupLink:= False; {12/4/96 }
LookupTable.upToDateRes:= res;
end;
if (res or (LookupTable.upToDate and LookupTable.upToDateRes)) then
begin
{$ifdef win32} { Support linked memo field display}
if LookupTable.FieldByName(fieldName) is TBlobField then
fieldbyName(parts[0]).text:= lookupTable.fieldByName(fieldName).asString
else
{$endif}
fieldbyName(parts[0]).text:= lookupTable.fieldByName(fieldName).text
end
else fieldbyName(parts[0]).text:= '';
end;
LookupTable.upToDate:= True;
end;
parts.free;
links.free;
end;
Function wwDataSetSyncLookupTable(dataSet: TDataSet; AlookupTable: TDataSet;
lookupFieldName: string; var fromField: string): boolean;
var links, parts: TStrings;
i,j, curpos: integer;
lookupFields, controlType, lookupLinks: TStrings;
lookupTable: TwwTable;
tempTblName1, tempTblName2: wwSmallString;
indexFields: string;
begin
parts:= TStringList.create;
links:= TStringList.create;
lookupFields:= wwGetLookupFields(dataSet);
controlType:= wwGetControlType(dataset);
lookupLinks:= wwGetLookupLinks(dataset);
lookupTable:= ALookupTable as TwwTable;
{ Remove lookup fields that are no longer there }
wwDataSetRemoveObsolete(dataSet, lookupfields, controlType, lookupLinks);
result:= False;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -