HMG 3.4.3

HMG Unicode versions 3.1.x related

Moderator: Rathinagiri

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

Re: HMG 3.4.3

Post by Rathinagiri » Tue Nov 22, 2016 10:17 am

Hi,

I have used the following code and it works fine.

So the problem is the append from command.

Code: Select all

#include <hmg.ch>

Function Main
   local astru:= { { "PEOPLE", "c", 30, 0 } }
   local aData := HB_ATOKENS( MEMOREAD( "peoples1.txt" ),   CRLF )
   dbCreate( "PEOPLES", astru )
   use PEOPLES new
   for i := 1 to hmg_len( aData )
      append blank
      replace people with aData[ i ] 
   next i   
   go top
   do while .not. eof() 
      msginfo( people )
      skip
   enddo   
Return

East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

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

Post by huiyi_ch » Tue Nov 22, 2016 11:21 am

Thank your solved method,But I try use "Harbour MiniGUI Extended Edition build 16.10" the append command ,it can be execute correctly.

User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil
Has thanked: 100 times
Been thanked: 177 times

Post by Pablo César » Tue Nov 22, 2016 11:43 am

huiyi_ch wrote:Thank your solved method,But I try use "Harbour MiniGUI Extended Edition build 16.10" the append command ,it can be execute correctly.
:o

If you want to work with specials characters (not English, for example), you will need more UNICODE. So, HMG works with UNICODE, HMG Extended not yet.

But tell me: why you do not mentioned before your are working with HMG Extended ? :roll:
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein

User avatar
kcarmody
Posts: 121
Joined: Tue Oct 07, 2014 11:13 am
Has thanked: 6 times
Been thanked: 16 times
Contact:

Post by kcarmody » Tue Nov 22, 2016 12:19 pm

Rathinagiri wrote:So the problem is the append from command.
huiyi_ch wrote:Thank your solved method,But I try use "Harbour MiniGUI Extended Edition build 16.10" the append command ,it can be execute correctly.
Yes, APPEND FROM DELIMITED does not work in HMG as expected with Unicode data files, with or without a UTF-8 BOM. And it is also true that APPEND FROM DELIMITED in MiniGui Extended works as expected. But MiniGui Extended cannot display Unicode, while HMG does. You need Unicode to display Chinese characters.

The HB_ATOKENS approach works well, as long as you do not use quotes around the field values (which APPEND FROM DELMITED allows), and you have a file that MEMOREAD can handle properly. I've tested MEMOREAD for files up to 4G and it seemed to work OK. I don't know about file sizes larger than this.

The HB_ATOKENS call that Rathi gave splits a file up into lines. Since there is only one field per line, the whole line can be read into the field. But if you are reading more than one field per record, you will have to split the line up with another HB_ATOKENS call. The FOR loop would then have to be something like this:

Code: Select all

for i := 1 to hmg_len( aData )
   aFields := HB_ATOKENS( aData[ i ], "," )
   append blank
   replace field1 with aFields[ 1 ]
   replace field2 with aFields[ 2 ]
   ...
next
The data file would look something like this:

Code: Select all

ABC,ABCDEFGHI
DEFG,KLMNOPQ
XY,THIRDREC

Code: Select all

中,中国
美,美国
俄,俄国
日,日本
You can also use APPEND FROM SDF. I tried this, and it does work as expected with Unicode data files. But if you have multiple fields per line, the lines must be set up differently. You do not use commas, but instead use spaces to pad out the fields to the field length. So if you had two fields, FIELD1 with length 5 and FIELD2 with length 10, an SDF file would have to look like this:

Code: Select all

ABC  ABCDEFGHI
DEFG KLMNOPQ
XY   THIRDREC

Code: Select all

中  中国
美  美国
俄  俄国
日  日本
Field lengths in DBF files are number of bytes, not number of characters. Each Chinese character in the PEOPLES1.txt file that you posted takes up 3 bytes. I believe that most Chinese characters in common use take up 3 bytes. Other Chinese characters may take 4 bytes.

The PEOPLES1.txt file that you posted contains a BOM (byte order mark). This does not work with APPEND FROM SDF. It worked only when I removed the BOM. The BOM is usually not necessary in Harbour, including PRG and other source files.

User avatar
kcarmody
Posts: 121
Joined: Tue Oct 07, 2014 11:13 am
Has thanked: 6 times
Been thanked: 16 times
Contact:

Post by kcarmody » Tue Nov 22, 2016 12:26 pm

Here is the code I used to test APPEND FROM SDF and APPEND FROM DELIMITED. The attached zip file contains the data files.

Code: Select all

#include <hmg.ch>

Function Main
local astru := { ;
  {"PRE"   ,"c", 5,0}, ;
  {"PEOPLE","c",30,0}  }
dbCreate("PEOPLES1DEL",astru)
dbCreate("PEOPLES1SDF",astru)
dbCreate("PEOPLES2DEL",astru)
dbCreate("PEOPLES2SDF",astru)
use PEOPLES1DEL new
append from PEOPLES1DEL.txt delimited
begin sequence
  dbEval({|| display_record()})
end
use PEOPLES1SDF new
append from PEOPLES1SDF.txt sdf
begin sequence
  dbEval({|| display_record()})
