FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Strange Error with xbrowse-restorestate
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Strange Error with xbrowse-restorestate
Posted: Fri Nov 05, 2010 08:51 AM
James Bott wrote:As Gilbert discovered, some cState values are too large to be retrieved from an INI file, thus they are truncated. Gilbert has not yet been able to compile a revised C program to correct the problem. But, it will happen as soon as we can get some guidance from a C programmer.


This is a working sample:

Code (fw): Select all Collapse
#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL cContent := "[Test]" + CRLF + "Test=" + REPLICATE( "x", 2048 )

    MEMOWRIT( "test.ini", cContent )

    ? LEN( GETPVPROFSTRING( "Test", "Test", "", ".\test.ini" ) )

    RETURN NIL


#pragma BEGINDUMP

#include "windows.h"
#include "hbapi.h"
#include "clipapi.h"


#ifdef __HARBOUR__
   HB_FUNC( GETPVPROFSTRING )
#else
   HB_FUNC( GETPVPROFS )
#endif
{
   BYTE bBuffer[ 4096 ];
   DWORD wLen;

   wLen = GetPrivateProfileString( hb_parc( 1 ),     // Section
                                   IF( ISCHAR( 2 ), hb_parc( 2 ), 0 ),   // Entry
                                   hb_parc( 3 ),     // Default
                                   ( char * ) bBuffer,        // Destination Buffer
                                   sizeof( bBuffer ) - 1,   // M x Len
                                   hb_parc( 4 ) );   // INI File
   if( wLen )
      hb_retclen( ( char * ) bBuffer, wLen );
   else
      hb_retc( "" );
}

#pragma ENDDUMP


EMG
Posts: 274
Joined: Fri Apr 04, 2008 01:25 PM
Re: Strange Error with xbrowse-restorestate
Posted: Fri Nov 05, 2010 09:36 AM
Enrico,

thanks for your help. But I still get following error:

Error E2342 EHO.PRG 2334: Type mismatch in parameter 'lpKeyName' (wanted 'const signed char *', got 'int') in function HB_FUN_GETPVPROFSTRING


(I am using BCC582)
Best Regards,

Gilbert Kuhnert
CTO Software GmbH
http://www.ctosoftware.de
Posts: 274
Joined: Fri Apr 04, 2008 01:25 PM
Re: Strange Error with xbrowse-restorestate
Posted: Fri Nov 05, 2010 10:05 AM
And in your stand-alone example I had to comment the line #include clipapi.h (because of double declaration of pword and word)

But I still get the same error:
Error E2342 READINI.PRG 36: Type mismatch in parameter 'lpKeyName' (wanted 'const signed char *', got 'int') in function HB_FUN_GETPVPROFSTRING
Best Regards,

Gilbert Kuhnert
CTO Software GmbH
http://www.ctosoftware.de
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Strange Error with xbrowse-restorestate
Posted: Fri Nov 05, 2010 10:34 AM
gkuhnert wrote:Enrico,

thanks for your help. But I still get following error:

Error E2342 EHO.PRG 2334: Type mismatch in parameter 'lpKeyName' (wanted 'const signed char *', got 'int') in function HB_FUN_GETPVPROFSTRING


(I am using BCC582)


I don't see lpKeyName anywhere in my sample. :-)

EMG
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Strange Error with xbrowse-restorestate
Posted: Fri Nov 05, 2010 10:37 AM
gkuhnert wrote:And in your stand-alone example I had to comment the line #include clipapi.h (because of double declaration of pword and word)


Sorry, I don't get any double declaration error.

EMG
Posts: 274
Joined: Fri Apr 04, 2008 01:25 PM
Re: Strange Error with xbrowse-restorestate
Posted: Fri Nov 05, 2010 11:11 AM
Enrico Maria Giordano wrote:
I don't see lpKeyName anywhere in my sample. :-)


I don't see lpKeyName either. I thought it is something within c, but I can't tell...
Just compiled your example. With clipapi.h I get following errors:

Error E2238 d:\xharbour\include\clipdefs.h 86: Multiple declaration for 'WORD'
Error E2344 d:\bcc582\include\windef.h 155: Earlier declaration of 'WORD'
Error E2238 d:\xharbour\include\clipdefs.h 88: Multiple declaration for 'PWORD'
Error E2344 d:\bcc582\include\windef.h 164: Earlier declaration of 'PWORD'


