HMG 3.4.3

HMG Unicode versions 3.1.x related

Moderator: Rathinagiri

rakesh1201
Posts: 1
Joined: Sun Feb 12, 2017 9:02 am

Re: GRID CONTROL problem

Post by rakesh1201 » Sun Feb 12, 2017 9:48 am

Huiyi,

I think there is a solution to your problem. Your code has been modified as follows:

#include <hmg.ch>
Function Main
PRIVATE n // declare a private variable

MAKEDATA()
DEFINE WINDOW MAIN AT 213 , 425;
WIDTH 482 HEIGHT 350 VIRTUAL WIDTH Nil VIRTUAL HEIGHT Nil ;
TITLE "Test grid control" ICON NIL MAIN CURSOR NIL

DEFINE LABEL Label_1
ROW 30
COL 40
WIDTH 120
HEIGHT 24
VALUE "Enter filter value"
FONTNAME "Arial"
FONTSIZE 9
TOOLTIP ""
ACTION Nil
AUTOSIZE .F.
BACKCOLOR NIL
FONTCOLOR NIL
RIGHTALIGN .T.
END LABEL

DEFINE TEXTBOX Text_1
ROW 30
COL 180
WIDTH 120
HEIGHT 24
FONTNAME "Arial"
FONTSIZE 9
TOOLTIP ""
CASECONVERT NONE
BACKCOLOR NIL
FONTCOLOR NIL
INPUTMASK "!!!!!"
FORMAT Nil
VALUE ""
END TEXTBOX

DEFINE BUTTON Button_1
ROW 30
COL 330
WIDTH 100
HEIGHT 28
ACTION FILTER(MAIN.TEXT_1.VALUE)
CAPTION "FILTER"
FONTNAME "Arial"
FONTSIZE 9
TOOLTIP ""
PICTURE Nil
PICTALIGNMENT TOP
END BUTTON

DEFINE GRID Grid_1
ROW 80
COL 30
WIDTH 420
HEIGHT 210
ITEMS { {""} }
VALUE Nil
WIDTHS {200,200 }
HEADERS {"field1","field2"}
FONTNAME "Arial"
FONTSIZE 9
TOOLTIP ""

BACKCOLOR NIL
FONTCOLOR NIL
HEADERIMAGES Nil
ROWSOURCE "test"
COLUMNFIELDS {"AA","BB"}
ALLOWAPPEND .F.
ALLOWDELETE .F.
BUFFERED .F.
DYNAMICDISPLAY Nil
ONSAVE Nil
LOCKCOLUMNS 0
ONCHANGE GridRefresh() // call a function when this event is fired
END GRID

END WINDOW
Main.Center
Main.Activate

Return

function makedata()
local astru:={{"AA","C",3,0},{"BB","C",5,0}}
dbcreate("test.dbf",astru)
use test new
dbAppend()
TEST->AA:="11"
TEST->BB:="AAAAA"
dbAppend()
TEST->AA:="12"
TEST->BB:="BBBBB"
dbAppend()
TEST->AA:="13"
TEST->BB:="AAAAA"
dbAppend()
TEST->AA:="14"
TEST->BB:="CCCCC"
dbAppend()
TEST->AA:="15"
TEST->BB:="AAAAA"
dbAppend()
TEST->AA:="16"
TEST->BB:="AAAAA"

count to n // store number of records

RETURN NIL

FUNCTION FILTER(CVALUE)
IF EMPTY(CVALUE)
dbClearFilter()
ELSE
dbSETFilter({||TEST->BB==CVALUE})
ENDIF
count to n // store number of filtered records
TEST->(DBGOTOP())
MAIN.GRID_1.REFRESH()
MAIN.GRID_1.SetFocus() // set focus on to the grid

keybd_event ( VK_DOWN ) //simulate key down and key up
keybd_event ( VK_UP )

RETURN NIL

Function GridRefresh()
MAIN.GRID_1.ItemCount := n // set grid itemcount to number of records
return NIL

It is working with HMG 3.4.3

huiyi_ch
Posts: 57
Joined: Sat May 21, 2016 5:27 am
Has thanked: 1 time
Been thanked: 7 times

Post by huiyi_ch » Mon Feb 13, 2017 12:55 am

Thanks rakesh1201 for your solution.
Best regards.
huiyi

User avatar
srvet_claudio
Posts: 1934
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 28 times
Been thanked: 112 times
Contact:

Post by srvet_claudio » Sat Feb 18, 2017 2:50 pm

Hi all,
please test this patch:

