Strange Error with xbrowse-restorestate

Re: Strange Error with xbrowse-restorestate

Postby Enrico Maria Giordano » Fri Nov 05, 2010 8: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: Select all  Expand view
#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
User avatar
Enrico Maria Giordano
 
Posts: 8711
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Strange Error with xbrowse-restorestate

Postby gkuhnert » Fri Nov 05, 2010 9: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
User avatar
gkuhnert
 
Posts: 274
Joined: Fri Apr 04, 2008 1:25 pm
Location: Aachen - Germany // Kerkrade - Netherlands

Re: Strange Error with xbrowse-restorestate

Postby gkuhnert » 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
User avatar
gkuhnert
 
Posts: 274
Joined: Fri Apr 04, 2008 1:25 pm
Location: Aachen - Germany // Kerkrade - Netherlands

Re: Strange Error with xbrowse-restorestate

Postby Enrico Maria Giordano » 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
User avatar
Enrico Maria Giordano
 
Posts: 8711
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Strange Error with xbrowse-restorestate

Postby Enrico Maria Giordano » 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
User avatar
Enrico Maria Giordano
 
Posts: 8711
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Strange Error with xbrowse-restorestate

Postby gkuhnert » 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
User avatar
gkuhnert
 
Posts: 274
Joined: Fri Apr 04, 2008 1:25 pm
Location: Aachen - Germany // Kerkrade - Netherlands

Re: Strange Error with xbrowse-restorestate

Postby Enrico Maria Giordano » Fri Nov 05, 2010 11:25 am

Try this:

Code: Select all  Expand view
#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
User avatar
Enrico Maria Giordano
 
Posts: 8711
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Strange Error with xbrowse-restorestate

Postby gkuhnert » 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
User avatar
gkuhnert
 
Posts: 274
Joined: Fri Apr 04, 2008 1:25 pm
Location: Aachen - Germany // Kerkrade - Netherlands

Re: Strange Error with xbrowse-restorestate

Postby Enrico Maria Giordano » Sun Nov 07, 2010 2:30 pm

Please try this too and let me know if it works correctly for you:

Code: Select all  Expand view
#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
User avatar
Enrico Maria Giordano
 
Posts: 8711
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Strange Error with xbrowse-restorestate

Postby gkuhnert » Mon Nov 08, 2010 1: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
User avatar
gkuhnert
 
Posts: 274
Joined: Fri Apr 04, 2008 1:25 pm
Location: Aachen - Germany // Kerkrade - Netherlands

Re: Strange Error with xbrowse-restorestate

Postby Enrico Maria Giordano » Mon Nov 08, 2010 3: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
User avatar
Enrico Maria Giordano
 
Posts: 8711
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Strange Error with xbrowse-restorestate

Postby gkuhnert » Mon Nov 08, 2010 3: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: Select all  Expand view
/*
 * $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
User avatar
gkuhnert
 
Posts: 274
Joined: Fri Apr 04, 2008 1:25 pm
Location: Aachen - Germany // Kerkrade - Netherlands

Re: Strange Error with xbrowse-restorestate

Postby Enrico Maria Giordano » Mon Nov 08, 2010 3:30 pm

As you can see:

Code: Select all  Expand view
#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
User avatar
Enrico Maria Giordano
 
Posts: 8711
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Strange Error with xbrowse-restorestate

Postby frose » Tue Nov 09, 2010 6:35 pm

Gilbert, James,

understanding now - with the help of Mr. Rao - why my application crashes when calling '::oBrw: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 :D

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
User avatar
frose
 
Posts: 392
Joined: Tue Mar 10, 2009 11:54 am
Location: Germany, Rietberg

Re: Strange Error with xbrowse-restorestate

Postby James Bott » Tue Nov 09, 2010 7:08 pm

Frank,

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

Regards,
James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Previous

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 90 guests