HMG 3.4.3
Moderator: Rathinagiri
-
- Posts: 2
- Joined: Sun Feb 12, 2017 9:02 am
Re: GRID CONTROL problem
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
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
Re: HMG 3.4.3
Thanks rakesh1201 for your solution.
Best regards.
huiyi
Best regards.
huiyi
- srvet_claudio
- Posts: 2193
- Joined: Thu Feb 25, 2010 8:43 pm
- Location: Uruguay
- Contact:
Re: HMG 3.4.3
Hi all,
please test this patch:
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 341 times
- Rathinagiri
- Posts: 5471
- Joined: Tue Jul 29, 2008 6:30 pm
- DBs Used: MariaDB, SQLite, SQLCipher and MySQL
- Location: Sivakasi, India
- Contact:
Re: HMG 3.4.3
Thanks a lot Claudio!
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
South or North HMG is worth.
...the possibilities are endless.
- serge_girard
- Posts: 3166
- Joined: Sun Nov 25, 2012 2:44 pm
- DBs Used: 1 MySQL - MariaDB
2 DBF - Location: Belgium
- Contact:
Re: HMG 3.4.3
Claudio, thank you very much for all the work involved !!
Serge
Serge
There's nothing you can do that can't be done...
Re: HMG 3.4.3
+1serge_girard wrote: ↑Sat Feb 18, 2017 3:40 pm Claudio, thank you very much for all the work involved !!
Serge
BPD
Convert Dream into Reality through HMG
Convert Dream into Reality through HMG
Re: HMG 3.4.3
Claudio
Thank you very much for the patch.
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:
or with two buffers only (works faster and involves less memory):
Program to test:
-----
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
Thank you very much for the patch.
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: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) ...
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);
}
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);
}
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