wpfuncs.pas

来自「详细说明:毕业论文中关于小型宾馆管理系统的详细设计毕 业论文中关于小型宾馆...」· PAS 代码 · 共 1,309 行 · 第 1/3 页

PAS
1,309
字号
     // Get bounds of array
     if VarArrayDimCount(olearray)=1 then begin
        // One-dimensional
        dim1:=TRUE;
        high_col:=VarArrayHighBound(olearray, 1);
        low_col:=VarArrayLowBound(olearray, 1);
     end else if VarArrayDimCount(olearray)=2 then begin
        // Two-dimensional
        dim1:=FALSE;
        high_col:=VarArrayHighBound(olearray, 1);
        low_col:=VarArrayLowBound(olearray, 1);
     end else begin
        // Not an array!
        //ShowMessage('Array has invalid number of dimensions:'+IntToStr(VarArrayDimCount(olearray)));
        Result:=nil;
        Exit;
     end;

     // Array information
     // Copy rows into scratch pad
      rows:=row;
      records:='';
      for cols:=low_col to high_col do begin
      if dim1 then begin
                if VarType(olearray[cols])=varNull then
                   Records:=''
                else if VarType(olearray[cols])=varInteger then
                   Records:=IntToStr(olearray[cols])
                else if VarType(olearray[cols])=varDate then begin
                   Records:=DateTimeToStr(olearray[cols]);
              
                end else if VarType(olearray[cols])=varBoolean then begin
                   if olearray[cols] then Records:='TRUE'
                   else Records:='FALSE';
                end else
                   Records:=olearray[cols];
      end else begin
                if VarType(olearray[cols, rows])=varNull then
                   Records:=''
                else if VarType(olearray[cols, rows])=varInteger then
                   Records:=IntToStr(olearray[cols, rows])
                else if VarType(olearray[cols, rows])=varDate then begin
                      Records:=DateTimeToStr(olearray[cols, rows]);

                end else if VarType(olearray[cols, rows])=varBoolean then begin
                   if olearray[cols, rows] then Records:='TRUE'
                   else Records:='FALSE';
                end else
                    Records:=olearray[cols, rows];
      end;

      StringList.Add(Records);

      end;

    Result:=StringList;

end;

//Get  column records
function Get_ColRecords(olearray: Variant;const col:integer): TStrings;
var high_row, low_row: Integer;
    cols, rows: Integer;
    Records: String;
    dim1: Boolean;
    StringList:Tstrings;
begin

    try
      StringList := TStringList.Create;
    except
      Result:=nil;
      Exit;
    end;

    // Check array
    if VarIsEmpty(olearray) then begin
        // Not an array!
        ShowMessage('Array is empty');
        Result:=nil;
        Exit;
    end;

     // Get bounds of array
     if VarArrayDimCount(olearray)=1 then begin
        // One-dimensional
        dim1:=TRUE;
        high_row:=0;
        low_row:=0;
     end else if VarArrayDimCount(olearray)=2 then begin
        // Two-dimensional
        dim1:=FALSE;
        high_row:= VarArrayHighBound(olearray, 2);
        low_row := VarArrayLowBound(olearray, 2);
     end else begin
        // Not an array!
        ShowMessage('Array has invalid number of dimensions:'+IntToStr(VarArrayDimCount(olearray)));
        Result:=nil;
        Exit;
     end;

     // Array information
     // Copy rows into scratch pad
     cols:=col;
     for rows:=low_row to high_row do begin
         records:='';
             if dim1 then begin
                if VarType(olearray[cols])=varNull then
                   Records:=''
                else if VarType(olearray[cols])=varInteger then
                   Records:=IntToStr(olearray[cols])
                else if VarType(olearray[cols])=varDate then
                   Records:=DateTimeToStr(olearray[cols])
                else if VarType(olearray[cols])=varBoolean then begin
                   if olearray[cols] then Records:='TRUE'
                   else Records:='FALSE';
                end else
                   Records:=olearray[cols];
       end else begin
                if VarType(olearray[cols, rows])=varNull then
                   Records:=''
                else if VarType(olearray[cols, rows])=varInteger then
                   Records:=IntToStr(olearray[cols, rows])
                else if VarType(olearray[cols, rows])=varDate then
                   Records:=DateTimeToStr(olearray[cols, rows])
                else if VarType(olearray[cols, rows])=varBoolean then begin
                   if olearray[cols, rows] then Records:='TRUE'
                   else Records:='FALSE';
                end else
                    Records:=olearray[cols, rows];

        end;

         StringList.Add(records);

     end;

     Result:=StringList;

end;

