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

📄 wwcommon.pas

📁 InfoPower_Studio 2007 v5.0.1.3 banben
💻 PAS
📖 第 1 页 / 共 5 页
字号:
         for i:= 0 to count-1 do begin
            strBreakApart(strings[i], ';', parts);
            if parts[0]=curField.fieldName then begin
               if parts.count<5 then continue;

               found:=True;
               databaseName:= parts[1];
               tableName:= parts[2];
               displayFieldName:= parts[3];

               joins:= wwGetLookupLinks(gridTable).Strings[i];
               break;
            end
         end
      end;

      if not found then begin
         databaseName:= wwGetDatabaseName(gridTable);
         tableName:= '';
         displayFieldName:= '';
         joins:= '';
      end;

      parts.free;

end;

{ Win95 for Bitmap support }
Function wwDataSetLookupDisplayField(
   curField: TField; var LookupValue: string; var DisplayField: TField): boolean;
var
    j, APos: integer;
    lookupTable: TwwTable;
    databasename, tableName, displayFieldName, joins: string;
    lookupTables: TList;
begin
    displayField:= curField;
    result:= False;
    if (curField=Nil) or (curField.dataSet=nil) then exit;
    if (wwGetLookupTables(curField.dataset)=nil) then exit;

    GetLookupFields(curField, databasename, tableName, displayFieldName, joins);
    LookupTables:= wwGetLookupTables(curField.dataset);

    for j:= 0 to LookupTables.count-1 do begin
       lookupTable:= TwwTable(lookupTables.items[j]);
       if (lookupTable.databaseName=databaseName) and
          (lookupTable.tableName=tableName) then
       begin
          if (lowercase(joins)=lowercase(lookupTable.CalcLookupLinks)) then
          begin
             DisplayField:= lookupTable.FieldByname(DisplayFieldName);
             APos:= 1;
             LookupValue:= curField.dataset.FieldByName(strGetToken(joins, ';', APos)).asString;
             result:= lookupTable.wwFindKey([lookupValue]);
             exit;
          end
       end
    end;

end;

Function wwDoLookupTable(ALookupTable : TTable;  DataSet: TDataset; links: TStrings) : boolean;
var res: boolean;
    lookupTable: TwwTable;
begin
   res:= False;
   lookupTable:= AlookupTable as TwwTable;
   with DataSet do begin
      if LookupTable.IndexFieldCount=0 then begin
         result:= LookupTable.wwFindRecord(FieldByName(links[0]).asString, links[1],
{                            FieldByName(links[1]).FieldName,}  { 1/17/96 - FieldByName ref. is incorrect}
                            mtExactMatch, False);
         exit;
      end;

      case (links.count) of
         2:  res:= lookupTable.wwFindKey(
                [FieldByName(links[0]).asString]);

         4:  res:= lookupTable.wwFindKey(
                      [FieldByName(links[0]).asString,
                       FieldByName(links[2]).asString] );

         6:  res:= lookupTable.wwFindKey(
                      [FieldByName(links[0]).asString,
                       FieldByName(links[2]).asString,
                       FieldByName(links[4]).asString] );

         8:  res:= lookupTable.wwFindKey(
                      [FieldByName(links[0]).asString,
                       FieldByName(links[2]).asString,
                       FieldByName(links[4]).asString,
                       FieldByName(links[6]).asString] );

        10:  res:= lookupTable.wwFindKey(
                      [FieldByName(links[0]).asString,
                       FieldByName(links[2]).asString,
                       FieldByName(links[4]).asString,
                       FieldByName(links[6]).asstring,
                       FieldByName(links[8]).asString] );

        12:  res:= lookupTable.wwFindKey(
                      [FieldByName(links[0]).asString,
                       FieldByName(links[2]).asString,
                       FieldByName(links[4]).asString,
                       FieldByName(links[6]).asstring,
                       FieldByName(links[8]).asstring,
                       FieldByName(links[10]).asString] );
         else;
      end;
   end;

   result:= res;
end;

Function wwisNonBDEField(thisField: TField): boolean;
begin
   {$ifdef win32}
   result:=  thisfield.calculated or thisfield.lookup;
   {$ifdef wwDelphi3Up}
   if (not result) and (thisField.dataset<>nil) then
      result:= not wwIsClass(thisField.dataset.classType, 'TBDEDataSet'); {9/20/97 - 3rd party engine}
   {$endif}
   {$else}
   result:=  thisfield.calculated;
   {$endif}
