BpcSMScriptLibrary 9
TStringGrid BPC Library
Language: Delphi 7 - 2007
Library provides routines for manipulating standard Delphi TStringGrids
////////////////////////////////////////////////////////////////////////////////////////// //////// TStringGrid BPC Library ////////////////////////////////////////////////////////////////////////////////////////// interface uses Classes, Types, Windows, Grids, DB; ////////////////////////////////////////////////// // TStringGrid BPC Library // Copy the selected rows from the grid into the clipboard as an smXMLPacket // Returns true if the clipboard is non-empty function bpcsmXMLSGGrid1Copy( Sender: TStringGrid) : boolean; // Copy the selected rows from the grid into the clipboard as a CSV packet // Returns true if the clipboard is non-empty function bpcCSVSGGrid1Copy( Sender: TStringGrid) : boolean; function bpcTABSGGrid1Copy( Sender: TStringGrid) : boolean; // Paste into the stringgrid as a CSV, TAB, XML string and return the string function bpcXMLSGGrid1Paste( Sender: TStringGrid) : TStringGrid; function bpcCSVSGGrid1Paste( Sender: TStringGrid) : TStringGrid; function bpcTABSGGrid1Paste( Sender: TStringGrid) : TStringGrid; // Write the stringgrid to a string as a CSV file and return the string function bpcSGWriteTABString(myStringGrid1: TStringGrid ) : string; // Write the stringgrid to a string as a CSV file and return the string function bpcSGWriteCSVString(myStringGrid1: TStringGrid ) : string; // Read in a CSV string - the first row MUST BE the headings. Strings are marked by "" and ',' are separators. // If bGrowFromLastRow is true, the file will be added to theend of the stringgrid without clearing, if bClearGrid is true all // columns will be cleared. FixedCols is the number of fixed columns from the left, while StartCol says which col to start // inserting data, while FixedColsList is a comma separated list of headings for the fixed columns portion (assuming the // startcol is after the fied cols. The CSVString is the CSV string to be imported. Returns the // stringgrid. function bpcSGLoadCSVString( myStringGrid1: TStringGrid; bGrowFromLastRow: boolean; bClearGrid: boolean; FixedCols, StartCol : integer; FixedColsList: string; CSVString: string): TStringGrid; overload; function bpcSGLoadTABString( myStringGrid1: TStringGrid; bGrowFromLastRow: boolean; bClearGrid: boolean; FixedCols, StartCol : integer; FixedColsList: string; CSVString: string): TStringGrid; overload; function bpcSGLoadDLMString( myStringGrid1: TStringGrid; bGrowFromLastRow: boolean; bClearGrid: boolean; FixedCols, StartCol : integer; FixedColsList: string; CSVString: string; Delim : char ): TStringGrid; overload; // Read in a CSV file - the first row MUST BE the headings. Strings are marked by "" and ',' are separators. // If bGrowFromLastRow is true, the file will be added to theend of the stringgrid without clearing, if bClearGrid is true all // columns will be cleared. FixedCols is the number of fixed columns from the left, while StartCol says which col to start // inserting data, while FixedColsList is a comma separated list of headings for the fixed columns portion (assuming the // startcol is after the fied cols. The FileName is the full path including filename to the csv file to be imported. Returns the // stringgrid. // eg: bpcSGLoadCSVFile( StringGrid1,(MergeRowsDSCBX.Checked), (not (MergeRowsDSCBX.Checked or MergeColsDSCBX.Checked)), 1, iff(MergeColsDSCBX.Checked,StringGrid1.ColCount,1), 'Status', FileName ); function bpcSGLoadCSVFile( myStringGrid1: TStringGrid; bGrowFromLastRow: boolean; bClearGrid: boolean; FixedCols, StartCol : integer; FixedColsList: string; FileName: string; QuotesAreDoubled : boolean=false ): TStringGrid; // Read in a dtatset - the fieild names are used as the headings of the grid. // If bGrowFromLastRow is true, the file will be added to theend of the stringgrid without clearing, if bClearGrid is true all // columns will be cleared. FixedCols is the number of fixed columns from the left, while StartCol says which col to start // inserting data, while FixedColsList is a comma separated list of headings for the fixed columns portion (assuming the // startcol is after the fied cols. The FileContents is the tdataset to be imported, which will be opened if necessary, // and repositioned at the first record after completion. Returns the stringgrid. // eg: bpcSGLoadFromTable( StringGrid1, (MergeRowsDSCBX.Checked), (not (MergeRowsDSCBX.Checked or MergeColsDSCBX.Checked)), 1, iff(MergeColsDSCBX.Checked,StringGrid1.ColCount,1), 'Status', FileContents ); function bpcSGLoadFromTable( myStringGrid1: TStringGrid; bGrowFromLastRow: boolean; bClearGrid: boolean; FixedCols, StartCol : integer; FixedColsList: string; FileContents: TDataSet): TStringGrid; // Fill a stringgrid column targcol with an (optionally incrementing) Mask of chars, or with GUID's, FromRow ToRowand and return the stringgrid // OVERLOADED FUNCTION // bpcSGFillRows( StringGrid1, FromRow, ToRow, MakeGUIDs, Mask, MaskChar, StartString, IncrementBy, OnlyNums ) // eg: bpcSGFillRows( StringGrid1, StringGrid1.Col, FromRow, ToRow, FillColumnDlg.UseGUIDCBX.Checked, FillColumnDlg.FillMask.Text, iff( FillColumnDlg.UseMaskCharCBX.Checked, iff( length(FillColumnDlg.MaskChar.Text)>0, FillColumnDlg.MaskChar.Text[1], '#'), #0 ), trim(FillColumnDlg.StartString.Text) ,iff( FillColumnDlg.IncrementCBX.Checked, FillColumnDlg.Incrementer.AsInteger, 0 ), FillColumnDlg.NumsOnlyCBX.Checked ); function bpcSGFillRows( myStringGrid1: TStringGrid; targcol : integer; FromRow, ToRow : integer; MakeGUIDs : boolean; Mask : string; MaskChar : char; StartString : string; IncrementBy : integer; OnlyNums : boolean ) : TStringGrid; overload; // Fill a stringgrid column targcol with GUID's FromRow ToRowand and return the stringgrid // OVERLOADED FUNCTION function bpcSGFillRows( myStringGrid1: TStringGrid; targcol : integer; FromRow, ToRow : integer; MakeGUIDs : boolean ) : TStringGrid; overload; // Write the stringgrid to a file called sFileName as a CSV file procedure bpcSGWriteCSVFile(myStringGrid1: TStringGrid; sFileName : string); // Insert a new blank col at curcol in a stringgrid col returning the stringgrid function bpcSGDeleteCol( myStringGrid1: TStringGrid; TargCol : integer ) : TStringGrid; // Delete the row at targrow in a stringgrid returning the stringgrid function bpcSGDeleteRow( myStringGrid1: TStringGrid; TargRow : integer ) : TStringGrid; // Delete the rows in a stringgrid preserving the header row if includeHeader is false and returning the stringgrid function bpcSGDeleteAllRows( myStringGrid1: TStringGrid; includeHeader : boolean ) : TStringGrid; // Insert a new blank col at curcol in a stringgrid col returning the stringgrid function bpcSGInsertCol( myStringGrid1: TStringGrid; CurCol : integer ) : TStringGrid; // Insert a new blank row at currow in a stringgrid row returning the stringgrid function bpcSGInsertRow( myStringGrid1: TStringGrid; CurRow : integer ) : TStringGrid; // Clear the contents of a stringgrid col at targcol function bpcSGClearCol( myStringGrid1: TStringGrid; targcol : integer ) : TStringGrid; // Clear the contents of a stringgrid row at targrow function bpcSGClearRow( myStringGrid1: TStringGrid; targrow : integer ) : TStringGrid; // Clear all the contents of a stringgrid preserving the header row if includeHeader is false and returning the stringgrid function bpcSGClearAllRows( myStringGrid1: TStringGrid; includeHeader : boolean ) : TStringGrid; // Returns the column index of the stringgrid col corresponding to the colname function bpcSGIndexOfSGCol( myStringGrid1: TStringGrid; colname : string ) : integer; // Returns true if the stringgrid row is empty function bpcSGIsEmptyRow( myStringGrid1: TStringGrid; targrow : integer ) : boolean; // Copies a StringGrid col fromcol tocol and returns the index of the col after the tocol function bpcSGCopyCol( myStringGrid1: TStringGrid; tocol, fromcol : integer ) : integer; // Copies a StringGrid row fromrow torow and returns the index of the row after the torow function bpcSGCopyRow( myStringGrid1: TStringGrid; torow, fromrow : integer ) : integer;