Formula One - Delphi

xiaoxiao2021-03-06  56

A function output from DBGRID to Formula One, with Formula One 6.1, some attribute Delphi comes with Formula One 3.0 does not support, at least to install Formula One 5.0 or higher.

You can modify this function and pass it directly to the DataSet to do parameters, and use DBGRID to make parameters to take into account the alignment, column width of DBGRID on F1BOOK.

The function is as follows:

/ / -------------------------------------------------------------------------------------------- ----------------------------- // Function Name: WriteDataFromDBGRID // Function Description: Output a DBGRID content to F1Book // Entrance parameters: adbGrid - Data Grid // ASTARTROW - Data Start Dip // ASTARTCOL - Data Start Column // Af1Book - Available Data Formula One Book // Example: WriteDataFromDBGRID (DBGRID1, 2, 2, F1Book1); / examples / DBGrid1 content above is output from F1Book1 two rows and two columns from // author: JoyHero // -------------------------- -------------------------------------------------- -procedure WriteDataFromDBGrid (ADBGrid: TDBGrid; AStartRow, AStartCol: Integer; AF1Book: TF1Book); var i, j: Integer; iColCount, iRowCount: Integer; cfTemp: F1CellFormat; iUnvisibleColCount: Integer; begin with AF1Book do begin // get the data column Number iColcount: = adbGrid.columns.count; irowcount: = adbGrid.datasource.dataset.recordcount; IunvisibleColcount: = 0;

// Fill the title column for j: = 0 to icolcount-1 do begin entryrc [ASTARTROW, ASTARTCOL J]: = adbGrid.columns [j] .title.caption; colwidth [ASTARTCOL J]: = adbGrid.columns [j ] .Width * 50;

// Fill data if adbgrid.datasource.DataSet.DataSource.DataSet Do Begin first; i: = ASTARTROW 1; While NOT EOF Do Begin for J: = 0 to icolcount-1 Do Begin Entryrc [i ASTARTCOL J]: = adbgrid.columns [j] .field.displaytext; end; negl; inc;

/ / Set the title column to display, the font is bold setSelection (Astartrow, Astartcol, Astartrow, AstartCol Icolcount-1); Halign: = f1halignCenter; fontbold: = true; // Set the alignment of the data column according to DBGRID try for j: = 0 to iColCount-1 do begin SetSelection (AStartRow 1, AStartCol j, AStartRow iRowCount, AStartCol j); Case ADBGrid.Columns [j] .Alignment of taLeftJustify: hAlign: = F1HAlignLeft; taRightJustify: Halign: = f1halignright; Tacenter: Halign: = f1haligncenter; end; end; except

// delete the column non-display DBGrid try for j: = 0 to iColCount-1 do begin if not ADBGrid.Columns [j] .Visible then begin SetSelection (AStartRow, AStartCol j-iUnvisibleColCount, AStartRow iRowCount, AStartCol j- IunvisibleColcount; editdelete (f1shiffhorizontal); IunvisibleColcount: = IUNVISIBLECOLCOUNT 1; END; End; Except End;

// Draw Border SetSelection (AStartRow, AStartCol, AStartRow iRowCount, AStartCol iColCount-1-iUnvisibleColCount); cfTemp: = GetCellFormat; cfTemp.BorderStyle [F1TopBorder]: = F1BorderThin; cfTemp.BorderStyle [F1LeftBorder]: = F1BorderThin; cfTemp. BorderStyle [F1BottomBorder]: = F1BorderThin; cfTemp.BorderStyle [F1RightBorder]: = F1BorderThin; cfTemp.BorderStyle [F1HInsideBorder]: = F1BorderThin; cfTemp.BorderStyle [F1VInsideBorder]: = F1BorderThin; SetCellFormat (cfTemp); end; end; Formula One support Directly connect the ODBC database and return query results, the following is a small example: put a F1Book on the form (I use Formula One 6.1) and a button Botton1, Botton1 Click event is as follows:

procedure TForm1.Button1Click (Sender: TObject); var myConnect: F1ODBCConnect; myQuery: F1ODBCQuery; begin myConnect: = CoF1ODBCConnect.Create; // Create an ODBC connection myConnect.ConnectStr: = ''; // ConnectStr set is empty, then the pop-up ODBC window Select F1Book1.odbcconnectex (MyConnect, true); // Open ODBC connection MyQuery: = Cof1odbcQuery.create; // Create a query myQuery.QueryStr: = '; // Setting ConnectStr is empty, popup SQL statement creation window You can also set up CONNECTSTR to query the query statement f1book1.odbcQueryex (MyQuery, 1, 1, true); //, return the result to F1Book F1book1.odbcdisconnect; // Disconnect ODBC connection END; run Let's click on the button, select an ODBC data source, then enter a "Select * from ..." query statement, you can see that the F1Book has returned the query data set.

The above two programs are passed under Win98, Delphi 5, Formula One 6.1.

转载请注明原文地址:https://www.9cbs.com/read-71125.html

New Post(0)