without the clipapi.h the error I mentioned with lpKeyName (but I don't know what lpKeyName means)

Are you using BCC582 too?
Best Regards,

Gilbert Kuhnert
CTO Software GmbH
http://www.ctosoftware.de
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Strange Error with xbrowse-restorestate
Posted: Fri Nov 05, 2010 11:25 AM
Try this:

Code (fw): Select all Collapse
#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL cContent := "[Test]" + CRLF + "Test=" + REPLICATE( "x", 2048 )

    MEMOWRIT( "test.ini", cContent )

    ? LEN( GETPVPROFSTRING( "Test", "Test", "", ".\test.ini" ) )

    RETURN NIL


#pragma BEGINDUMP

#include "windows.h"
#include "hbapi.h"
//#include "clipapi.h"


#define IF(x,y,z) ((x)?(y):(z))


#ifdef __HARBOUR__
   HB_FUNC( GETPVPROFSTRING )
#else
   HB_FUNC( GETPVPROFS )
#endif
{
   BYTE bBuffer[ 4096 ];
   DWORD wLen;

   wLen = GetPrivateProfileString( hb_parc( 1 ),     // Section
                                   IF( ISCHAR( 2 ), hb_parc( 2 ), 0 ),   // Entry
                                   hb_parc( 3 ),     // Default
                                   ( char * ) bBuffer,        // Destination Buffer
                                   sizeof( bBuffer ) - 1,   // M x Len
                                   hb_parc( 4 ) );   // INI File
   if( wLen )
      hb_retclen( ( char * ) bBuffer, wLen );
   else
      hb_retc( "" );
}

#pragma ENDDUMP


EMG
Posts: 274
Joined: Fri Apr 04, 2008 01:25 PM
Re: Strange Error with xbrowse-restorestate
Posted: Fri Nov 05, 2010 12:01 PM

Enrico,

great job, it works! (and the result is 2048)

Thank you very much :)

Best Regards,

Gilbert Kuhnert
CTO Software GmbH
http://www.ctosoftware.de
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Strange Error with xbrowse-restorestate
Posted: Sun Nov 07, 2010 02:30 PM
Please try this too and let me know if it works correctly for you:

Code (fw): Select all Collapse
#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL cContent := "[Test]" + CRLF + "Test=" + REPLICATE( "x", 2048 )

    MEMOWRIT( "test.ini", cContent )

    ? LEN( GETPVPROFSTRING( "Test", "Test", "", ".\test.ini" ) )

    RETURN NIL


#pragma BEGINDUMP

#include "windows.h"
//#include "hbapi.h"
#include "clipapi.h"


//#define IF(x,y,z) ((x)?(y):(z))


#ifdef __HARBOUR__
   HB_FUNC( GETPVPROFSTRING )
#else
   HB_FUNC( GETPVPROFS )
#endif
{
   BYTE bBuffer[ 4096 ];
   DWORD wLen;

   wLen = GetPrivateProfileString( hb_parc( 1 ),     // Section
                                   IF( ISCHAR( 2 ), hb_parc( 2 ), 0 ),   // Entry
                                   hb_parc( 3 ),     // Default
                                   ( char * ) bBuffer,        // Destination Buffer
                                   sizeof( bBuffer ) - 1,   // M x Len
                                   hb_parc( 4 ) );   // INI File
   if( wLen )
      hb_retclen( ( char * ) bBuffer, wLen );
   else
      hb_retc( "" );
}

#pragma ENDDUMP


EMG
Posts: 274
Joined: Fri Apr 04, 2008 01:25 PM
Re: Strange Error with xbrowse-restorestate
Posted: Mon Nov 08, 2010 01:24 PM
Enrico,

in this example I get following errors: (exactly like before)

Error E2238 d:\xharbour\include\clipdefs.h 86: Multiple declaration for 'WORD'
Error E2344 d:\bcc582\include\windef.h 155: Earlier declaration of 'WORD'
Error E2238 d:\xharbour\include\clipdefs.h 88: Multiple declaration for 'PWORD'
Error E2344 d:\bcc582\include\windef.h 164: Earlier declaration of 'PWORD'
Best Regards,

Gilbert Kuhnert
CTO Software GmbH
http://www.ctosoftware.de
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Strange Error with xbrowse-restorestate
Posted: Mon Nov 08, 2010 03:06 PM

So you are using the wrong clipdefs.h version (you must use the [x]Harbour one) or have the wrong BCC configuration file (BCC32.CFG, can I see it?).

EMG

Posts: 274
Joined: Fri Apr 04, 2008 01:25 PM
Re: Strange Error with xbrowse-restorestate
Posted: Mon Nov 08, 2010 03:22 PM
bcc32.cfg:
-I"d:\bcc582\include;d:\bcc582\include\dinkumware"
-L"d:\bcc582\lib"


and the only clipdefs.h I could find in my directories is in the d:\xharbour-Directory

Code (fw): Select all Collapse
/*
 * $Id: clipdefs.h,v 1.8 2009/11/09 09:38:44 marchuet Exp $
 */