//All Records
function Get_RowColRecords(olearray: Variant;const high_row,low_row,high_col,low_col:integer): TStrings;
var
    cols, rows: Integer;
    row: String;
    dim1: Boolean;
    StringList:Tstrings;
begin

     try
       StringList := TStringList.Create;
     except
       Result:=nil;
       Exit;
     end;

     // Check array
     if VarIsEmpty(olearray) then begin
        // Not an array!
        //ShowMessage('Array is empty');
        Result:=nil;
        Exit;
     end;

     // Get bounds of array
     if VarArrayDimCount(olearray)=1 then begin
        // One-dimensional
        dim1:=TRUE;
     end else if VarArrayDimCount(olearray)=2 then begin
        // Two-dimensional
        dim1:=FALSE;
     end else begin
        // Not an array!
        //ShowMessage('Array has invalid number of dimensions:'+IntToStr(VarArrayDimCount(olearray)));
        Result:=nil;
        Exit;
     end;

     // Array information
     // Copy rows into scratch pad
     for rows:=low_row to high_row do begin
         row:='';
         for cols:=low_col to high_col do begin
             if dim1 then begin
                if VarType(olearray[cols])=varNull then
                   row:=row+'NULL'
                else if VarType(olearray[cols])=varInteger then
                   row:=row+IntToStr(olearray[cols])
                else if VarType(olearray[cols])=varDate then
                   row:=row+DateTimeToStr(olearray[cols])
                else if VarType(olearray[cols])=varBoolean then begin
                   if olearray[cols] then row:=row+'TRUE'
                   else row:=row+'FALSE';
                end else
                   row:=row+'['+olearray[cols]+']';
             end else begin
                if VarType(olearray[cols, rows])=varNull then
                   row:=row+'NULL'
                else if VarType(olearray[cols, rows])=varInteger then
                   row:=row+IntToStr(olearray[cols, rows])
                else if VarType(olearray[cols, rows])=varDate then
                   row:=row+DateTimeToStr(olearray[cols, rows])
                else if VarType(olearray[cols, rows])=varBoolean then begin
                   if olearray[cols, rows] then row:=row+'TRUE'
                   else row:=row+'FALSE';
                end else
                    row:=row+olearray[cols, rows];
             end;
             if cols<>high_col then row:=row+', ';
         end;
         StringList.Add(row);

     end;

     Result:=StringList;

end;
// Add listview columns
function ListViewAddColumns(captions: array of String; widths: array of Integer;ListView:TListView):Boolean;
var lc: TListColumn;
    i: Integer;
begin

   try
     // Check args
     if (Low(captions)<>Low(widths)) or (High(captions)<>High(widths)) then begin
        Result:=FALSE;
        Exit;
     end;
     listView.Columns.Clear;
     // Create columns
     for i:=Low(captions) to High(captions) do begin
         lc:=ListView.Columns.Add;
         lc.Caption:=captions[i];
         lc.Width:=Widths[i];
     end;
   except
     Result:=FALSE;
     Exit;
   end;

   Result:=TRUE;

end;
// Add Listview records
function ListViewAddRows(rows: OleVariant;ListView:TListView): Integer;
var ListItem: TListItem;
    row, col, hc, lc, hr, lr: Integer;
begin
     // Valid data?
     if (not ValidSelectResult(rows)) or
        (not GetArrayBounds(rows, hc, lc, hr, lr)) then begin
        // No rows
        Result:= -1;
        Exit;
     end;
     ListView.Items.Clear;
     // Initialise controls
     for row:=lr to hr do begin
         ListItem:=ListView.Items.Add;
         if VarType(rows[lc, row])=varNull then
            ListItem.Caption:=''
         else if VarType(rows[lc, row])=varEmpty then
            ListItem.Caption:=''
         else if VarType(rows[lc, row])=varInteger then
            ListItem.Caption:=IntToStr(rows[lc, row])
         else if VarType(rows[lc, row])=varDate then
            ListItem.Caption:=DateTimeToStr(rows[lc, row])
         else if VarType(rows[lc, row])=varBoolean then begin
            if rows[lc, rows] then ListItem.Caption:='Yes'
            else ListItem.Caption:='No';
         end else
            ListItem.Caption:=rows[lc, row];

         for col:=lc + 1 to hc do begin
             //showmessage(inttostr(col)+rows[col,row]);
             if VarType(rows[col, row])=varNull then
                ListItem.SubItems.Add('')
             else if VarType(rows[col, row])=varEmpty then
                ListItem.SubItems.Add('')
             else if VarType(rows[col, row])=varInteger then
                ListItem.SubItems.Add(IntToStr(rows[col, row]))
             else if VarType(rows[col, row])=varDate then
                ListItem.SubItems.Add(DateTimeToStr(rows[col, row]))
             else if VarType(rows[col, row])=varBoolean then begin
                if rows[col, row] then ListItem.SubItems.Add('Yes')
                else ListItem.SubItems.Add('No')
             end else
                ListItem.SubItems.Add(rows[col, row]);
         end;
     end;

     // Done
     Result:=(hr - lr) + 1;
