Amiguinho
Outra dica e é a que estou usando sempre é a de colocar tais informações em arquivos externos e nunca mais dentro do codigo de forma compilada.
Crie um modulo onde vc possa armazenar as impressoras, dando-lhes nomes e direções, salve em .DBFs ou arquivos .INI, deva uma dica usando .INI.
Código: Selecionar todos
VTERM:=UPPER(NETNAME())
//
lGrava := .F. // Qdo .F. grava se nao existir, Qdo .T. grava mesmo que exista, reescrevendo
cPath := CurDrive() + ":\" + Curdir() + "\"
cQueLPT1 := Upper(VerifyINI( VTERM, "LPT" , "LPT1" , cPath+"sistema.ini",lGrava))
cQualCaminho := Upper(VerifyINI( VTERM, "CAMINHO", "\\SERVIDOR\TERMINAL1", cPath+"sistema.ini",lGrava))
//
IF !(VTERM="CREDIARIO_01")
NETREDIR( cQueLPT1, cQualCaminho )
ENDIF
COPY FILE("FICHA.PRN") TO ("LPT2")
[code]
Outro exemplo de uso de arquivos .INI:
[code]
function LimpaSpool()
cEmiteMotor := Upper(VerifyINI("SISTEMA","Emite_Motor","WAPI",cPath+"pos"+M->CAIXA+".ini",.F.))
if valtype(PRNcFile) <> "C"
return .t.
endif
CONTADOR := ADIR( "*.ecf" )
IF CONTADOR != 0
DECLARE TXT_NOMES[ CONTADOR ]
ADIR( "*.ecf", TXT_NOMES )
FOR CONTADOR := 1 TO LEN( TXT_NOMES )
//WaitRun("write " + TXT_NOMES[CONTADOR] + "/p" )
do case
case cEmiteMotor = "COMMAND.COM"
WaitRun("command.com /c copy /b " + PRNcFile + " LPT1" , 0 )
case cEmiteMotor = "WRITE"
WaitRun("write " + PRNcFile + " /p" )
case cEmiteMotor = "WAPI"
WaitRun( [WAPI -PRINT:"]+PRNcPort+[";]+PRNcFile+[;"Impressao";RESULTA.TXT], 7 )
endcase
//WAITRUN("command.com /c copy /b " + TXT_NOMES[CONTADOR] + " lpt1" , 0 )
SysWait(2)
if file( TXT_NOMES[CONTADOR] )
FERASE( TXT_NOMES[CONTADOR] )
endif
NEXT
ENDIF
SysRefresh()
return .t.
[code]
Funcao VerifyINI simplificada:
[code]
function VerifyINI( _section_, _entry_, _var_, _inifile_, _grava_ )
oIni := TIni():New( _inifile_ )
if _grava_ = .t.
oIni:Set( _section_, _entry_, _var_ )
endif
return oIni:Get( _section_, _entry_, _var_, _var_ )
Codigo fonte da classe .INI, pondendo ser usada qualquer outra forma de escrita em arquivos .INI:
Código: Selecionar todos
#include "FiveWin.ch"
#include "DLL.ch"
//----------------------------------------------------------------------------//
CLASS TIni
DATA cIniFile, lAutoSet
METHOD New( cIniFile ) CONSTRUCTOR
METHOD Get( cSection, cEntry, uDefault, uVar )
METHOD Set( cSection, cEntry, uValue )
METHOD Sections()
METHOD DelSection( cSection ) INLINE DelIniSection( cSection, ::cIniFile )
METHOD DelEntry( cSection, cEntry ) INLINE ;
DelIniEntry( cSection, cEntry, ::cIniFile )
ENDCLASS
//----------------------------------------------------------------------------//
METHOD New( cIniFile ) CLASS TIni
DEFAULT cIniFile := ""
if ! Empty( cIniFile ) .and. At( ".", cIniFile ) == 0
cIniFile += ".ini"
endif
::cIniFile = cIniFile
::lAutoSet = .t.
return Self
//----------------------------------------------------------------------------//
METHOD Get( cSection, cEntry, uDefault, uVar ) CLASS TIni
local cType := ValType( If( uDefault != nil, uDefault, uVar ) )
if Empty( ::cIniFile )
if cType == "N"
uVar = GetProfInt( cSection, cEntry, uDefault )
else
uVar = GetProfString( cSection, cEntry, cValToChar( uDefault ) )
endif
else
if cType == "N"
uVar = GetPvProfInt( cSection, cEntry, uDefault, ::cIniFile )
else
uVar = GetPvProfString( cSection, cEntry, cValToChar( uDefault ),;
::cIniFile )
endif
endif
do case
case cType == "D"
uVar = CToD( uVar )
case cType == "L"
uVar = ( Upper( uVar ) == ".T." )
endcase
if uVar == uDefault .and. ::lAutoSet
::Set( cSection, cEntry, uDefault)
endif
return uVar
//----------------------------------------------------------------------------//
METHOD Set( cSection, cEntry, uValue ) CLASS TIni
if Empty( ::cIniFile )
WriteProfString( cSection, cEntry, cValToChar( uValue ) )
else
WritePProString( cSection, cEntry, cValToChar( uValue ), ::cIniFile )
endif
return nil
//----------------------------------------------------------------------------//
METHOD Sections() CLASS TIni
local cBuffer := Space( 4096 ), p, aSec:={}
// cBuffer := Left( cBuffer, GetPvPrfSe( @cBuffer, 4095, ::cIniFile ) )
p = GetPvPrfSe( @cBuffer, 4095, ::cIniFile )
cBuffer = Left( cBuffer, p )
while ( p := At( Chr( 0 ), cBuffer ) ) > 1
AAdd( aSec, Left( cBuffer, p - 1 ) )
cBuffer = SubStr( cBuffer, p + 1 )
enddo
return aSec
//----------------------------------------------------------------------------//
DLL32 FUNCTION GetPvPrfSe(cBuffer AS LPSTR, nSize AS DWORD, cIni AS LPSTR) AS DWORD PASCAL ;
FROM "GetPrivateProfileSectionNamesA" LIB "Kernel32.dll"