end
use PEOPLES2DEL new
append from PEOPLES2DEL.txt delimited
begin sequence
  dbEval({|| display_record()})
end
use PEOPLES2SDF new
append from PEOPLES2SDF.txt sdf
begin sequence
  dbEval({|| display_record()})
end
Return nil

function display_record
  if ! msgyesno( ;
    'File ' + alias() + CRLF + ;
    'Record number ' + ltrim(str(recno())) + ' of ' + ltrim(str(reccount())) + CRLF + ;
    'Field PRE = ' + FIELD->PRE + CRLF + ;
    'Field PEOPLE = ' + FIELD->PEOPLE + CRLF + ;
    'Continue?')
    break
  end
Return nil
Attachments
PEOPLES.zip
(720 Bytes) Downloaded 51 times

User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil
Has thanked: 100 times
Been thanked: 177 times

Post by Pablo César » Tue Nov 22, 2016 1:31 pm

Thank you Kevin for your prompt response and always so rich with your explanations.

You are the UNICODE man. :D

I think this limitations is due to Harbour not to HMG, because is based on in low level for APPENDs and SDF cases.

Anyway, it's as you mentioned, in this cases works in ANSI. Probably to convert in UNICODE but after importing proccess.

Best regards
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein

User avatar
srvet_claudio
Posts: 1958
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 32 times
Been thanked: 124 times
Contact:

Post by srvet_claudio » Tue Nov 22, 2016 11:01 pm

huiyi_ch wrote:Hmg.3.4.3不能将中文正确读入表中
请看下面例子:
假如我要把下列文本添加到表中:
People2.txt(CHINESE、AMERICANE、RUSSIAN、JAPANINESE)
运行程序后可将文本正确读入表中.
如果我想把下列中文文本添加到表中:
People1.txt(中国、美国、俄国、日本)
程序将不能正确读入表中。


Hmg.3.4.3 The Chinese can not be correctly read into the table
Consider the following example:
Suppose I want to add the following text to the table
People2.txt(CHINESE、AMERICANE、RUSSIAN、JAPANINESE)
After the program can be run correctly read the text into the table,

If I want to add the following Chinese text to the table:
People1.txt(中国、美国、俄国、日本)
The program will not be correctly read into the table.

Code: Select all

#include <hmg.ch>

Function Main
open_table("2")
dbEval({||msginfo(PEOPLES->PEOPLE)})
use 
open_table("1")
dbEval({||msginfo(PEOPLES->PEOPLE)})
USE
Return

function open_table(ctype)
local astru:={{"PEOPLE","c",30,0}}
dbCreate("PEOPLES",astru)
use PEOPLES new
if ctype="1"
append from PEOPLES1.txt delimited
else
append from PEOPLES2.txt delimited
endif
return
test.rar
I not tested but see: SET( _SET_DBCODEPAGE, cCp )

See Massimo Belgrano post: https://groups.google.com/forum/m/#!top ... iFrmIyv12c
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com

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

Post by huiyi_ch » Wed Nov 23, 2016 3:01 am

非常感谢各位的热情帮助!
Thank you very much for your warm help!

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

Post by huiyi_ch » Wed Nov 23, 2016 3:38 am

我发现当HMG3.4.3(UNICODE )在读取INI文件时,如果INI 文件中存在汉字,则读取出来的文本可能不正确!
比如,编译运行下面程序,在INI文件中是“我非常喜欢HMG!”,而读取出的字符串是“我非常”

I found that when hmg3.4.3 (Unicode) in reading the INI file, if the INI file exists in Chinese characters, then read out the text may not be correct!
For example, compile and run the following program, in the INI file is "我非常喜欢HMG!" and read out the string is "我非常".
My englist is very poor,so please forgive me.

Code: Select all

#include <hmg.ch>
FUNCTION main()
LOCAL cIniFile := GetStartupFolder() + '\demo.ini'
LOCAL aRet

SetIniValue(cIniFile)
aRet := GetValue(cIniFile)
AEVAL( aRet, { |x| MsgInfo( x ) } )
RETURN NIL


PROCEDURE SetIniValue( cIni )

BEGIN INI FILE cIni
  SET SECTION 'HMG' ENTRY 'Vers' TO 3.43
  SET SECTION 'HMG' ENTRY 'DESCRIBE_1' TO "我非常喜欢HMG!"
  SET SECTION 'HMG' ENTRY 'DESCRIBE_2' TO "I LIKE HMG VERY MUCH!"
END INI

RETURN


FUNCTION GetValue( cIni )
LOCAL cDescrib_1:="", cDescrib_2:="",nVers:=0

BEGIN INI FILE (cIni)
  GET cDescrib_1 SECTION 'HMG' ENTRY 'DESCRIBE_1' DEFAULT ''
  GET cDescrib_2 SECTION 'HMG' ENTRY 'DESCRIBE_2' DEFAULT ''
  GET nVers SECTION 'HMG' ENTRY 'Vers' DEFAULT 3.43
END INI

RETURN {cDescrib_1,cDescrib_2, nVers}
test_ini.rar
(1.23 MiB) Downloaded 57 times

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

Post by Rathinagiri » Wed Nov 23, 2016 4:59 am

IMHO, it may be because of the older version of Harbour that HMG uses.

If possible, please try to rebuild HMG with the latest version of Harbour and whether we have the same problem.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

Post Reply