PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: Chris Cullen on November 23, 2004, 08:18:49 AM

Title: Trouble with ADO and XP SP2
Post by: Chris Cullen on November 23, 2004, 08:18:49 AM
I have tried to use the examples that Jose posted for the MS Flex Grid control.  Unfortunately, the OCX he uses is not on my machine.

Anyway,  I have completely failed to use a ADO.Connection object in place of the one Jose used.  I also wonder why the example does not use the 'built in' ADO support - it does not say much for it if it is ignored in this example  :?

Is it possible to use the FF ADO in place of the one used in the tutorial.  Does anyone have an example of binding a DataGrid or Hierachial Flex Grid to a ADO record set object in FF (or powerbasic for that!)

Thanks
Title: Trouble with ADO and XP SP2
Post by: Jose Roca on November 23, 2004, 12:18:31 PM
Quote
I also wonder why the example does not use the 'built in' ADO support - it does not say much for it if it is ignored in this example
Because I made these examples to show how to use OCXs with FireFly, not how to use ADO. For that reason, I used the Microsoft Common Dialogs in other examples instead of FF_OpenFileDialog and FF_SaveFileDialog.

To connect an HierarchicalFlexGrid control with and ADO recordset, follow the steps in the example related to the grid control and, instead of using an Adodc control, paste the following code.

In the General section paste

Global lpConnection As Dword
Global lpRecordset As Dword


In the FORM1_WM_CREATE function paste

  Local vIdx As Variant
  Local vVar As Variant
  Local ConStr As String    
  Local SqlStr As String
  Local lpDataSource As Dword

  ' Change the width of the columns
  vIdx = 0 : vVar =  300 : Object Let DISPATCH_FORM1_GRID.ColWidth(vIdx) = vVar
  vIdx = 1 : vVar = 3500 : Object Let DISPATCH_FORM1_GRID.ColWidth(vIdx) = vVar
  vIdx = 2 : vVar =  600 : Object Let DISPATCH_FORM1_GRID.ColWidth(vIdx) = vVar
  vIdx = 3 : vVar = 1200 : Object Let DISPATCH_FORM1_GRID.ColWidth(vIdx) = vVar
  vIdx = 4 : vVar =  600 : Object Let DISPATCH_FORM1_GRID.ColWidth(vIdx) = vVar
  vIdx = 5 : vVar =  850 : Object Let DISPATCH_FORM1_GRID.ColWidth(vIdx) = vVar
  vIdx = 6 : vVar = 1800 : Object Let DISPATCH_FORM1_GRID.ColWidth(vIdx) = vVar
  vIdx = 7 : vVar = 1000 : Object Let DISPATCH_FORM1_GRID.ColWidth(vIdx) = vVar
  vIdx = 8 : vVar = 3000 : Object Let DISPATCH_FORM1_GRID.ColWidth(vIdx) = vVar
   
  ' Change the foreground and background colors
  vVar = %BLACK           : Object Let DISPATCH_FORM1_GRID.ForeColor = vVar
  vVar = RGB(255,255,235) : Object Let DISPATCH_FORM1_GRID.BackColor = vVar
   
  ' Creates an ADO connection object
  lpConnection = FF_AdoCreateObject("ADODB.Connection")
  If IsFalse lpConnection Then GoTo Terminate
  ' Connection string - Remember to change the path of the Data Source
  ConStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\FFADO\Biblio.mdb"
  ' Sets the connection string
  FF_AdoConnection_SetConnectionString(lpConnection, Constr)
  ' Opens the database
  FF_AdoConnection_Open(lpConnection)
  If FF_AdoResult Then GoTo Terminate

  ' Creates an ADO recordset object
  lpRecordset = FF_AdoCreateObject("ADODB.Recordset")
  If IsFalse lpRecordset Then GoTo Terminate
  ' Opens the recordset
  SqlStr = "SELECT * FROM Titles ORDER BY Title"
  FF_AdoRecordset_Open(lpRecordset, SqlStr, lpConnection, %adOpenKeyset, %adLockOptimistic, %adCmdText)
  If FF_AdoResult Then GoTo Terminate

  ' Get the Datasource property of the recordset
  lpDataSource = FF_AdoRecordset_GetDataSource(lpRecordset)
  If IsFalse lpDataSource Then GoTo Terminate  
  ' Convert it into a dispatch variant
  FF_AdoMakeDispatchVariant lpDataSource, vVar
  ' Bind the grid to the recordset
  Object Set DISPATCH_FORM1_GRID.DataSource = vVar
  vVar = EMPTY

Terminate:


And in the Function FORM1_WM_DESTROY function paste

  ' Close and release the recordset
  If lpRecordset Then
     FF_AdoRecordset_Close(lpRecordset)
     FF_AdoRelease(lpRecordset)
  End If
  ' Close and release the connection
  If lpConnection Then
     FF_AdoConnection_Close(lpConnection)
     FF_AdoRelease(lpConnection)
  End If
Title: Trouble with ADO and XP SP2
Post by: Chris Cullen on November 23, 2004, 01:07:22 PM
QuoteBecause I made these examples to show how to use OCXs with FireFly, not how to use ADO. For that reason, I used the Microsoft Common Dialogs in other examples instead of FF_OpenFileDialog and FF_SaveFileDialog.

Fair comment!

Well, all I can say is Thank You - Big Time!

I was messing around all day with this getting nowhere fast.  Your code worked great!  You are obviously very cleaver!  I was not really sure where the OBJECT SET,LET,GET,CALL stuff ends and calling your functions begins, and this example has really helped there!  

Finally, and you must promise not to laugh, I had a MSFlexGrid on my form and NOT a HierarchicalFlexGrid and I wondered why setting the datasource kept giving me a 'unknown member' error.  I wish Microsoft would have an error message like 'Duh?' or 'Your Kidding - Right?', which would have helped me to find my error!  :oops:

Many, Many thanks for all your help.  :lol:
Title: Trouble with ADO and XP SP2
Post by: Jose Roca on November 23, 2004, 01:22:21 PM
PB Automation and wrapper functions can be mixed if you know how to do it. PB automation uses object or dispatch variables and the wrapper functions use pointers. You can retrieve a pointer from a dispatch variable using OBJPTR and you can convert a pointer to a dispatch variable using TB_MakeDispatchVariant (FF_AdoMakeDispatchVariant in the ADO examples).

I have added this example to the MSHFlexGrid tutorial and I will also post others using PB automation so everyone will be able to use his prefered technique.