You can't use oActiveX:bOnEvent if used CreateOleObject(). This features return a handle and not a object.
If use oActiveX = TActiveX():New( oWnd, "GrFingerX.
") the result is better.
Code: Select all
/*
*
* Mais informacoes sobre ADO em
* http://www.microsoft.com/brasil/technet/Colunas/scriptcenter/resources/officetips/nov05/tips1103.mspx
*
*/
#include "Fivewin.ch"
#include "adodb.ch"
FUNCTION MAIN()
PUBLIC oRs
StrDatabase := [DBMRDELIVERY]
StrServer := [127.0.0.1]
StrPort := 3306
StrUserID := [root]
StrUserPWD := []
StrDriver := "MySQL ODBC 3.51 Driver"
StrTable := [TBCLIENTE]
StrField := [ddd]
StrField2 := [nome]
StrWhere := StrField+[="034"]
StrSqlCommand := [SELECT * FROM ] + StrTable + [ WHERE ] + StrWhere
ADO CONNECT ON StrServer ;
PORT StrPort ;
DATABASE StrDatabase ;
USER StrUserID ;
PASSWORD StrUserPWD ;
OPTIONS 35 ;
DRIVER StrDriver
ADO EXECUTE StrSqlCommand
ADO GOTOP
Browse( oRs )
ADO CLOSE
RETURN NIL
function WBrowseRecordSet( oRs, cStrField )
LOCAL oDlg, oBrw, nRec
DEFINE DIALOG oDlg SIZE 300, 300
@ 0, 0 LISTBOX oBrw FIELDS oRs:Fields( "nome" ):Value ;
HEADERS "Nome do Cliente" ;
FIELDSIZES 300 ;
ON RIGHT CLICK ( nRec := oRs:AbsolutePosition,;
oBrw:Report( "TWBrowse report", .T. ),;
oRs:MoveFirst(),;
oRs:Move( nRec - 1 ) )
oBrw:bLDblClick:= { |nRow,nCol| MsgStop( oRs:Fields( "BAIRRO" ):Value ) }
oBrw:nHeaderStyle := 2
oBrw:nHeaderHeight := 20
oBrw:nLineHeight := 15
oBrw:bLogicLen := { || oRs:RecordCount }
oBrw:bGoTop := { || oRs:MoveFirst() }
oBrw:bGoBottom := { || oRs:MoveLast() }
oBrw:bSkip := { | nSkip | ADOSkipper( oRs, nSkip ) }
oBrw:cAlias := "ARRAY"
ACTIVATE DIALOG oDlg;
ON INIT oDlg:SetControl( oBrw );
CENTER
RETURN NIL
function browse(oRs, bPrc, bAdc, bAlt, bExc, bImp, bSai)
LOCAL oDlg, oBrw, nRec
LOCAL aData := {}
LOCAL nFor
LOCAL oLbx, cItem
LOCAL btnPrc, btnAdc, btnAlt, btnExc, btnImp, btnsai
DEFAULT bPrc := { || RecPrc( oLbx ) },;
bAdc := { || RecInc( oLbx ) },;
bAlt := { || RecAlt( oLbx ) },;
bExc := { || RecExc( oLbx ) },;
bImp := { || RecImp( oLbx ) },;
bSai := { || oDlg2:End() }
DEFINE DIALOG oDlg2 From 0,0 To 800,1020 Pixel TITLE " ListBox da Tabela "
@ 05,15 listbox oBrw Fields oRs:Fields( "nome" ):Value, oRs:Fields( "fone" ):Value;
headers "Nome","Telefone";
fieldsizes 250,100 ;
pixel size 400,300 of odlg2
//oBrw:bLDblClick:= { |nRow,nCol| MsgStop( oRs:Fields( "apelido" ):Value ) }
oBrw:nHeaderStyle := 2
oBrw:nHeaderHeight := 20
oBrw:nLineHeight := 15
oBrw:bLogicLen := { || oRs:RecordCount }
oBrw:bGoTop := { || oRs:MoveFirst() }
oBrw:bGoBottom := { || oRs:MoveLast() }
oBrw:bSkip := { | nSkip | ADOSkipper( oRs, nSkip ) }
oBrw:cAlias := "ARRAY"
@ 18.7 , 05 button btnprc prompt "&Procurar" of oDlg2 size 40,12 Action RecPrc(oBrw)
@ 18.7 , 15 button btnadc prompt "&Adicionar" of oDlg2 size 40,12 Action RecInc(oBrw)
@ 18.7 , 25 button btnalt prompt "A<erar" of oDlg2 size 40,12 Action RecAlt(oBrw)
@ 18.7 , 35 button btnexc prompt "&Excluir" of oDlg2 size 40,12 Action RecExc(oBrw)
@ 18.7 , 45 button btnimp prompt "&Imprimir" of oDlg2 size 40,12
@ 18.7 , 55 button btnsai prompt "&Sair" of oDlg2 size 40,12 Action oDlg2:End()
ACTIVATE DIALOG oDlg2 //;
//ON INIT oDlg2:SetControl( oBrw );
//CENTER
RETURN NIL
function ADOSkipper( oRs, nSkip )
LOCAL nRec := oRs:AbsolutePosition
oRs:Move( nSkip )
IF oRs:EOF; oRs:MoveLast(); ENDIF
IF oRs:BOF; oRs:MoveFirst(); ENDIF
RETURN oRs:AbsolutePosition - nRec
//-----------------------------------------------------------
static function RecPrc(oLbx)
Local odlg1
Local cCodigo:=0
Local cSair:=" "
Local sql
DEFINE DIALOG oDlg1 From 0,0 To 160,250 PIXEL;
TITLE " Procura na Tabela em Access "
DEFINE FONT oFont NAME "FIXEDSYS" SIZE 10, -10 && Use a Nonproportional font
SET FONT OF oDlg1 TO oFont && so characters line up in Says
@ 02,05 say "Codigo : " OF oDlg1
@ 02.2,10 get cCodigo OF oDlg1 picture "9999" size 20,10
@ 02.7 , 10 button "Procurar" of oDlg1 size 40,12 action (cSair:="*",oDlg1:End())
ACTIVATE DIALOG oDlg1 centered
if cSair="*"
//locate for (odbf:cAlias)->field_0001 = cCodigo
criterio = "idpessoa Like '" + cCodigo + "%'"
//oRs:MoveFirst()
//oRs:Find criterio, 0, adSearchFoward
if eof()
msgAlert("NÆo encontrado !!!")
go top
endif
oLbx:Refresh()
endif
return nil
//-----------------------------------------------------------
static function RecInc(oLbx)
LOCAL odlg3
LOCAL cNome := space(40)
LOCAL cTelefone := space(14)
LOCAL cEndereco := space(45)
LOCAL cSair := " "
DEFINE DIALOG oDlg3 From 0,0 To 230,500 PIXEL TITLE " Inclusao na Tabela em Access "
DEFINE FONT oFont NAME "FIXEDSYS" SIZE 10, -10 && Use a Nonproportional font
SET FONT OF oDlg3 TO oFont && so characters line up in Says
@ 02,05 say "Nome_____: " OF oDlg3
@ 03,05 say "Telefone_: " OF oDlg3
@ 04,05 say "Endereco_: " OF oDlg3
//go bottom
//cCodigo := odbf:au_id+1
@ 02.2,10 get cNome OF oDlg3 picture "@!" size 150,10
@ 03.3,10 get cTelefone OF oDlg3 picture "(99)9999-9999" size 100,10 valid !empty(cNome)
@ 04.4,10 get cEndereco OF oDlg3 picture "@!" size 150,10
@ 04.7 , 15 button "Salvar" of oDlg3 size 40,12 action (cSair:="*",oDlg3:End())
ACTIVATE DIALOG oDlg3 centered
if cSair="*"
ADO APPEND BLANK
ADO REPLACE nome WITH cNome
ADO REPLACE fone WITH cTelefone
ADO REPLACE endereco WITH cEndereco
ADO COMMIT
oLbx:Refresh()
//oLbx:UpStable()
endif
return nil
//-----------------------------------------------------------
static function RecExc(oLbx)
if MsgYesNo( "Excluir este Registro ?", "Por Favor, confirme" )
ADO DELETE
ADO SKIP
oLbx:Refresh()
//oLbx:UpStable()
endif
return nil
//-----------------------------------------------------------
static function RecAlt(oLbx)
LOCAL odlg3
LOCAL cNome := oRs:Fields( "nome" ):Value
LOCAL cTelefone := oRs:Fields( "fone" ):Value
LOCAL cEstado := oRs:Fields( "endereco" ):Value
LOCAL cSair := " "
DEFINE DIALOG oDlg3 From 0,0 To 230,500 PIXEL TITLE " Inclusao na Tabela em Access "
DEFINE FONT oFont NAME "FIXEDSYS" SIZE 10, -10 && Use a Nonproportional font
SET FONT OF oDlg3 TO oFont && so characters line up in Says
@ 02,05 say "Nome_____: " OF oDlg3
@ 03,05 say "Telefone_: " OF oDlg3
@ 04,05 say "Endereco_: " OF oDlg3
//go bottom
//cCodigo := odbf:au_id+1
@ 02.2,10 get cNome OF oDlg3 picture "@!" size 150,10
@ 03.3,10 get cTelefone OF oDlg3 picture "(99)9999-9999" size 100,10 valid !empty(cNome)
@ 04.4,10 get cEndereco OF oDlg3 picture "@!" size 150,10
@ 04.7 , 15 button "Salvar" of oDlg3 size 40,12 action (cSair:="*",oDlg3:End())
ACTIVATE DIALOG oDlg3 centered
if cSair="*"
ADO APPEND BLANK
ADO REPLACE nome WITH cNome
ADO REPLACE fone WITH cTelefone
ADO REPLACE endereco WITH cEndereco
ADO COMMIT
oLbx:Refresh()
//oLbx:UpStable()
endif
return nil
//-----------------------------------------------------------
static function RecImp( oLbx )
/*
local oRpt
local n
local cAlias := If( oLbx != nil, oLbx:cAlias, Alias() )
REPORT oRpt TITLE "Report: " + cAlias ;
HEADER "Date: " + DToC( Date() ) + ", Time: " + Time() ;
FOOTER "Page: " + Str( oRpt:nPage, 3 ) ;
PREVIEW
if Empty( oRpt ) .or. oRpt:oDevice:hDC == 0
return nil
endif
for n = 1 to FCount()
oRpt:AddColumn( TrColumn():New( { FInfo1( cAlias, n ) },,;
{ FInfo2( cAlias, n ) },,,,,,,,,, oRpt ) )
next
ENDREPORT
ACTIVATE REPORT oRpt
GO TOP
*/
return nil
//--------------------------------------------
static function FInfo1( cAlias, n )
return { || ( cAlias )->( FieldName( n ) ) }
//-----------------------------------------------------------
static function FInfo2( cAlias, n )
return { || ( cAlias )->( FieldGet( n ) ) }
Function DbfDbt()
Return Nil
This samples works with MySQL, but you can modify to work with Access.
No i sent in private, i prefer to share this information.
Good work.