end;

Function wwisNonPhysicalField(thisField: TField): boolean;
begin
   {$ifdef win32}
   result:=  thisfield.calculated or thisfield.lookup;
   {$else}
   result:=  thisfield.calculated;
   {$endif}
end;

Procedure wwConvertFieldToParam(OtherField:TField;var AFilterParam:TParam;AFilterFieldBuffer: PChar);
var
   tempInt: integer;
   tempdouble: double;
   tempSmallInt: smallint;
  {$ifdef win32}
   tempTimeStamp: TTimeStamp;
  {$else}
   tempTime:LongInt;
   tempDate:LongInt;
   tempDateTime:double;
  {$endif}
   tempWordBool: WordBool;
  {tempBCD : fmtBCD;}
begin
   if OtherField=nil then { 11/7/98 - If nil (i.e. ClientDataSet), then return blank  }
   begin
      strPLCopy(AFilterFieldBuffer, '', 32767);
      AFilterParam.SetData(AFilterFieldBuffer);
      exit;
   end;

   case OtherField.DataType of
      ftString, ftMemo: { 11/3/97 - Treat ftMemo as ftString }
        begin
          strPLCopy(AFilterFieldBuffer, OtherField.asString, 32767);
          AFilterParam.SetData(AFilterFieldBuffer);
        end;
      ftSmallint,ftWord:
        begin
          tempSmallInt:= OtherField.asInteger;
          move(tempSmallInt, AFilterFieldBuffer^, 2);
          AFilterParam.SetData(AFilterFieldBuffer);
        end;
      ftInteger, ftAutoInc: { 8/7/99 }
        begin
          tempInt:= OtherField.asInteger;
          move(tempInt, AFilterFieldBuffer^, 4);
          AFilterParam.SetData(AFilterFieldBuffer);
        end;
      ftFloat,ftCurrency:
        begin
          tempDouble:= OtherField.asFloat;
          move(tempDouble, AFilterFieldBuffer^, 8);
          AFilterParam.SetData(AFilterFieldBuffer);
        end;
      ftBoolean:
        begin
          tempWordBool:= OtherField.asBoolean;
          move(tempWordBool, AFilterFieldBuffer^, 2); { 9/16/98 - WordBool is 2 bytes }
          AFilterParam.SetData(AFilterFieldBuffer);
        end;
      ftTime:
        begin
         {$ifdef win32}
           tempTimeStamp:= DateTimeToTimeStamp(OtherField.asDateTime);
           move(tempTimeStamp.time, AFilterFieldBuffer^, 4);
           AFilterParam.SetData(AFilterFieldBuffer);
         {$else}
           tempTime := Round(Frac(OtherField.AsDateTime) * MSecsPerDay);
           move(tempTime, AFilterFieldBuffer^, 4);
           AFilterParam.SetData(AFilterFieldBuffer);
         {$endif}
        end;
      ftDate:
        begin
         {$ifdef win32}
           tempTimeStamp:= DateTimeToTimeStamp(OtherField.asDateTime);
           move(tempTimeStamp.date, AFilterFieldBuffer^, 4);
           AFilterParam.SetData(AFilterFieldBuffer);
         {$else}
           tempDate := Trunc(OtherField.AsDateTime);
           move(tempDate, AFilterFieldBuffer^, 4);
           AFilterParam.SetData(AFilterFieldBuffer);
         {$endif}
        end;

      {$ifdef wwDelphi6Up}
      ftTimeStamp,
      {$endif}
      ftDateTime:
        begin
         {$ifdef win32}
           tempDouble:= TimeStampToMSecs(DateTimeToTimeStamp(OtherField.asDateTime));
           move(tempDouble, AFilterFieldBuffer^, sizeof(double));
           AFilterParam.SetData(AFilterFieldBuffer);
         {$else}
           tempDateTime := OtherField.AsDateTime * MSecsPerDay;
           move(tempDateTime, AFilterFieldBuffer^, sizeof(double));
           AFilterParam.SetData(AFilterFieldBuffer);
         {$endif}
        end;
     {$ifdef wwDelphi6Up}
     ftFMTBCD:
        begin
           CurrToBCD((OtherField as TFMTBCDField).asFloat,
                     pBcd(AFilterFieldBuffer)^, 32, 4);
           AFilterParam.SetData(AFilterFieldBuffer);
        end;
    {$endif}
     ftBCD: { 11/21/99 - Support BCD }
        begin
           {$ifdef wwDelphi5Up}
           CurrToBCD((OtherField as TBCDField).asFloat,
                     pBcd(AFilterFieldBuffer)^, 32, 4);
           {$else} { Comment out as need Delphi 5 to compile this coce }
