IGETLINE_GetLine() function to read text files | developer.brewmp.com IGETLINE_GetLine() function to read text files | developer.brewmp.com

Developer

IGETLINE_GetLine() function to read text files

Forums:

I need to preload a BREW database with data, and am attempting to use the IGETLINE_GetLine() function to read text files. Each comma-delimited line, would become a record.

When I compile, though, I get an "incompatible types - from 'struct _IFile *' to 'struct IGetLine *'" error, and the results are not coming through.

Basic code:
rv = IGETLINE_GetLine(pIFile, &gl, IGETLINE_LF);

Questions:
1. Has anyone used IGETLINE_GetLine() to retrieve "lines" of text from a file, and can you provide sample code?

2. Is there a better way?

Much appreciation!

Martin

IFile inherits from IAStream, not IGetLine. What you can do is create an ISourceUtil by calling CreateInstance with AEECLSID_SOURCEUTIL. Use this to get an IGetLine to access your IFile. First you need to cast your IFile* to an IAStream*, and then pass that to ISOURCEUTIL_SourceFromAStream(). Take the resulting ISource and pass that to ISOURCEUTIL_GetLineFromSource().

IFile inherits from IAStream, not IGetLine. What you can do is create an ISourceUtil by calling CreateInstance with AEECLSID_SOURCEUTIL. Use this to get an IGetLine to access your IFile. First you need to cast your IFile* to an IAStream*, and then pass that to ISOURCEUTIL_SourceFromAStream(). Take the resulting ISource and pass that to ISOURCEUTIL_GetLineFromSource().

Thanks Mark,
Obviously your coding skills are better than mine. Would you mind providing sample code?
Martin

Thanks Mark,
Obviously your coding skills are better than mine. Would you mind providing sample code?
Martin

markb wrote:IFile inherits from IAStream, not IGetLine. What you can do is create an ISourceUtil by calling CreateInstance with AEECLSID_SOURCEUTIL. Use this to get an IGetLine to access your IFile. First you need to cast your IFile* to an IAStream*, and then pass that to ISOURCEUTIL_SourceFromAStream(). Take the resulting ISource and pass that to ISOURCEUTIL_GetLineFromSource().
Can anyone provide sample code, to make this work?
Thanks,
Martin

markb wrote:IFile inherits from IAStream, not IGetLine. What you can do is create an ISourceUtil by calling CreateInstance with AEECLSID_SOURCEUTIL. Use this to get an IGetLine to access your IFile. First you need to cast your IFile* to an IAStream*, and then pass that to ISOURCEUTIL_SourceFromAStream(). Take the resulting ISource and pass that to ISOURCEUTIL_GetLineFromSource().
Can anyone provide sample code, to make this work?
Thanks,
Martin

Got it!!
//File => Stream => Source => Line
//Declair the variables
IFile * pIFile;
ISourceUtil * pisu;
ISource * pISource;
IGetLine * piGetLine;
GetLine gl;
int rv;
//Create a ISourceUtil
if (ISHELL_CreateInstance(pMe->a.m_pIShell,AEECLSID_SOURCEUTIL,(void **)&pisu))
return;
//Create an IFileMgr
if(ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_FILEMGR,(void **)&pMe->m_pIFileMgr))
return;
//Open the associated file
if ((pIFile = IFILEMGR_OpenFile(pMe->m_pIFileMgr,"aabbcc", _OFM_READ)) == NULL)
{
IFILEMGR_Release(pMe->m_pIFileMgr);
pMe->m_pIFileMgr = NULL;
return;

//Get a Source from a Stream, which was cast from a File
if (ISOURCEUTIL_SourceFromAStream(pisu,(IAStream*)pIFile,&pISource))
return;
//Get a GetLine from a Source
if (ISOURCEUTIL_GetLineFromSource(pisu, pISource, 5000, &piGetLine))
return;
//Get a line of text
rv = IGETLINE_GetLine(piGetLine, &gl, IGETLINE_LF);
/* if stream's not reached EOF */
if (!IGETLINE_Exhausted(rv)) {
//Print line!!
DBGPRINTF(gl.psz);

Martin

Got it!!
//File => Stream => Source => Line
//Declair the variables
IFile * pIFile;
ISourceUtil * pisu;
ISource * pISource;
IGetLine * piGetLine;
GetLine gl;
int rv;
//Create a ISourceUtil
if (ISHELL_CreateInstance(pMe->a.m_pIShell,AEECLSID_SOURCEUTIL,(void **)&pisu))
return;
//Create an IFileMgr
if(ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_FILEMGR,(void **)&pMe->m_pIFileMgr))
return;
//Open the associated file
if ((pIFile = IFILEMGR_OpenFile(pMe->m_pIFileMgr,"aabbcc", _OFM_READ)) == NULL)
{
IFILEMGR_Release(pMe->m_pIFileMgr);
pMe->m_pIFileMgr = NULL;
return;

//Get a Source from a Stream, which was cast from a File
if (ISOURCEUTIL_SourceFromAStream(pisu,(IAStream*)pIFile,&pISource))
return;
//Get a GetLine from a Source
if (ISOURCEUTIL_GetLineFromSource(pisu, pISource, 5000, &piGetLine))
return;
//Get a line of text
rv = IGETLINE_GetLine(piGetLine, &gl, IGETLINE_LF);
/* if stream's not reached EOF */
if (!IGETLINE_Exhausted(rv)) {
//Print line!!
DBGPRINTF(gl.psz);

Martin

good job ...
thanks..

good job ...
thanks..