Code: Select all

   - Fixed bug in BrowseUpdate function of Browse control(contrib by Marek)
   - Fixed bug in _ActivateWindow when use debug with modal window
   - Fixed bug in grid onquery event
   - Fixed bug in grid when load NIL values(hb_ValToStr)
   - Fixed bug in grid inplace column (contrib by ASESORMIX)
   - Implemented GetProperty ReadOnly EditBox and TextBox
   - Fixed bug in BT_BitmapSaveFile() function (reported by Roberto Lopez)
   - Fixed problem in Navigator.htm file of documentation (contrib by Roberto Lopez)
   - Fixed bug in GetLastActiveFormIndex() and GetLastActiveControlIndex() functions (contrib by Pablo Cesar)
   - Fixed bug in GetMainFormName() and GetMainFormHandle() functions (contrib by KDJ)
   - Fixed leak memory in HMG_UPPER and HMG_LOWER functions (reported by KDJ)
   - Fixed bug in HMG_EditControlGetSel() function (contrib by KDJ)
   - Fixed bug in HMG_ISALPHA, HMG_ISDIGIT, HMG_ISLOWER, HMG_ISUPPER, HMG_ISALPHANUMERIC functions (reported by Esgici)
   - Fixed functions BT_DrawTextXXX, BT_DrawTextEx ( see SaveDC in the code )
   - New: BT_DrawEMF ( [ hDC ] , cFileNameOld , cFileNameNew , cFuncNameCallBack )  ---> Return nError, e.g. Zero is OK
   - New: BT_BitmapIsValidFileImage( cFileName ) 
Attachments
HMG.3.4.3_patch_1.rar
(3.68 MiB) Downloaded 87 times
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com

User avatar
Rathinagiri
Posts: 5148
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 124 times
Been thanked: 126 times
Contact:

Post by Rathinagiri » Sat Feb 18, 2017 3:06 pm

Thanks a lot Claudio!
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

User avatar
mol
Posts: 2801
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 112 times
Been thanked: 52 times
Contact:

Post by mol » Sat Feb 18, 2017 3:24 pm

Thanks!

User avatar
serge_girard
Posts: 1803
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 260 times
Been thanked: 60 times
Contact:

Post by serge_girard » Sat Feb 18, 2017 3:40 pm

Claudio, thank you very much for all the work involved !!
Serge

User avatar
bpd2000
Posts: 943
Joined: Sat Sep 10, 2011 4:07 am
Location: India
Has thanked: 117 times
Been thanked: 42 times

Post by bpd2000 » Sat Feb 18, 2017 4:45 pm

serge_girard wrote:
Sat Feb 18, 2017 3:40 pm
Claudio, thank you very much for all the work involved !!
Serge
+1
BPD
Convert Dream into Reality through HMG

User avatar
tonton2
Posts: 245
Joined: Sat Jun 29, 2013 1:26 pm
Location: Algerie
Has thanked: 3 times
Been thanked: 6 times
Contact:

Post by tonton2 » Sat Feb 18, 2017 9:00 pm

merci beaucoup Dr Claudio
L'Algerie vous salut
Y.TABET

KDJ
Posts: 164
Joined: Mon Sep 05, 2016 3:04 am
Location: Poland
Been thanked: 148 times

Post by KDJ » Sat Feb 18, 2017 10:20 pm

Claudio

Thank you very much for the patch.
srvet_claudio wrote:
Sat Feb 18, 2017 2:50 pm
Hi all,
please test this patch:

Code: Select all

   ...
   - Fixed leak memory in HMG_UPPER and HMG_LOWER functions (reported by KDJ)
   ...
This has been fixed at one-third, because in HMG_UPPER function are used three buffers allocated on the heap, and only one has been released:
1. "Text" buffer returned by HMG_parc(1) - not released,
2. "Buffer" buffer - this is released,
3. buffer returned by hb_osStrU16Decode(Buffer) in HMG_retc(Buffer) - not released.

My solutions are the following:

Code: Select all

   HB_FUNC (HMG_UPPER1)
   {  
      TCHAR *Text   = (TCHAR*)  HMG_parc(1);

      if (Text == NULL)
      {   HMG_retc (NULL);
          return;
      }

      INT   nLen    = (INT)     lstrlen(Text) + 1;
      TCHAR *Buffer = (TCHAR *) hb_xgrab (nLen * sizeof(TCHAR));

      if (Buffer != NULL)
      {   lstrcpy (Buffer, Text);
          CharUpper (Buffer);

          LPSTR RetStr = hb_osStrU16Decode(Buffer);
          hb_retc (RetStr);
          hb_xfree (RetStr);

          hb_xfree (Buffer);
      }
      else
         HMG_retc (NULL);

      hb_xfree (Text);
   }
or with two buffers only (works faster and involves less memory):

Code: Select all

   HB_FUNC (HMG_UPPER2)
   {  
      TCHAR *Text   = (TCHAR*)  HMG_parc(1);

      if (Text == NULL)
      {   HMG_retc (NULL);
          return;
      }

      CharUpper (Text);

      LPSTR RetStr = hb_osStrU16Decode(Text);
      hb_retc (RetStr);
      hb_xfree (RetStr);

      hb_xfree (Text);
   }
Program to test:

Code: Select all