/*
 * Harbour Project source code:
...
 */

/* DON'T USE THIS FILE FOR NEW HARBOUR C CODE */

/* This file is provided to support some level of */
/* Harbour compatibility for old Clipper C extension code */

#ifndef _CLIPDEFS_H
#define _CLIPDEFS_H

#include "hbapi.h"

/* Old types */

typedef BYTE    byte;
typedef USHORT  quant;
typedef BOOL    Boolean;

/* New types */

typedef BYTE *  BYTEP;
typedef BYTEP   PBYTE;
typedef BYTEP   BYTEPP;

typedef SHORT * SHORTP;
typedef SHORTP  PSHORT;

typedef USHORT * USHORTP;

#ifndef __WATCOMC__
typedef USHORTP PUSHORT;
#endif

#if !(defined(HB_OS_WIN) && defined(HB_OS_WIN_USED))
   #if !( ( defined(__DMC__) || defined(__MINGW32__) || defined(__POCC__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__) ) && defined(HB_THREAD_SUPPORT))
      typedef unsigned int WORD;
      typedef WORD *  WORDP;
      typedef WORDP   PWORD;
   #endif
#endif

typedef LONG *  LONGP;
typedef LONGP   PLONG;

typedef ULONG * ULONGP;
typedef ULONGP  PULONG;

typedef ULONG   DWORD;
typedef DWORD * DWORDP;
typedef DWORDP  PDWORD;

typedef BOOL *  BOOLP;
typedef BOOLP   PBOOL;

typedef void *  NEARP;
typedef NEARP * NEARPP;

#if !(defined(HB_OS_WIN) && defined(HB_OS_WIN_USED))
   typedef void *  FARP;
   typedef FARP *  FARPP;
   typedef FARP    VOIDP;
   typedef FARP    PVOID;
#endif

typedef void *  HANDLE;
typedef HB_ERRCODE IHELP;
typedef HB_ERRCODE ICODE;

/* default func ptr -- USHORT return, USHORT param */
typedef USHORT  ( * FUNCP )( USHORT param, ...);
typedef FUNCP * FUNCPP;

#define HIDE    static
#define CLIPPER HARBOUR

#ifndef NIL
   #define NIL     '\0'
#endif
#ifndef NULL
   #define NULL    0
#endif

#endif /* _CLIPDEFS_H */
Best Regards,

Gilbert Kuhnert
CTO Software GmbH
http://www.ctosoftware.de
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Strange Error with xbrowse-restorestate
Posted: Mon Nov 08, 2010 03:30 PM
As you can see:

Code (fw): Select all Collapse
#if !(defined(HB_OS_WIN) && defined(HB_OS_WIN_USED))
   #if !( ( defined(__DMC__) || defined(__MINGW32__) || defined(__POCC__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__) ) && defined(HB_THREAD_SUPPORT))
      typedef unsigned int WORD;
      typedef WORD *  WORDP;
      typedef WORDP   PWORD;
   #endif
#endif


WORD and PWORD are defined only if a series of conditions are true. Can you check why they evaluate true in your sistem? At least your Borland compiler should define __BORLANDC__ and this would set the entire second condition to false.

EMG
Posts: 392
Joined: Tue Mar 10, 2009 11:54 AM
Re: Strange Error with xbrowse-restorestate
Posted: Tue Nov 09, 2010 06:35 PM
Gilbert, James,

understanding now - with the help of Mr. Rao - why my application crashes when calling '::Refresh()' in the method RestoreState().

Mr. Rao stated here: viewtopic.php?f=3&t=20202#p107192
1. SetAlign() method is intended to be used for changing alignment during runtime. Recommended way to set alignment of columns, during initial definition of xbrowse, is by oCol:nDataStrAlign := <nAlign>.

2. From the error code, it is understood that data source is not yet specified ( in command mode ALIAS, ARRAY, RECORDSET, etc or in oops style, SetRDD, SetArray, etc ) before defining columns and properties.

The same statement is valid for RestoreState(), so:

      ACTIVATE WINDOW oWnd ON INIT( oBrw:RestoreState( cState ) ) VALID ( cState := oBrw:SaveState(), .T. )

does the job :-)

Now it's much easier to change the browse from one to another layout by user action, because we can restore the browse state during runtime!
Windows 11 Pro 22H2 22621.1848

Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384

Harbour 3.2.0dev (r2008190002)

FWH 23.10 x86
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Strange Error with xbrowse-restorestate
Posted: Tue Nov 09, 2010 07:08 PM

Frank,

Thanks for the summary and example. I am recording it in my notes.

Regards,
James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10

Continue the discussion