end;
// Delete listvier row
function ListViewDeleteRow(key: String;ListView:TListView): Integer;
var i: Integer;
    ListItem: TListItem;
begin
     // List control
     for i:=0 to ListView.Items.Count - 1 do begin
         ListItem:=ListView.Items[i];
         if ListItem.Caption=key then begin
            ListView.Items.Delete(i);
            Result:=1;
            Exit;
         end;
     end;

     // Not found
     Result:= -1;
end;

// Copy strings to olevariant
procedure CopyStrToOle(const Strlist:TStrings;var StrOle: OleVariant);
var
    i: Integer;
begin
     // Initialise
     StrOle:=Unassigned;

     // Now copy them to an OLE variant
   try
     if Strlist.Count > 0 then begin
        StrOle:=VarArrayCreate([0, Strlist.Count - 1], varOLEStr);
        for i:=0 to Strlist.Count - 1 do StrOle[i]:=Strlist[i];
     end else
        StrOle:=Unassigned;
   except
       StrOle:=Unassigned;
   end;
end;
// Get type according as description
//
// Rows: All Data
// TableColumns :which table
// DesColumns : description  column
// TypeColumns : type column
// description: condition
// Return -> type
//
// Example:
// i:=GetDesToType(rows,Description.text,AS_DOCUMENT_TYPES_COLUMNS,
//              AS_DOCUMENT_TYPES_DESCRIPTION,AS_DOCUMENT_TYPES_DOCUMENT_TYPE);}
//
function GetDesToType(const rows:Olevariant;
  description: WideString;TableColumns,DesColumns,TypeColumns:integer): Integer;
var
  i,lr, lc, hr, hc: Integer;
  lDes:Tstrings;
  lType:Tstrings;
begin
     lDes:=nil;
     lType:=nil;
  try
     lDes:=TstringList.Create;
     lType:=TstringList.Create;
     // Valid data? If not simply clear the edit fields
     if (not ValidSelectResult(rows, tableColumns)) or
        (not GetArrayBounds(rows, hc, lc, hr, lr)) then begin
        // No rows
        Result:=-1;
        Exit;
    end;

     lDes:=Get_ColRecords(rows,DesColumns);
     lType:=Get_ColRecords(rows,typeColumns);
     for i:=0 to lDes.Count-1 do begin
         if lDes.Strings[i]=description then begin
            Result:=StrToInt(lType.Strings[i]);
            lDes.Free;
            lType.Free;
            Exit;
         end;
     end;
  except
        Result:=-1;
        lDes.Free;
        lType.Free;
        Exit;
  end;
     lDes.Free;
     lType.Free;
     Result:=-1;
end;
// Get description as type
//
// Rows: All Data
// TableColumns :which table
// DesColumns : description column
// Return -> description value
//
// Example:
// Result:=GetTypeToDes(rows,AS_DOCUMENT_TYPES_COLUMNS,AS_DOCUMENT_TYPES_DESCRIPTION);
//
function GetTypeToDes(const rows:OleVariant;
  TableColumns,DesColumns:integer): WideString;
var
  lr, lc, hr, hc: Integer;
begin
  try
     // Valid data? If not simply clear the edit fields
     if (not ValidSelectResult(rows, TableColumns)) or
        (not GetArrayBounds(rows, hc, lc, hr, lr)) then begin
        // No rows
        Result:='';
        Exit;
     end;
     // Single row
     Result:=rows[lc + DesColumns, 0];
  except
        Result:='';
        Exit;
  end;

end;

// Get integer field value according as string field
//
// Rows: All Data
// TableColumns :which table
// StrColumns : which string column
// IntColumns : which integer column
// str: condition
// Return -> integer
//
// Example: AS_DocumentTpes
// Result:=GetIntWhereStr(rows,Description.Text,AS_DOCUMENT_TYPES_COLUMNS,
//        AS_DOCUMENT_TYPES_DESCRIPTION,AS_DOCUMENT_TYPES_DOCUMENT_TYPE);
//
function GetIntWhereStr(const rows:Olevariant;
       str: WideString;TableColumns,StrColumns,IntColumns:integer): Integer;
var
  i,lr, lc, hr, hc: Integer;
  lStr:Tstrings;

⌨️ 快捷键说明

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