// Press 'Test: ...' and observe memory usage at status bar

#include 'hmg.ch'


FUNCTION Main()

  SET FONT TO 'MS Shell Dlg', 8

  DEFINE WINDOW MainWnd;
    COL    200;
    ROW    100;
    WIDTH  180;
    HEIGHT 210;
    TITLE  'Memory usage test';
    MAIN;
    MINBUTTON .F.;
    MAXBUTTON .F.;
    NOSIZE

    DEFINE BUTTON Test1_BU
      COL      10
      ROW      20
      WIDTH   150
      HEIGHT   25
      CAPTION 'Test: HMG_Upper'
      ACTION  DoTest(@HMG_Upper())
    END BUTTON

    DEFINE BUTTON Test2_BU
      COL      10
      ROW      50
      WIDTH   150
      HEIGHT   25
      CAPTION 'Test: HMG_Upper1'
      ACTION  DoTest(@HMG_Upper1())
    END BUTTON

    DEFINE BUTTON Test3_BU
      COL      10
      ROW      80
      WIDTH   150
      HEIGHT   25
      CAPTION 'Test: HMG_Upper2'
      ACTION  DoTest(@HMG_Upper2())
    END BUTTON

    DEFINE BUTTON Test4_BU
      COL      10
      ROW     110
      WIDTH   150
      HEIGHT   25
      CAPTION 'Test: Upper'
      ACTION  DoTest(@Upper())
    END BUTTON

    DEFINE STATUSBAR
      STATUSITEM ''
    END STATUSBAR

    DEFINE TIMER MainWnd_TI;
      INTERVAL 1000;
      ACTION   UpdateStatus()

    ON KEY ESCAPE ACTION MainWnd.RELEASE

  END WINDOW

  UpdateStatus()
  MainWnd.ACTIVATE

RETURN NIL


FUNCTION DoTest(sFunc)
  LOCAL cLowerStr := 'abcdefghijklmnop'
  LOCAL cUpperStr
  LOCAL nSeconds
  LOCAL cTime
  LOCAL n

  nSeconds := Seconds()

  FOR n := 1 TO 100000
    cUpperStr := sFunc:exec(cLowerStr)
  NEXT

  cTime := Str((Seconds() - nSeconds) * 1000, 5)

  UpdateStatus()
  MsgBox('Lower: ' + cLowerStr + CRLF + 'Upper: ' + cUpperStr + CRLF + 'Time: ' + cTime + ' ms', sFunc:name + '()')

RETURN NIL


FUNCTION UpdateStatus()

  MainWnd.STATUSBAR.Item(1) := 'Memory usage: ' + LTrim(Str(GetProcessMemoryInfo()[3] / 1024, 10, 0) + ' KB')

RETURN NIL


#pragma BEGINDUMP

  #include "SET_COMPILE_HMG_UNICODE.ch"
  #include "HMG_UNICODE.h"
  #include <windows.h>
  #include "hbapi.h"

   HB_FUNC (HMG_UPPER1)
   {  
      TCHAR *Text   = (TCHAR*)  HMG_parc(1);

      if (Text == NULL)
      {   HMG_retc (NULL);
          return;
      }

      INT   nLen    = (INT)     lstrlen(Text) + 1;
      TCHAR *Buffer = (TCHAR *) hb_xgrab (nLen * sizeof(TCHAR));

      if (Buffer != NULL)
      {   lstrcpy (Buffer, Text);
          CharUpper (Buffer);

          LPSTR RetStr = hb_osStrU16Decode(Buffer);
          hb_retc (RetStr);
          hb_xfree (RetStr);

          hb_xfree (Buffer);
      }
      else
         HMG_retc (NULL);

      hb_xfree (Text);
   }


   HB_FUNC (HMG_UPPER2)
   {  
      TCHAR *Text   = (TCHAR*)  HMG_parc(1);

      if (Text == NULL)
      {   HMG_retc (NULL);
          return;
      }

      CharUpper (Text);

      LPSTR RetStr = hb_osStrU16Decode(Text);
      hb_retc (RetStr);
      hb_xfree (RetStr);

      hb_xfree (Text);
   }

#pragma ENDDUMP
-----
PS:
Unresolved is the question of the HMG_parc, HMG_retc and HMG_storc, HMG_itemPutC macros in other functions and HMG_GetUnicodeCharacter, HMG_UNICODE_TO_ANSI, HMG_ANSI_TO_UNICODE.
I wrote about it here:
viewtopic.php?f=20&t=4884&p=48854#p48854
viewtopic.php?f=20&t=4884&p=49045#p49045

User avatar
andyglezl
Posts: 835
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Has thanked: 7 times
Been thanked: 20 times
Contact:

Post by andyglezl » Sat Feb 18, 2017 10:39 pm

Gracias Dr. Claudio !
Andrés González López
Desde Guadalajara, Jalisco. México.

Post Reply