//           CurrToBCD((OtherField as TBCDField).asFloat,
//                     pFmtBcd(AFilterFieldBuffer)^, 32, 4);
           {$endif}
           AFilterParam.SetData(AFilterFieldBuffer);
        end;
   end;
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 getTablePrefix(tableName: string): string;
var APos: integer;
begin
   APos:= 1;
   result:= strGetToken(tableName, '.', APos);
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;

    Function SyncLookupTable(DataSet:TDataset;Alookuptable: TDataSet;links:TStrings;
       Method: TMethod): boolean;
    var res:boolean;
        lookupTable:TwwTable;
    begin
       res := False;
       if not (Alookuptable is TwwTable) then begin
         { Only 1 field lookups for non TwwTables }
         {$ifdef win32}
         if Method.data=nil then { 11/7/98 - ClientDataSet lookups pass method.data=nil}
         begin
            // 7/4/02 - If isnull then use .Value, as .AsString can lead
            // to run-time exception
            if dataset.fieldbyname(links[0]).isNull then
            begin
              result:= ALookupTable.Locate(links[1],
                     DataSet.FieldByName(links[0]).Value, [])
            end
            else
              result:= ALookupTable.Locate(links[1],
                     DataSet.FieldByName(links[0]).asString, [])
         end
         else begin
            // 6/23/03 - Check for null lookup value
            if dataset.fieldbyname(links[0]).isNull then
            begin
              result:= ALookupTable.Locate(links[1],
                    wwGetFilterFieldValue(method, links[0]).Value, []);
            end
            else
              result:= ALookupTable.Locate(links[1],
                    wwGetFilterFieldValue(method, links[0]).asString, []);
         end;
         {$else}
         result:= False;
         {$endif}
         exit;
       end;

       lookupTable := Alookuptable as TwwTable;
       case (links.count) of
         2: begin
            res := TwwTable(lookuptable).wwFindKey(
              [(wwGetFilterFieldValue(method, links[0])).asString]);
            end;
         4: begin
            res := TwwTable(lookuptable).wwFindKey(
                  [wwGetFilterFieldValue(Method,links[0]).asString,
                   wwGetFilterFieldValue(Method,links[2]).asString]);
            end;
         6: begin
            res := TwwTable(lookuptable).wwFindKey(
                      [wwGetFilterFieldValue(method,links[0]).asString,
                       wwGetFilterFieldValue(method,links[2]).asString,
                       wwGetFilterFieldValue(method,links[4]).asString] );
            end;
         8: begin
            res := TwwTable(lookuptable).wwFindKey(
                      [wwGetFilterFieldValue(method,links[0]).asString,
                       wwGetFilterFieldValue(method,links[2]).asString,
                       wwGetFilterFieldValue(method,links[4]).asString,
                       wwGetFilterFieldValue(method,links[6]).asString] );
            end;
        10: begin
            res := TwwTable(lookuptable).wwFindKey(
                      [wwGetFilterFieldValue(method,links[0]).asString,
                       wwGetFilterFieldValue(method,links[2]).asString,
                       wwGetFilterFieldValue(method,links[4]).asString,
                       wwGetFilterFieldValue(method,links[6]).asString,
                       wwGetFilterFieldValue(method,links[8]).asString] );
            end;
        12: begin
            res := TwwTable(lookuptable).wwFindKey(
                      [wwGetFilterFieldValue(method,links[0]).asString,
                       wwGetFilterFieldValue(method,links[2]).asString,
                       wwGetFilterFieldValue(method,links[4]).asString,
                       wwGetFilterFieldValue(method,links[6]).asString,
                       wwGetFilterFieldValue(method,links[8]).asString,
                       wwGetFilterFieldValue(method,links[10]).asString] );
            end;
         else;
      end;
      result := res;
    end;

Function wwDataSet_GetFilterLookupField(dataSet: TDataSet; curfield: TField; AMethod: TMethod): TField;
var OtherField : TField;
    links: TStrings;
    foundvalue: bool;
    foundtable: bool;
    lookuplinks:string;
    mylookuplinks:Tstrings;
    lookuptable:TwwTable;
    lookupfields:Tstrings;
    lookuptables:TList;

⌨️ 快捷键说明

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