topic
stringlengths 1
63
| text
stringlengths 1
577k
⌀ |
|---|---|
Artificial intelligence - Class TPerceptron
|
OK, I found the problem!
It only occurs when I copy code from the forum. Sometimes there are special characters (invisible) instead of spaces indenting the code. I this case it was this line:
[code=fw:35ao5vy2]<div class="fw" id="{CB}" style="font-family: monospace;"><span style="color: #00C800;">CLASS</span> TPerceptron<br /> <span style="color: #00C800;">METHOD</span> <span style="color: #00C800;">New</span><br /><span style="color: #000000;">[</span>special characters<span style="color: #000000;">]</span><span style="color: #00C800;">METHOD</span> Learn<br /><span style="color: #00C800;">ENDCLASS</span><br /><br /> </div>[/code:35ao5vy2]
When I changed the invisible characters to spaces there are no more errors.
I haven't figured out which characters they are as it is difficult to do with hex view in my editor. At first I thought they were tabs, but I inserted tabs and they work fine.
James
|
Artificial intelligence - Class TPerceptron
|
Ok, normally you use 3 spaces to indent. These are hex 20,20,20.
Some of the lines in the Perceptron code indented with spaces but others are indented with A0,20,A0. This causes a syntax error by the compiler.
I am at a loss as to how code that was working, can then be uploaded to the forum and end up with the A0,20,A0 syntax. I have never seen this until recently. Perhaps the forum software is doing this and it wasn't before?
Regards,
James
|
Artificial intelligence - Class TPerceptron
|
James,
I copied from the posted code and did a past with my editor.
Maybe Your used EDITOR is the problem ?
regards
Uwe <!-- s:?: --><img src="{SMILIES_PATH}/icon_question.gif" alt=":?:" title="Question" /><!-- s:?: -->
|
Artificial intelligence - Class TPerceptron
|
The problem is a bug in MS Edge. Try with IE and it will work fine.
EMG
|
Artificial intelligence - Class TPerceptron
|
Enrico,
[quote:3qv9r2wi]The problem is a bug in MS Edge. Try with IE and it will work fine.[/quote:3qv9r2wi]
Thanks so much for that tip. I am using Edge. I'll try to remember the next time I copy text to use IE.
I have been using Edge for a couple of years now and I never had that problem before. I suppose the bug must have been introduced recently.
Regards,
James
|
Artificial intelligence - Class TPerceptron
|
Antonio,
Pardon me for accidentally hijacking your thread.
I have found a good article about preceptrons:
[url=https://appliedgo.net/perceptron/:1ckugwjd]Perceptrons - the most basic form of a neural network[/url:1ckugwjd]
James
|
Artificial intelligence - Class TPerceptron
|
I've been looking for some old source code to prove it to myself but this looks very similar to what I was taught as Predictor/Corrector methods back in the mid-80s when I was working on my mechanical engineering degree. I had forgotten about it until reading this code. If I remember correctly, for learning purposes, we used it for contour mapping, as in topographical maps. I remember it being fun to work with, but for the life of me I can't recall how it actually worked. I would need to find the original source to be sure. I may only have it on a floppy disk, probably written in Fortran 77.
I did do some derivative work based on that method, written for an aerospace company, which means nothing I owned or can share as I wouldn't have a copy. I suppose the original code I wrote it in college I own. If I can find it I'll see about porting it to harbour and will share it. Don't wait for it, it may be on a 5 1/4" floppy disk, and I don't have one of those drives anywhere any longer.
Robb
|
Artificial intelligence - Class TPerceptron
|
[quote="James Bott":1oab6g2e]Enrico,
[quote:1oab6g2e]The problem is a bug in MS Edge. Try with IE and it will work fine.[/quote:1oab6g2e]
Thanks so much for that tip. I am using Edge. I'll try to remember the next time I copy text to use IE.
I have been using Edge for a couple of years now and I never had that problem before. I suppose the bug must have been introduced recently.
Regards,
James[/quote:1oab6g2e]
Yes, I saw it the first time with W10 Anniversary Update, if I remember correctly.
EMG
|
Artificial intelligence - Class TPerceptron
|
[quote="rhlawek":37plpnov]I've been looking for some old source code to prove it to myself but this looks very similar to what I was taught as Predictor/Corrector methods back in the mid-80s[/quote:37plpnov]
Yes, it's a very old concept. But still interesting.
EMG
|
Artificial intelligence - Class TPerceptron
|
Pedro Domingos name them "learners": software that can "learn" from data.
The simplest way of learning from data is comparing two bytes. How ? Substracting them: A zero means they are equal, different from zero means they are different.
The difference between them is the "error". To correct the error, we modify a "weight" . Its amazing that from that simple concept, all what can be built. In the same way all our software technology comes from a bit, being zero or one.
The perceptron mimics (in a very simple way) the behavior of a brain neuron. The neuron receives several inputs, each one has a weight (stored at the neuron) and the sum of all those inputs times their weights may fire or not an output.
Backpropagation helps to fine tune those weights, and finally the perceptron "adjusts" itself to the right weight for each input to produce the expected output.
AI is already everywhere and will change very much our lives and the way software is developed <!-- s:-) --><img src="{SMILIES_PATH}/icon_smile.gif" alt=":-)" title="Smile" /><!-- s:-) -->
|
Artificial intelligence - Class TPerceptron
|
[img:3eaqkasd]https://bitbucket.org/fivetech/screenshots/downloads/perceptron.JPG[/img:3eaqkasd]
|
Artificial intelligence - Class TPerceptron
|
[img:34qo88ic]https://bitbucket.org/fivetech/screenshots/downloads/redNeuronal.JPG[/img:34qo88ic]
Perceptrón [b:34qo88ic]Multicapa[/b:34qo88ic]
|
Artificial intelligence - Class TPerceptron
|
C and C++ source code:
<!-- l --><a class="postlink-local" href="http://forums.fivetechsupport.com/viewtopic.php?f=6&t=33946&p=202105#p202104">viewtopic.php?f=6&t=33946&p=202105#p202104</a><!-- l -->
|
Artificial intelligence - Class TPerceptron
|
David Miller C++ code ported to Harbour:
<!-- l --><a class="postlink-local" href="http://forums.fivetechsupport.com/viewtopic.php?p=202115#p202115">viewtopic.php?p=202115#p202115</a><!-- l -->
Don't miss to try your first neural network <!-- s:-) --><img src="{SMILIES_PATH}/icon_smile.gif" alt=":-)" title="Smile" /><!-- s:-) -->
|
Artificial intelligence - Class TPerceptron
|
Inspecting the neural network:
[code=fw:2s7helmi]<div class="fw" id="{CB}" style="font-family: monospace;"><span style="color: #00D7D7;">#include</span> <span style="color: #ff0000;">"FiveWin.ch"</span><br /><br /><span style="color: #00C800;">function</span> Main<span style="color: #000000;">(</span><span style="color: #000000;">)</span><br /><br /> <span style="color: #00C800;">local</span> oNet := TNet<span style="color: #000000;">(</span><span style="color: #000000;">)</span>:<span style="color: #00C800;">New</span><span style="color: #000000;">(</span> <span style="color: #000000;">{</span> <span style="color: #000000;">1</span>, <span style="color: #000000;">2</span>, <span style="color: #000000;">1</span> <span style="color: #000000;">}</span> <span style="color: #000000;">)</span>, n<br /> <span style="color: #00C800;">local</span> x <br /><br /> <span style="color: #00C800;">while</span> oNet:<span style="color: #000000;">nRecentAverageError</span> < <span style="color: #000000;">0.95</span><br /> oNet:<span style="color: #000000;">FeedForward</span><span style="color: #000000;">(</span> <span style="color: #000000;">{</span> x := nRandom<span style="color: #000000;">(</span> <span style="color: #000000;">1000</span> <span style="color: #000000;">)</span> <span style="color: #000000;">}</span> <span style="color: #000000;">)</span><br /> oNet:<span style="color: #000000;">Backprop</span><span style="color: #000000;">(</span> <span style="color: #000000;">{</span> <span style="color: #00C800;">If</span><span style="color: #000000;">(</span> x % <span style="color: #000000;">5</span> == <span style="color: #000000;">0</span>, <span style="color: #000000;">5</span>, <span style="color: #000000;">1</span> <span style="color: #000000;">)</span> <span style="color: #000000;">}</span> <span style="color: #000000;">)</span> <br /> end <br /><br /> oNet:<span style="color: #000000;">FeedForward</span><span style="color: #000000;">(</span> <span style="color: #000000;">{</span> <span style="color: #000000;">15</span> <span style="color: #000000;">}</span> <span style="color: #000000;">)</span><br /> <br /> XBROWSER ArrTranspose<span style="color: #000000;">(</span> <span style="color: #000000;">{</span> <span style="color: #ff0000;">"Layer 1 1st neuron"</span> + CRLF + <span style="color: #ff0000;">"Input:"</span> + Str<span style="color: #000000;">(</span> oNet:<span style="color: #000000;">aLayers</span><span style="color: #000000;">[</span> <span style="color: #000000;">1</span> <span style="color: #000000;">]</span><span style="color: #000000;">[</span> <span style="color: #000000;">1</span> <span style="color: #000000;">]</span>:<span style="color: #000000;">nOutput</span> <span style="color: #000000;">)</span> + ;<br /> CRLF + <span style="color: #ff0000;">"Weigth 1:"</span> + Str<span style="color: #000000;">(</span> oNet:<span style="color: #000000;">aLayers</span><span style="color: #000000;">[</span> <span style="color: #000000;">1</span> <span style="color: #000000;">]</span><span style="color: #000000;">[</span> <span style="color: #000000;">1</span> <span style="color: #000000;">]</span>:<span style="color: #000000;">aWeights</span><span style="color: #000000;">[</span> <span style="color: #000000;">1</span> <span style="color: #000000;">]</span>, <span style="color: #000000;">4</span>, <span style="color: #000000;">2</span> <span style="color: #000000;">)</span>, ;<br /> <span style="color: #000000;">{</span> <span style="color: #ff0000;">"Layer 2, 1st neuron"</span> + CRLF + <span style="color: #ff0000;">"Weigth 1: "</span> + Str<span style="color: #000000;">(</span> oNet:<span style="color: #000000;">aLayers</span><span style="color: #000000;">[</span> <span style="color: #000000;">2</span> <span style="color: #000000;">]</span><span style="color: #000000;">[</span> <span style="color: #000000;">1</span> <span style="color: #000000;">]</span>:<span style="color: #000000;">aWeights</span><span style="color: #000000;">[</span> <span style="color: #000000;">1</span> <span style="color: #000000;">]</span> <span style="color: #000000;">)</span> + ;<br /> CRLF + <span style="color: #ff0000;">"Output: "</span> + Str<span style="color: #000000;">(</span> oNet:<span style="color: #000000;">aLayers</span><span style="color: #000000;">[</span> <span style="color: #000000;">2</span> <span style="color: #000000;">]</span><span style="color: #000000;">[</span> <span style="color: #000000;">1</span> <span style="color: #000000;">]</span>:<span style="color: #000000;">nOutput</span> <span style="color: #000000;">)</span>,;<br /> <span style="color: #ff0000;">"Layer 2, 2nd neuron"</span> + CRLF + <span style="color: #ff0000;">"Weight 1: "</span> + Str<span style="color: #000000;">(</span> oNet:<span style="color: #000000;">aLayers</span><span style="color: #000000;">[</span> <span style="color: #000000;">2</span> <span style="color: #000000;">]</span><span style="color: #000000;">[</span> <span style="color: #000000;">2</span> <span style="color: #000000;">]</span>:<span style="color: #000000;">aWeights</span><span style="color: #000000;">[</span> <span style="color: #000000;">1</span> <span style="color: #000000;">]</span> <span style="color: #000000;">)</span> + ;<br /> CRLF + <span style="color: #ff0000;">"Output: "</span> + Str<span style="color: #000000;">(</span> oNet:<span style="color: #000000;">aLayers</span><span style="color: #000000;">[</span> <span style="color: #000000;">2</span> <span style="color: #000000;">]</span><span style="color: #000000;">[</span> <span style="color: #000000;">2</span> <span style="color: #000000;">]</span>:<span style="color: #000000;">nOutput</span> <span style="color: #000000;">)</span> <span style="color: #000000;">}</span>,;<br /> <span style="color: #ff0000;">"Layer 3 1st neuron"</span> + CRLF + <span style="color: #ff0000;">"Weigth 1: "</span> + Str<span style="color: #000000;">(</span> oNet:<span style="color: #000000;">aLayers</span><span style="color: #000000;">[</span> <span style="color: #000000;">3</span> <span style="color: #000000;">]</span><span style="color: #000000;">[</span> <span style="color: #000000;">1</span> <span style="color: #000000;">]</span>:<span style="color: #000000;">aWeights</span><span style="color: #000000;">[</span> <span style="color: #000000;">1</span> <span style="color: #000000;">]</span> <span style="color: #000000;">)</span> + ;<br /> CRLF + <span style="color: #ff0000;">"Weigth 2: "</span> + Str<span style="color: #000000;">(</span> oNet:<span style="color: #000000;">aLayers</span><span style="color: #000000;">[</span> <span style="color: #000000;">3</span> <span style="color: #000000;">]</span><span style="color: #000000;">[</span> <span style="color: #000000;">1</span> <span style="color: #000000;">]</span>:<span style="color: #000000;">aWeights</span><span style="color: #000000;">[</span> <span style="color: #000000;">2</span> <span style="color: #000000;">]</span> <span style="color: #000000;">)</span> + ;<br /> CRLF + <span style="color: #ff0000;">"Output: "</span> + Str<span style="color: #000000;">(</span> oNet:<span style="color: #000000;">aLayers</span><span style="color: #000000;">[</span> <span style="color: #000000;">2</span> <span style="color: #000000;">]</span><span style="color: #000000;">[</span> <span style="color: #000000;">2</span> <span style="color: #000000;">]</span>:<span style="color: #000000;">nOutput</span> <span style="color: #000000;">)</span> <span style="color: #000000;">}</span> <span style="color: #000000;">)</span> ;<br /> SETUP <span style="color: #000000;">(</span> oBrw:<span style="color: #000000;">nDataLines</span> := <span style="color: #000000;">4</span>,;<br /> oBrw:<span style="color: #000000;">aCols</span><span style="color: #000000;">[</span> <span style="color: #000000;">1</span> <span style="color: #000000;">]</span>:<span style="color: #000000;">nWidth</span> := <span style="color: #000000;">180</span>,;<br /> oBrw:<span style="color: #000000;">aCols</span><span style="color: #000000;">[</span> <span style="color: #000000;">2</span> <span style="color: #000000;">]</span>:<span style="color: #000000;">nWidth</span> := <span style="color: #000000;">180</span>,;<br /> oBrw:<span style="color: #000000;">aCols</span><span style="color: #000000;">[</span> <span style="color: #000000;">3</span> <span style="color: #000000;">]</span>:<span style="color: #000000;">nWidth</span> := <span style="color: #000000;">180</span>,;<br /> oBrw:<span style="color: #000000;">nMarqueeStyle</span> := <span style="color: #000000;">3</span> <span style="color: #000000;">)</span> <br /> <br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">nil</span></div>[/code:2s7helmi]
[img:2s7helmi]https://bitbucket.org/fivetech/screenshots/downloads/neuralnet_browse.JPG[/img:2s7helmi]
|
Artificial intelligence - Class TPerceptron
|
[b:2wih07x9]Teaching a perceptron to multiply a number by 2:[/b:2wih07x9]
[code=fw:2wih07x9]<div class="fw" id="{CB}" style="font-family: monospace;"><span style="color: #00D7D7;">#include</span> <span style="color: #ff0000;">"FiveWin.ch"</span><br /><br /><span style="color: #00C800;">function</span> Main<span style="color: #000000;">(</span><span style="color: #000000;">)</span><br /><br /> <span style="color: #00C800;">local</span> oNeuron := TPerceptron<span style="color: #000000;">(</span><span style="color: #000000;">)</span>:<span style="color: #00C800;">New</span><span style="color: #000000;">(</span> <span style="color: #000000;">1</span> <span style="color: #000000;">)</span><br /> <span style="color: #00C800;">local</span> n, nValue<br /><br /> <span style="color: #00C800;">for</span> n = <span style="color: #000000;">1</span> <span style="color: #0000ff;">to</span> <span style="color: #000000;">50</span><br /> oNeuron:<span style="color: #000000;">Learn</span><span style="color: #000000;">(</span> <span style="color: #000000;">{</span> nValue := nRandom<span style="color: #000000;">(</span> <span style="color: #000000;">1000</span> <span style="color: #000000;">)</span> <span style="color: #000000;">}</span>, ExpectedResult<span style="color: #000000;">(</span> nValue <span style="color: #000000;">)</span> <span style="color: #000000;">)</span><br /> <span style="color: #00C800;">next</span><br /><br /> <span style="color: #0000ff;">MsgInfo</span><span style="color: #000000;">(</span> oNeuron:<span style="color: #000000;">aWeights</span><span style="color: #000000;">[</span> <span style="color: #000000;">1</span> <span style="color: #000000;">]</span> <span style="color: #000000;">)</span><br /> <br /> <span style="color: #0000ff;">MsgInfo</span><span style="color: #000000;">(</span> oNeuron:<span style="color: #000000;">Calculate</span><span style="color: #000000;">(</span> <span style="color: #000000;">{</span> <span style="color: #000000;">5</span> <span style="color: #000000;">}</span> <span style="color: #000000;">)</span> <span style="color: #000000;">)</span><br /><br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">nil</span> <br /><br /><span style="color: #00C800;">function</span> ExpectedResult<span style="color: #000000;">(</span> nValue <span style="color: #000000;">)</span><br /><br /><span style="color: #00C800;">return</span> nValue * <span style="color: #000000;">2</span><br /><br /><span style="color: #00C800;">CLASS</span> TPerceptron<br /><br /> <span style="color: #00C800;">DATA</span> aWeights<br /><br /> <span style="color: #00C800;">METHOD</span> <span style="color: #00C800;">New</span><span style="color: #000000;">(</span> nInputs <span style="color: #000000;">)</span><br /><br /> <span style="color: #00C800;">METHOD</span> Learn<span style="color: #000000;">(</span> aInputs, nExpectedResult <span style="color: #000000;">)</span><br /><br /> <span style="color: #00C800;">METHOD</span> Calculate<span style="color: #000000;">(</span> aInputs <span style="color: #000000;">)</span><br /><br /><span style="color: #00C800;">ENDCLASS</span><br /><br /><span style="color: #00C800;">METHOD</span> <span style="color: #00C800;">New</span><span style="color: #000000;">(</span> nInputs <span style="color: #000000;">)</span> <span style="color: #00C800;">CLASS</span> TPerceptron<br /><br /> <span style="color: #00C800;">local</span> n<br /><br /> ::<span style="color: #000000;">aWeights</span> = Array<span style="color: #000000;">(</span> nInputs <span style="color: #000000;">)</span><br /><br /> <span style="color: #00C800;">for</span> n = <span style="color: #000000;">1</span> <span style="color: #0000ff;">to</span> nInputs<br /> ::<span style="color: #000000;">aWeights</span><span style="color: #000000;">[</span> n <span style="color: #000000;">]</span> = <span style="color: #000000;">0</span><br /> <span style="color: #00C800;">next</span><br /><br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">Self</span><br /><br /><span style="color: #00C800;">METHOD</span> Learn<span style="color: #000000;">(</span> aInputs, nExpectedResult <span style="color: #000000;">)</span> <span style="color: #00C800;">CLASS</span> TPerceptron<br /><br /> <span style="color: #00C800;">local</span> nSum := ::<span style="color: #000000;">Calculate</span><span style="color: #000000;">(</span> aInputs <span style="color: #000000;">)</span><br /><br /> <span style="color: #00C800;">if</span> nSum < nExpectedResult<br /> ::<span style="color: #000000;">aWeights</span><span style="color: #000000;">[</span> <span style="color: #000000;">1</span> <span style="color: #000000;">]</span> += <span style="color: #000000;">0.1</span><br /> <span style="color: #00C800;">endif</span><br /><br /> <span style="color: #00C800;">if</span> nSum > nExpectedResult<br /> ::<span style="color: #000000;">aWeights</span><span style="color: #000000;">[</span> <span style="color: #000000;">1</span> <span style="color: #000000;">]</span> -= <span style="color: #000000;">0.1</span><br /> <span style="color: #00C800;">endif</span><br /><br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">nil</span> <br /><br /><span style="color: #00C800;">METHOD</span> Calculate<span style="color: #000000;">(</span> aInputs <span style="color: #000000;">)</span> <span style="color: #00C800;">CLASS</span> TPerceptron<br /><br /> <span style="color: #00C800;">local</span> n, nSum := <span style="color: #000000;">0</span><br /><br /> <span style="color: #00C800;">for</span> n = <span style="color: #000000;">1</span> <span style="color: #0000ff;">to</span> Len<span style="color: #000000;">(</span> aInputs <span style="color: #000000;">)</span><br /> nSum += aInputs<span style="color: #000000;">[</span> n <span style="color: #000000;">]</span> * ::<span style="color: #000000;">aWeights</span><span style="color: #000000;">[</span> n <span style="color: #000000;">]</span><br /> <span style="color: #00C800;">next</span><br /><br /><span style="color: #00C800;">return</span> nSum</div>[/code:2wih07x9]
|
Artificial intelligence - Class TPerceptron
|
Antonio,
Inteligência Artificial
<!-- m --><a class="postlink" href="https://www.facebook.com/504184556441407/videos/568926636633865">https://www.facebook.com/50418455644140 ... 6636633865</a><!-- m -->
<!-- m --><a class="postlink" href="https://www.youtube.com/watch?v=h0DyYLLf3m8">https://www.youtube.com/watch?v=h0DyYLLf3m8</a><!-- m -->
|
Artificial intelligence - Class TPerceptron
|
[url:3alvrg4b]http://www.learnartificialneuralnetworks.com/neural-network-software/backpropagation-source-code/[/url:3alvrg4b]
|
Artificial intelligence - Class TPerceptron
|
[url:1wg8s8mx]https://github.com/alkresin/hrb4fann[/url:1wg8s8mx]
[url:1wg8s8mx]http://leenissen.dk/[/url:1wg8s8mx]
[url:1wg8s8mx]https://github.com/libfann/fann[/url:1wg8s8mx]
FannTool:
[url:1wg8s8mx]https://bitbucket.org/birolkuyumcu/fanntool/downloads/[/url:1wg8s8mx]
documentation:
[url:1wg8s8mx]https://sourceforge.net/projects/fann/files/fann_doc/1.0/fann_doc_complete_1.0.pdf[/url:1wg8s8mx]
[url:1wg8s8mx]https://es.slideshare.net/bluekid/fann-tool-usersguide[/url:1wg8s8mx]
|
Artificial intelligence - Class TPerceptron
|
[b:39azm5uk]Scaled value:[/b:39azm5uk] ( Input Value - Minimum ) / ( Maximum - Minimum )
[b:39azm5uk]Descaled value (Input Value):[/b:39azm5uk] ( Scaled value * ( Maximum - Minimum ) ) + Minimum
|
Artificial intelligence - Class TPerceptron
|
Test of scaling and descaling values:
Scaling: ( value - minimum ) / ( Maximum - Minimum )
0 --> ( 0 - 0 ) / ( 9 - 0 ) --> 0
1 --> ( 1 - 0 ) / ( 9 - 0 ) --> 0.111
2 --> ( 2 - 0 ) / ( 9 - 0 ) --> 0.222
3 --> ( 3 - 0 ) / ( 9 - 0 ) --> 0.333
4 --> ( 4 - 0 ) / ( 9 - 0 ) --> 0.444
5 --> ( 5 - 0 ) / ( 9 - 0 ) --> 0.555
6 --> ( 6 - 0 ) / ( 9 - 0 ) --> 0.666
7 --> ( 7 - 0 ) / ( 9 - 0 ) --> 0.777
8 --> ( 8 - 0 ) / ( 9 - 0 ) --> 0.888
9 --> ( 9 - 0 ) / ( 9 - 0 ) --> 1
|
Artificial intelligence - Class TPerceptron
|
In TensorFlow we have the [b:2dhjlltl]Softmax[/b:2dhjlltl] function which transforms the output of each unit to a value between 0 and 1, and makes the sum of all units equals 1. It will tell us the probability of each category
[url:2dhjlltl]https://medium.com/@Synced/big-picture-machine-learning-classifying-text-with-neural-networks-and-tensorflow-da3358625601[/url:2dhjlltl]
|
Artificial intelligence - Class TPerceptron
|
Hola !
Articulo interesante que ayuda a entrar en este mundillo... <!-- m --><a class="postlink" href="https://blogs.elconfidencial.com/tecnologia/tribuna/2017-09-02/deep-learning-demonios-explicacion_1437007/">https://blogs.elconfidencial.com/tecnol ... n_1437007/</a><!-- m -->
Saludetes.
|
As I can define this function to use in the FWH/xHarbour ?
|
Antonio,
As I can define this function to use in the FWH/xHarbour ?
[code:2hp6kag5]CreateTerWindow
Open a TER Window:
HWND CreateTerWindow(ptr)
struct arg_list far *ptr;
The ptr argument points to a structure that provides the initial parameters to open a window. This structure includes the following parameters:
struct arg_list {
int x
Initial X position of the editing window. You may specify CW_USEDEFAULT here to use the default value. The CW_USEDEFAULT constant is defined by Windows as hex 8000 for 16 bit and hex 80000000 for 32 bit.
int y
Initial Y position of the editing window. You may specify CW_USEDEFAULT here to use the default value.
int width
Window width. You may specify CW_USEDEFAULT here to use the default value
int height
Window Height. You may specify CW_USEDEFAULT here to use the default value.
int LineLimit
Maximum number of lines allowed for text editing. Set this field to 0 to allow unlimited number of lines.
BOOL WordWrap
If set to TRUE, this flag enables the word wrapping feature.
BOOL PrintView
Normally (PrintView = FALSE) the text lines are wrapped at the right edge of the window. This is a convenient editing mode with better performance. In the print view edit mode, however, the text lines are wrapped as they would be wrapped when printed at the current printer.
BOOL PageMode
Set to TRUE to facilitate editing of documents one page at a time. This feature is useful when editing multiple column documents. The text is displayed in side-by-side columns. This mode also implies the PrintView mode.
BOOL FittedView
Special case of the page mode in which the text wraps to the window width and the soft page breaks are not displayed
BOOL ShowStatus
If set to TRUE, the editor will display a status line describing the current cursor location, and the insert/overtype indicator.
BOOL ShowMenu
If set to TRUE, the editor displays the editor menu under the caption bar. When set to FALSE, the editor commands must be selected using only the accelerator keys.
BOOL ShowHorBar
If set to TRUE, the editor displays the horizontal scroll bar.
BOOL ShowVerBar
If set to TRUE, the editor displays the vertical scroll bar.
BOOL ruler
Set this variable to TRUE to show a ruler with tab stops.
BOOL ToolBar
Set this variable to TRUE to show the tool bar.
BOOL UserCanClose
Set this variable to TRUE if you want your user to be able to close the TER window by selecting the exit option from the TER menu. Otherwise, your application will need to close the window by using the CloseTer function.
BOOL BorderMargins
Set this field to TRUE to create a thin margin around the text area within the TER window. This margin area is for cosmetic purpose only.
BOOL ReadOnly
This is a browser mode which does not allow text modifications.
int InitLine
The first line number to position on when the TER routine is called.
char InputType
This field specifies the input type to the editor. If you wish to pass a text file name to the editor, set this flag to 'F'. However, if the text input will be passed in a global memory buffer, set this flag to 'B'.
char file[129]
If the InputType field is set to 'F', this field specifies the full path of the input file.
HANDLE hBuffer
If the InputType field is set to 'B', this field specifies the handle to the global memory containing the input text data. To specify an empty buffer, allocate a buffer for 1 byte, place the 'delim' character in the first byte and set the 'BufferLen' field to 1. The input memory handle must be unlocked before calling the editor routine. You can get the updated text by using the GetTerBuffer prior to closing the TER window.
long BufferLen
When the InputType field is set to 'B', the BufferLen field specifies the length of the input buffer.
char delim
This character should be be set to 13 (carriage return character).
int SaveFormat
This field determines the format of the output file or buffer:
SAVE_DEFAULT:
Save in the format of the input file.
SAVE_TER:
Save in the native TER format.
SAVE_RTF:
Save in the Rich Text Format.
SAVE_TEXT:
Save in ASCII format.
SAVE_TEXT_LINES:
Save in ASCII format with line breaks.
SAVE_UTEXT
Save in the Unicode text format (not available in 16 bit)
HANDLE hInst
Handle for the current instance of the application.
HWND hParentWnd
Handle of the parent window. The DLL sends the TER_CLOSE message to this function before closing a TER window (see the CloseTer API function).
HWND hTextWnd
The editor fills in this field with the window handle of the editor window. The editor does this as soon as the window is created. You will need this handle to use other TER API functions.
DWORD style
The window style that you provide here is simply passed to the CreateWindow function.
char FontTypeFace[30]
Default font typeface for the document. Example: "Helv", "Courier", "System" etc. A menu option in the TER window provides multiple selections of typeface and point sizes to choose from.
int PointSize
Point size of the default font. Please remember that 72 points are equal to one inch. Most written correspondences use a letter size of 10 or 12 points.
BOOL open
The editor set this variable to a TRUE value after initializing a TER window.
BOOL modified
This variable is reserved for internal use.
}
Description: This function opens a TER window.
Return Value: If successful, the function returns the window handle of the new window. Otherwise it returns a NULL value. The handle to the newly opened window is also returned to you using the hTextWnd variable within the arg_list structure. If your application provides the data using a global buffer, the handle to the specified global buffer becomes the property of the DLL. Your application MUST not try to lock or free this handle. To get the updated text data, you should use the GetTerBuffer function.
Comments: This function is not available as an ActiveX control method. It must be used as a DLL function.
[/code:2hp6kag5]
|
As I can define this function to use in the FWH/xHarbour ?
|
Vilian,
The easiest way is to fill the C structure from C code:
[code:2hxidul6]
#pragma BEGINDUMP
#include <windows.h>
#include <hbapi.h>
HB_FUNC( CREATETERWINDOW )
{
struct arg_list ptr;
... fill the ptr ... members using hb_par...( x ), i.e.:
ptr.width = hb_parnl( 3 );
hb_retnl( ( ULONG ) CreateTerWindow( &ptr ) );
}
#pragma ENDDUMP
[/code:2hxidul6]
|
As I can define this function to use in the FWH/xHarbour ?
|
Antonio,
When I try to compile appear the following messages:
[code:17v8cehx]Error E2450 \\tec2000\\sig50\\SIG241.PRG 1410: Undefined structure 'arg_list' in function HB_FUN_CREATETERWINDOW
Error E2449 \\tec2000\\sig50\\SIG241.PRG 1410: Size of 'ptr' is unknown or zero in function HB_FUN_CREATETERWINDOW
Error E2450 \\tec2000\\sig50\\SIG241.PRG 1410: Undefined structure 'arg_list' in function HB_FUN_CREATETERWINDOW
Error E2450 \\tec2000\\sig50\\SIG241.PRG 1410: Undefined structure 'arg_list' in function HB_FUN_CREATETERWINDOW
Error E2449 \\tec2000\\sig50\\SIG241.PRG 1410: Size of 'ptr' is unknown or zero in function HB_FUN_CREATETERWINDOW
Error E2451 \\tec2000\\sig50\\SIG241.PRG 1412: Undefined symbol 'x' in function HB_FUN_CREATETERWINDOW
Error E2451 \\tec2000\\sig50\\SIG241.PRG 1413: Undefined symbol 'y' in function HB_FUN_CREATETERWINDOW
Error E2451 \\tec2000\\sig50\\SIG241.PRG 1414: Undefined symbol 'width' in function HB_FUN_CREATETERWINDOW
Error E2451 \\tec2000\\sig50\\SIG241.PRG 1415: Undefined symbol 'height' in function HB_FUN_CREATETERWINDOW
Warning W8065 \\tec2000\\sig50\\SIG241.PRG 1417: Call to function 'CreateTerWindow' with no prototype in function HB_FUN_CREATETERWINDOW
[/code:17v8cehx]
What I am making made a mistake?
|
As I can define this function to use in the FWH/xHarbour ?
|
Try it this way:
[code:2it2b738]
#pragma BEGINDUMP
#include <windows.h>
#include <hbapi.h>
HWND CreateTerWindow( ... );
HB_FUNC( CREATETERWINDOW )
{
hb_retnl( ( ULONG ) CreateTerWindow( hb_parnl( 1 ), // x
hb_parnl( 2 ), // y
hb_parnl( 3 ), // width
hb_parnl( 4 ), // height
hb_parnl( 5 ), // lineLimit
hb_parl( 6 ), // WordWrap
hb_parl( 7 ), // PrintView
hb_parl( 8 ), // PageMode
hb_parl( 9 ), // FittedView
<continue you :-) >
) );
}
#pragma ENDDUMP
[/code:2it2b738]
|
As I can define this function to use in the FWH/xHarbour ?
|
Antonio,
Thanks.
|
As I can define this function to use in the FWH/xHarbour ?
|
[quote="vilian":305k87st]Antonio,
Thanks.[/quote:305k87st]Hola Vilian,Conseguistes funcionar CreateTerWindow() desde FWH?Cómo?SaludosCarlos G.
|
As I can define this function to use in the FWH/xHarbour ?
|
Sim, o suporte de subsystem é excelente e ajudou muito.[code:30dxv44v]xDll := LoadLib32("TER15.DLL")
TerSetLicenceKey("XXXX-XXXX-XXXX")
DEFINE WINDOW oWndEdt TITLE "Editor de Laudos" MDICHILD OF oWnd
DEFINE BUTTONBAR oBar 3D SIZE 22,27 TOP OF oWndEdt
DEFINE BUTTON NAME "OPEN" OF oBar ;
ACTION( AbrirLaudo(oWndEdt,oActivex) ) ;
TOOLTIP "Definir Laudos de Exames" ;
NOBORDER
DEFINE BUTTON NAME "AUTOTEXT" OF oBar ;
ACTION ( DefAutoText(cMedAtual,oWndEdt) );
TOOLTIP "Definir Auto-textos" ;
WHEN .NOT. Empty(cMedAtual) NOBORDER
DEFINE BUTTON NAME "BBASS" OF oBar ;
ACTION ( IncAssMed(cMedAtual,oWndEdt) ) ;
TOOLTIP "Incluir assinatura do médico no laudo" ;
WHEN .NOT. Empty(cMedAtual) NOBORDER
DEFINE BUTTON NAME "BBINIBAK" OF oBar ;
ACTION( GravaArquivo() ) ;
TOOLTIP "Salvar arquivo" ;
NOBORDER
DEFINE BUTTON NAME "BBCONS" OF oBar ;
ACTION( PesqLaudo(oWndEdt) ) ;
TOOLTIP "Pesquisar Laudos por paciente" ;
NOBORDER
DEFINE BUTTON NAME "BBPRINT" OF oBar ;
ACTION IF(GravaArquivo(.t.),oActiveX:Do("TerCommand",ID_PRINT),NIL);
TOOLTIP "Imprimir laudos" ;
NOBORDER
DEFINE BUTTON NAME "BBPESQ" OF oBar ;
ACTION oActiveX:Do("TerCommand",ID_PRINT_PREVIEW);
TOOLTIP "Visualizar impressão" ;
NOBORDER
DEFINE BUTTON NAME "UNDO" OF oBar ;
ACTION(oActiveX:Do("TerCommand",ID_UNDO));
TOOLTIP "Desfaz";
NOBORDER;
GROUP
DEFINE BUTTON NAME "REDO" OF oBar ;
ACTION(oActiveX:Do("TerCommand",ID_REDO));
TOOLTIP "ReFaz";
NOBORDER
DEFINE BUTTON oBtn NAME "LINDUP" OF oBar ;
ACTION MudaTipoLinha(oBtn) ;
TOOLTIP "Espaço duplo entre linhas";
NOBORDER;
GROUP
DEFINE BUTTON NAME "EXITEDT" OF oBar ;
ACTION ( FechaEditor() ) ;
TOOLTIP "Fechar/Sair do editor";
NOBORDER GROUP
@ 7, 300 SAY oSayEdt PROMPT "Chv:" SIZE 160, 15 PIXEL OF oBar
oActiveX = TActiveX():New( oWndEdt, "TOC15.Toc15Ctrl.1" )
oWndEdt:oClient = oActiveX // To fill the entire window surface
oActiveX:Do("TerCommand",ID_RULER)
oActiveX:Do("TerCommand",ID_TOOL_BAR)
oActiveX:Do("TerCommand",ID_SHOW_PAGE_BORDER)
oActiveX:Do("TerSetFlags4",1,TFLAG4_ONE_ROW_TOOLBAR)
oActiveX:Do("TerRecreateToolbar",1)
oActiveX:bOnEvent := { | event, aParams,nKey,nx,ny | EventInfo( event, aParams,oActiveX,nKey,nx,ny ) }
oEditor := TEditor()
oEditor:cAlias := "AUT"
oEditor:Cargo := {NIL,NIL,cMedAtual}
nHand := oActiveX:GetProp("hWnd")
ACTIVATE WINDOW oWndEdt MAXIMIZED[/code:30dxv44v]
|
As I can define this function to use in the FWH/xHarbour ?
|
[quote="vilian":1bya4kxv]Sim, o suporte de subsystem é excelente e ajudou muito.
[code:1bya4kxv]xDll := LoadLib32("TER15.DLL")
TerSetLicenceKey("XXXX-XXXX-XXXX")
DEFINE WINDOW oWndEdt TITLE "Editor de Laudos" MDICHILD OF oWnd
DEFINE BUTTONBAR oBar 3D SIZE 22,27 TOP OF oWndEdt
DEFINE BUTTON NAME "OPEN" OF oBar ;
ACTION( AbrirLaudo(oWndEdt,oActivex) ) ;
TOOLTIP "Definir Laudos de Exames" ;
NOBORDER
DEFINE BUTTON NAME "AUTOTEXT" OF oBar ;
ACTION ( DefAutoText(cMedAtual,oWndEdt) );
TOOLTIP "Definir Auto-textos" ;
WHEN .NOT. Empty(cMedAtual) NOBORDER
DEFINE BUTTON NAME "BBASS" OF oBar ;
ACTION ( IncAssMed(cMedAtual,oWndEdt) ) ;
TOOLTIP "Incluir assinatura do médico no laudo" ;
WHEN .NOT. Empty(cMedAtual) NOBORDER
DEFINE BUTTON NAME "BBINIBAK" OF oBar ;
ACTION( GravaArquivo() ) ;
TOOLTIP "Salvar arquivo" ;
NOBORDER
DEFINE BUTTON NAME "BBCONS" OF oBar ;
ACTION( PesqLaudo(oWndEdt) ) ;
TOOLTIP "Pesquisar Laudos por paciente" ;
NOBORDER
DEFINE BUTTON NAME "BBPRINT" OF oBar ;
ACTION IF(GravaArquivo(.t.),oActiveX:Do("TerCommand",ID_PRINT),NIL);
TOOLTIP "Imprimir laudos" ;
NOBORDER
DEFINE BUTTON NAME "BBPESQ" OF oBar ;
ACTION oActiveX:Do("TerCommand",ID_PRINT_PREVIEW);
TOOLTIP "Visualizar impressão" ;
NOBORDER
DEFINE BUTTON NAME "UNDO" OF oBar ;
ACTION(oActiveX:Do("TerCommand",ID_UNDO));
TOOLTIP "Desfaz";
NOBORDER;
GROUP
DEFINE BUTTON NAME "REDO" OF oBar ;
ACTION(oActiveX:Do("TerCommand",ID_REDO));
TOOLTIP "ReFaz";
NOBORDER
DEFINE BUTTON oBtn NAME "LINDUP" OF oBar ;
ACTION MudaTipoLinha(oBtn) ;
TOOLTIP "Espaço duplo entre linhas";
NOBORDER;
GROUP
DEFINE BUTTON NAME "EXITEDT" OF oBar ;
ACTION ( FechaEditor() ) ;
TOOLTIP "Fechar/Sair do editor";
NOBORDER GROUP
@ 7, 300 SAY oSayEdt PROMPT "Chv:" SIZE 160, 15 PIXEL OF oBar
oActiveX = TActiveX():New( oWndEdt, "TOC15.Toc15Ctrl.1" )
oWndEdt:oClient = oActiveX // To fill the entire window surface
oActiveX:Do("TerCommand",ID_RULER)
oActiveX:Do("TerCommand",ID_TOOL_BAR)
oActiveX:Do("TerCommand",ID_SHOW_PAGE_BORDER)
oActiveX:Do("TerSetFlags4",1,TFLAG4_ONE_ROW_TOOLBAR)
oActiveX:Do("TerRecreateToolbar",1)
oActiveX:bOnEvent := { | event, aParams,nKey,nx,ny | EventInfo( event, aParams,oActiveX,nKey,nx,ny ) }
oEditor := TEditor()
oEditor:cAlias := "AUT"
oEditor:Cargo := {NIL,NIL,cMedAtual}
nHand := oActiveX:GetProp("hWnd")
ACTIVATE WINDOW oWndEdt MAXIMIZED[/code:1bya4kxv][/quote:1bya4kxv]Vilian,Esta noche lo pruebo.Um Grande ObrigadoCarlos G.
|
As byte
|
Estoy usando un control activeX, y necesito llamar un metodo y pasarle un parmetro, dicho parametro espera recibirlo del tipo array de bytes (ByRef aRawData() As Byte) ).
Alguna idea para pasarselo desde harbour.
El parametro es el contenido de un fichero binario.
En VB se hace de la siguiente forma:
[code=fw:3sa6kv98]<div class="fw" id="{CB}" style="font-family: monospace;"><br />Dim blob<span style="color: #000000;">(</span><span style="color: #000000;">)</span> As Byte<br /> <span style="color: #ff0000;">' Read binary data from file.<br /> Open CommonDialog1.FileName For Binary As #1<br /> ReDim blob(LOF(1))<br /> Get #1, , blob()<br /> Close #1<br /> Templ.Deserialize blob<br /></span></div>[/code:3sa6kv98]
Esto mismo desde harbour y pasandole como parametro el contenido del fichero leido con fRead, no funciona.
Si con el propio activex, ejecuto serialize y lo muevo a una variable, y despues la paso al activex si funciona.
[code=fw:3sa6kv98]<div class="fw" id="{CB}" style="font-family: monospace;"><br />cTmp:= oAx:<span style="color: #000000;">Serialize</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span><br />oAx:<span style="color: #000000;">DeSearialize</span><span style="color: #000000;">(</span> cTmp <span style="color: #000000;">)</span> <span style="color: #B900B9;">//Ok</span><br /> </div>[/code:3sa6kv98]
Cualquier otro parametro leido desde fichero, de otra variable, etc no fucniona, aunque en teoria son "identicos" en tamaño, etc.
|
As byte
|
<!-- l --><a class="postlink-local" href="http://forums.fivetechsupport.com/viewtopic.php?f=3&t=16746">viewtopic.php?f=3&t=16746</a><!-- l -->
|
As byte
|
Hola...
Perdón por entrar a este post con otro tema...
Escribo para comentarle a Biel que estuve mirando su blog y dejé un comentario en el topic de Compresión y descrompresión de ficheros Zip...
Tuve algunos problemitas con sus funciones, y quizá amablemente podría darme una mano.
Desde ya muchas gracias, y nuevamente disculpas.
Saludos,
|
As byte
|
Esteban, te he contestado en el blog.
|
As byte
|
[quote="Antonio Linares":3p4peptw]Biel,
This is obvious, but have you tried it in this order ?
[code=fw:3p4peptw]<div class="fw" id="{CB}" style="font-family: monospace;"><br />oTmp:<span style="color: #000000;">Deserialize</span><span style="color: #000000;">(</span> xVar2<span style="color: #000000;">)</span> <span style="color: #B900B9;">//Crash</span><br />oTmp:<span style="color: #000000;">Deserialize</span><span style="color: #000000;">(</span> xVar1<span style="color: #000000;">)</span> <span style="color: #B900B9;">//Runs Ok</span><br /> </div>[/code:3p4peptw][/quote:3p4peptw]
No funciona cambiando el orden, el control activex casca al pasarle el parametro, el parametro no es del tipo esperado y produce un error.
El tema es que una variable harbour es capaz de contener un valor valido, pero desde Harbour soy incapaz de genera ese tipo de dato.
No habria alguna manera desde una funcion de C retornar un tipo as byte, y colocarlo en una variable Harbour.
|
As byte
|
Hola Biel...
No he probado esto, pero puedes intentar de esta manera...
[code=fw:w34mz90n]<div class="fw" id="{CB}" style="font-family: monospace;"><br />....<br />Serialize<span style="color: #000000;">(</span> oAx, xVal <span style="color: #000000;">)</span><br />...<br /><br /><span style="color: #00D7D7;">#pragma</span> BEGINDUMP<br /><br /><span style="color: #00D7D7;">#include</span> <hbapi.h><br /><span style="color: #00D7D7;">#include</span> <hbvm.h> <br /><br /><br /><span style="color: #00C800;">HB_FUNC</span><span style="color: #000000;">(</span> SERIALIZE <span style="color: #000000;">)</span> <br /><span style="color: #000000;">{</span> <br /> PHB_ITEM pObj = hb_param<span style="color: #000000;">(</span> <span style="color: #000000;">1</span>, HB_IT_OBJECT <span style="color: #000000;">)</span>;<br /> PHB_ITEM pStr = hb_param<span style="color: #000000;">(</span> <span style="color: #000000;">2</span>, HB_IT_STRING <span style="color: #000000;">)</span>;<br /><br /> hb_vmPushSymbol<span style="color: #000000;">(</span> hb_dynsymGetSymbol<span style="color: #000000;">(</span> <span style="color: #ff0000;">"SERIALIZE"</span> <span style="color: #000000;">)</span> <span style="color: #000000;">)</span>; <br /> hb_vmPush<span style="color: #000000;">(</span> pObj <span style="color: #000000;">)</span>; <br /> hb_vmPush<span style="color: #000000;">(</span> pStr <span style="color: #000000;">)</span>;<br /> hb_vmFunction<span style="color: #000000;">(</span> <span style="color: #000000;">1</span> <span style="color: #000000;">)</span>; <br /><br /><span style="color: #000000;">}</span> <br /><br /><span style="color: #00D7D7;">#pragma</span> ENDDUMP<br /> </div>[/code:w34mz90n]
|
As byte
|
Biel,
Que ActiveX es ? Hay demo de él ?
|
As byte
|
Biel,
Pensando en el asunto, has probado esto ?
[code=fw:34pzwcio]<div class="fw" id="{CB}" style="font-family: monospace;"><br />xVar2 := xVar1<br />oTmp:<span style="color: #000000;">Deserialize</span><span style="color: #000000;">(</span> xVar2 <span style="color: #000000;">)</span><br /> </div>[/code:34pzwcio]
|
As byte
|
[quote="Daniel Garcia-Gil":10ul4lxa]Hola Biel...
No he probado esto, pero puedes intentar de esta manera...
[code=fw:10ul4lxa]<div class="fw" id="{CB}" style="font-family: monospace;"><br />....<br />Serialize<span style="color: #000000;">(</span> oAx, xVal <span style="color: #000000;">)</span><br />...<br /><br /><span style="color: #00D7D7;">#pragma</span> BEGINDUMP<br /><br /><span style="color: #00D7D7;">#include</span> <hbapi.h><br /><span style="color: #00D7D7;">#include</span> <hbvm.h> <br /><br /><br /><span style="color: #00C800;">HB_FUNC</span><span style="color: #000000;">(</span> SERIALIZE <span style="color: #000000;">)</span> <br /><span style="color: #000000;">{</span> <br /> PHB_ITEM pObj = hb_param<span style="color: #000000;">(</span> <span style="color: #000000;">1</span>, HB_IT_OBJECT <span style="color: #000000;">)</span>;<br /> PHB_ITEM pStr = hb_param<span style="color: #000000;">(</span> <span style="color: #000000;">2</span>, HB_IT_STRING <span style="color: #000000;">)</span>;<br /><br /> hb_vmPushSymbol<span style="color: #000000;">(</span> hb_dynsymGetSymbol<span style="color: #000000;">(</span> <span style="color: #ff0000;">"SERIALIZE"</span> <span style="color: #000000;">)</span> <span style="color: #000000;">)</span>; <br /> hb_vmPush<span style="color: #000000;">(</span> pObj <span style="color: #000000;">)</span>; <br /> hb_vmPush<span style="color: #000000;">(</span> pStr <span style="color: #000000;">)</span>;<br /> hb_vmFunction<span style="color: #000000;">(</span> <span style="color: #000000;">1</span> <span style="color: #000000;">)</span>; <br /><br /><span style="color: #000000;">}</span> <br /><br /><span style="color: #00D7D7;">#pragma</span> ENDDUMP<br /> </div>[/code:10ul4lxa][/quote:10ul4lxa]
Hola Daniel, gracias por tu sugerencia, lo he probado y da el mismo error que si le paso al activex una cadena de caracteres.
|
As byte
|
[quote="Antonio Linares":3biwmw41]Biel,
Pensando en el asunto, has probado esto ?
[code=fw:3biwmw41]<div class="fw" id="{CB}" style="font-family: monospace;"><br />xVar2 := xVar1<br />oTmp:<span style="color: #000000;">Deserialize</span><span style="color: #000000;">(</span> xVar2 <span style="color: #000000;">)</span><br /> </div>[/code:3biwmw41][/quote:3biwmw41]
Si, esto lo habia probado y funciona ok.
Intentare enviarte el Activex.
|
As byte
|
Biel,
Me parece que es un bug generado entre el soporte de OLE y el ItemApi. Te explico mis razones:
1. El valor que viene devuelto del ActiveX se pasa de Variant a Item de Harbour/xHarbour usando: hb_oleVariantToItem()
2. Puesto que es de tipo "C", se ha llamado a la función hb_itemPutCPtr():
[code=fw:1exkgrmk]<div class="fw" id="{CB}" style="font-family: monospace;"><br /> <span style="color: #00C800;">case</span> VT_BSTR:<br /> <span style="color: #000000;">{</span><br /> char* szString = WideToAnsi<span style="color: #000000;">(</span> pVariant->n1.n2.n3.bstrVal <span style="color: #000000;">)</span>;<br /> hb_itemPutCPtr<span style="color: #000000;">(</span> pItem, szString <span style="color: #000000;">)</span>;<br /> <span style="color: #00C800;">break</span>;<br /> <span style="color: #000000;">}</span><br /> </div>[/code:1exkgrmk]
3. Y el bug finalmente se produce por contener ceros la cadena, en estas líneas de hb_itemPutCPtr():
[code=fw:1exkgrmk]<div class="fw" id="{CB}" style="font-family: monospace;"><br /> ulLen = szText ? <span style="color: #0000ff;">strlen</span><span style="color: #000000;">(</span> szText <span style="color: #000000;">)</span> : <span style="color: #000000;">0</span>; <span style="color: #B900B9;">// no se deberia usar strlen() pues no reconoce ceros dentro de la cadena</span><br /> pItem->item.asString.length = ulLen; <span style="color: #B900B9;">// incorrecto! </span><br /> ...<br /> pItem->item.asString.value = szText; <span style="color: #B900B9;">// el puntero se asigna tal cual, luego conserva todos los bytes</span><br /> </div>[/code:1exkgrmk]
Resumiendo: el contenido del item cadena y su longitud no se corresponden
Hay que reportarlo a las listas de Harbour y xHarbour para que se verifique este bug y en caso afirmativo, que se corrija.
Y gracias a ti por haberlo puesto de manifiesto <!-- s:-) --><img src="{SMILIES_PATH}/icon_smile.gif" alt=":-)" title="Smile" /><!-- s:-) -->
|
As byte
|
[url:1r1ocu1n]http://www.matrixlist.com/pipermail/harbour/2009-September/025325.html[/url:1r1ocu1n]
|
As byte
|
Biel,
Este cambio en olecore.c deberia solucionar el bug:
[code=fw:12t53931]<div class="fw" id="{CB}" style="font-family: monospace;"><br /> <span style="color: #00C800;">case</span> VT_BSTR:<br /> <span style="color: #000000;">{</span><br /> char* szString = WideToAnsi<span style="color: #000000;">(</span> pVariant->n1.n2.n3.bstrVal <span style="color: #000000;">)</span>;<br /> hb_itemPutCLPtr<span style="color: #000000;">(</span> pItem, szString, WideCharToMultiByte<span style="color: #000000;">(</span><br />CP_ACP, <span style="color: #000000;">0</span>, pVariant->n1.n2.n3.bstrVal, <span style="color: #000000;">-1</span>, <span style="color: #00C800;">NULL</span>, <span style="color: #000000;">0</span>, <span style="color: #00C800;">NULL</span>, <span style="color: #00C800;">NULL</span> <span style="color: #000000;">)</span> <span style="color: #000000;">)</span>;<br /> <span style="color: #00C800;">break</span>;<br /> <span style="color: #000000;">}</span><br /> </div>[/code:12t53931]
|
As byte
|
Muchas gracias Antonio por el tiempo dedicado, para mi hubiera sido imposible localizarlo.
No he podido comprobar el funcionamiento, hoy salgo de viaje, pero cuando regrese de Andorra, interar compilar los cambios y te comento.
|
As byte
|
Biel,
El bug fué arreglado unos dias antes en el propio repositorio de Harbour <!-- s:-) --><img src="{SMILIES_PATH}/icon_smile.gif" alt=":-)" title="Smile" /><!-- s:-) -->
Solo hay que volver a construir un nuevo build de Harbour y listo <!-- s:-) --><img src="{SMILIES_PATH}/icon_smile.gif" alt=":-)" title="Smile" /><!-- s:-) -->
|
As download a file from xharbour in a fixed route without q
|
WaitRun(iexplore()+"http://www.aduanet.gob.pe/aduanas/sgdbf/Vehiculos.zip")
As download a file from xharbour in a fixed route without q the users the route
|
As to catch return of oActiveX:Do
|
hi,
I need to catch the return of the following command:
oActiveX:Do("TerSearchReplace2","rich","",SRCH_SEARCH,N,0)
According to documentation of the [b:r6eul5q6]TerSearchReplace2[/b:r6eul5q6] component would have to return a numerical value.
|
As to catch return of oActiveX:Do
|
Vilian,
Try:
MsgInfo( oActiveX:Do("TerSearchReplace2","rich","",SRCH_SEARCH,N,0) )
|
As to catch return of oActiveX:Do
|
Antonio,
Already I tried thus and is returning NIL.
|
As to catch return of oActiveX:Do
|
Antonio,
Studying activex.prg with the aid of the Gilmer, we perceive that the Do() method treats only 4(four) parameters. But necessary TerSearchReplace2 of 5(five). We try to make thus:
nPos := ActXInvoke( ActXPdisp( oActiveX:hActiveX ),"TerSearchReplace2","rich","",SRCH_SEARCH,N,0)
But also it did not function. You can help me?
|
As to catch return of oActiveX:Do
|
Vilian,
Are you using Harbour or xHarbour ?
|
As to catch return of oActiveX:Do
|
Antonio,
I use xHarbour.
|
As to catch return of oActiveX:Do
|
Vilian,
Please do this: tlib fivehc.lib - ole.obj
then add these functions to your app:
[code:3lygq5xq]
function OleGetProperty( hObj, cPropName )
local o := TOleAuto()
local uRet
o:hObj = hObj
uRet = __ObjSendMsg( o, cPropName )
o:hObj = nil
return uRet
function OleSetProperty( hObj, cPropName, uValue )
local o := TOleAuto()
local uRet
o:hObj = hObj
uRet = __ObjSendMsg( o, "_" + cPropName, uValue )
o:hObj = nil
return uRet
function OleInvoke( hObj, cMethName, ... )
local o := TOleAuto()
local uRet
o:hObj = hObj
uRet = o:Invoke( cMethName, ... )
o:hObj = nil
return uRet
[/code:3lygq5xq]
|
As to catch return of oActiveX:Do
|
Antonio,
Later that I made what you asked for started to occur the following error:
[code:2j2av2ya]Application
===========
Path and name: F:\FWH\SAMPLES\pdf.exe (32 bits)
Size: 1,306,624 bytes
Time from start: 0 hours 0 mins 0 secs
Error occurred at: 07/31/07, 09:38:02
Error description: Error /16389 E_FAIL: TERCOMMAND
Args:
[ 1] = N 680
[ 2] = U
[ 3] = U
[ 4] = U
[ 5] = U
Stack Calls
===========
Called from: win32ole.prg => TOLEAUTO:TERCOMMAND(0)
Called from: => HB_EXECFROMARRAY(0)
Called from: win32ole.prg => TOLEAUTO:INVOKE(397)
Called from: => ACTXINVOKE(67)
Called from: ACTIVEX.PRG => TACTIVEX:DO(0)
Called from: pdf.prg => MAIN(16)[/code:2j2av2ya]
|
As to catch return of oActiveX:Do
|
Antonio,
I changed OleInvoke for the following one:
[code:288w5goi]function OleInvoke( hObj, cMethName, uPar1, uPar2, uPar3, uPar4, uPar5 )
local o := TOleAuto()
local uRet
o:hObj = hObj
IF uPar2 # NIL
uRet = o:Invoke( cMethName, uPar1, uPar2, uPar3, uPar4, uPar5 )
ELSE
uRet = o:Invoke( cMethName, uPar1 )
ENDIF
o:hObj = nil
return uRet[/code:288w5goi]
The error message stopped to happen, but I continue not receiving the return correct. I tried the following one:
[code:288w5goi]STATIC FUNCTION EventInfo(event, aParams,oActiveX,oWnd,nKey,nx,ny)
LOCAL nSt,text:=Space(100),font:="",n
IF Upper(event) $ "KEYPRESS"
? oActiveX:Do("TerSearchReplace2","rich","",SRCH_SEARCH,N,0)
ENDIF
RETURN NIL[/code:288w5goi]
It did not function, then I made as a test(see bellow), but also it did not function.
[code:288w5goi]STATIC FUNCTION EventInfo(event, aParams,oActiveX,oWnd,nKey,nx,ny)
LOCAL nSt,text:=Space(100),font:="",n
IF Upper(event) $ "KEYPRESS"
? OleInvoke(oActivex:hWnd,"TerSearchReplace2","rich","",SRCH_SEARCH,N,0)
ENDIF
RETURN NIL[/code:288w5goi]
|
As to catch return of oActiveX:Do
|
Vilian,
> ? OleInvoke(oActivex:hWnd, ...
That is not correct, as the first parameter is NOT the hWnd.
It has to be OleInvoke( ActXPdisp( oActivex:hActiveX ), ...
|
As to catch return of oActiveX:Do
|
Antonio,
Very grateful. Now he was ok.
|
As to catch return of oActiveX:Do
|
Antonio,
Now necessary to implement keyboard key accelerator(Sample: CTRL+P to print). I made thus:
[code:1sohd6hx]
oActiveX:bOnEvent := { | event, nKey | EventInfo( event, nKey ) }
STATIC FUNCTION EventInfo(event, nKey)
IF Upper(event) $ "KEYPRESS,KEYDOWN"
IF nKey = 80
.....
ENDIF
ENDIF
RETURN NIL
[/code:1sohd6hx]
[b:1sohd6hx]event[/b:1sohd6hx] is ok, But [b:1sohd6hx]nKey[/b:1sohd6hx] is returning NULL!
|
As to catch return of oActiveX:Do
|
have you tried with two params ?
oActiveX:bOnEvent := { | event, nKey1, nKey2 | EventInfo( event, nKey1, nKey2 ) }
|
As to catch return of oActiveX:Do
|
Antonio,
Yes, i tried with four params.
oActiveX:bOnEvent := { | event, nKey1, nKey2, nKey3, nKey4 | EventInfo( event, nKey1, nKey2, nKey3, nKey4 ) }
The return is:
nKey1 = array empty
nKey2 = 1242696 ever(constant)
nKey3 = NIL
nKey4 = NIL
|
As to catch return of oActiveX:Do
|
Vilian,
Analize the value 1242696 according to WM_KEYDOWN docs:
<!-- m --><a class="postlink" href="http://msdn2.microsoft.com/en-us/library/ms646280.aspx">http://msdn2.microsoft.com/en-us/library/ms646280.aspx</a><!-- m -->
unless that activex provides different parameters
|
As to catch return of oActiveX:Do
|
Antonio,
I verified the topic that you he suggested, I identified some functions for the treatment of messages, but I did not understand as they can help me !
|
As to catch return of oActiveX:Do
|
Vilian,
Do you always get 1242696 no matter what key you press ?
|
As to catch return of oActiveX:Do
|
Antonio,
any one.
|
As to catch return of oActiveX:Do
|
Do you get that value without pressing a key ?
What documentation about such event does your activex provides ?
|
As to catch return of oActiveX:Do
|
Antonio,
On these specific events the following text only exists:
[code:21dqwyrg]Standard events:
The control supports these standard events: Click, Double click, Got Focus, and Lost Focus, KeyDown, KeyPress, KeyUp. The KeyDown, KeyPress and KeyUp event take one integer parameter which passes the value of the key code.
[/code:21dqwyrg]
The support technician of them returned me the following one:
[code:21dqwyrg] KeyPress event is not an internal TE message (it is only an ActiveX message), it would not be routed to the callback message. The KeyPress event takes only one parameter which is the keyvalue for the keystroke. So nKey1 should be the numeric key values.[/code:21dqwyrg]
I tested this event in Visual Basic and it seems to work properly. However, VB shows only one parameter, which is nKey.
|
As to catch return of oActiveX:Do
|
Vilian,
You may need to modify these methods in Class TActiveX:
METHOD KeyChar() VIRTUAL
METHOD KeyDown() VIRTUAL
|
As to catch return of oActiveX:Do
|
Antonio,
I made the modification, but nothing he modified in the result.
|
As to catch return of oActiveX:Do
|
Vilian,
I don't know, don't have more ideas <!-- s:-( --><img src="{SMILIES_PATH}/icon_sad.gif" alt=":-(" title="Sad" /><!-- s:-( -->
Thats the problem with ActiveX (same as old Microsoft VBXs). We don't have their source code and we don't have full control over them
|
As to catch return of oActiveX:Do
|
Antonio,
If you to install the control in its computer help to decide the problem?
|
As to catch return of oActiveX:Do
|
Antonio,
I asked to the support of them - Exists some another way to implement what necessary?
The support technician of them returned me the following one:
[code:12kvpa9c]
If your application lets you define callback function, then you can use the TerRegisterMsgCallback function to register your callback function. TE would then route the internal TE messages to the callback function. The callback function should have the following prototypes:
LRESULT WINAPI _export TerCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
Also, since KeyPress event is not an internal TE message (it is only an ActiveX message), it would not be routed to the callback message. You can instead use the PreProcess event for this purpose.[/code:12kvpa9c]
Aid?
|
As to catch return of oActiveX:Do
|
Vilian,
> You can instead use the PreProcess event for this purpose.
Whats that ? Tell him to explain you whats the PreProcess event and a sample of its use
|
As your functions/methods become more complex
|
Hello friends,
As your functions/methods become more complex, splitting up, preprocessing and patching helps to simplify source code.
Best regards,
Otto
[url:3acgq6ut]https://www.facebook.com/groups/modharbour.club/?multi_permalinks=1190790684808490[/url:3acgq6ut]
|
As your functions/methods become more complex
|
Hello friends,
Here you can see an example of how to simplify a really complex source code like xBrowse with a patcher.
Best regards,
Otto
[img:1du4aww0]https://mybergland.com/harbourinoxbrowse_clip3.jpg[/img:1du4aww0]
[img:1du4aww0]https://mybergland.com/harbourinoxbrowse_clip4.jpg[/img:1du4aww0]
[img:1du4aww0]https://mybergland.com/harbourinoxbrowse_clip5.jpg[/img:1du4aww0]
[img:1du4aww0]https://mybergland.com/harbourinoxbrowse_clip6.jpg[/img:1du4aww0]
[img:1du4aww0]https://mybergland.com/harbourinoxbrowse_clip7.jpg[/img:1du4aww0]
|
AscW() function
|
Hi, all !
VBA (Excel) has an AscW() function. It is used to obtain the Unicode character code. How do I do this on FW ?
|
AscW() function
|
Please try
[code=fw:3igwcobk]<div class="fw" id="{CB}" style="font-family: monospace;"><br />HB_UTF8CHR<span style="color: #000000;">(</span> nChar <span style="color: #000000;">)</span><br /> </div>[/code:3igwcobk]
Maybe that is what you are looking for.
|
AscW() function
|
[url=https://docs.microsoft.com/it-it/dotnet/api/microsoft.visualbasic.strings.ascw?view=netframework-4.8:16ayodgd]AscW[/url:16ayodgd] return the unicode value from character or string. I think the Harbour version is HB_UTF8ASC:
[code=fw:16ayodgd]<div class="fw" id="{CB}" style="font-family: monospace;">HB_UTF8ASC<span style="color: #000000;">(</span> <cUtf8> <span style="color: #000000;">)</span> -> <nUnicode></div>[/code:16ayodgd]
HB_UTF8CHR is:
[code=fw:16ayodgd]<div class="fw" id="{CB}" style="font-family: monospace;">HB_UTF8CHR<span style="color: #000000;">(</span> <nUniVal> <span style="color: #000000;">)</span> -> <cUtf8Char></div>[/code:16ayodgd]
|
AscW() function
|
Yes, Mr. Antonio
And thanks for the correction.
|
AscW() function
|
Yes, the HB_UTF8Asc() function suits me, but it is not available for FWH18.06
|
AscW() function
|
This is not FWH function.
This is a Harbour function available both in Harbour and xHarbour.
|
AscW() function
|
I downloaded xHarbour Binaries 1.2.3 Rev. 10252 for BCC 5.8.2 with xharbour.org But when linking the hb_utf8asc function is not detected
|
AscW() function
|
I confirm: there is no hb_utf8asc() function in xHarbour. I can try to add it to xHarbour, if you really need it.
EMG
|
AscW() function
|
Yes, I do. I will be very grateful to you
|
AscW() function
|
Ok, I'll see what I can do...
EMG
|
AscW() function
|
Please, try this function and let me know if there are any problems:
[code=fw:32iwsqm5]<div class="fw" id="{CB}" style="font-family: monospace;"><span style="color: #00D7D7;">#include</span> <span style="color: #ff0000;">"Fivewin.ch"</span><br /><br /><br /><span style="color: #00C800;">FUNCTION</span> MAIN<span style="color: #000000;">(</span><span style="color: #000000;">)</span><br /><br /> ? HB_UTF8ASC<span style="color: #000000;">(</span> <span style="color: #ff0000;">"A"</span> <span style="color: #000000;">)</span><br /><br /> <span style="color: #00C800;">RETURN</span> <span style="color: #00C800;">NIL</span><br /><br /><br /><span style="color: #00D7D7;">#pragma</span> BEGINDUMP<br /><br /><br /><span style="color: #00D7D7;">#include</span> <span style="color: #ff0000;">"error.ch"</span><br /><span style="color: #00D7D7;">#include</span> <span style="color: #ff0000;">"hbapierr.h"</span><br /><br /><br /><span style="color: #00C800;">static</span> BOOL utf8tou16nextchar<span style="color: #000000;">(</span> UCHAR ucChar, int * n, USHORT * uc <span style="color: #000000;">)</span><br /><span style="color: #000000;">{</span><br /> <span style="color: #00C800;">if</span><span style="color: #000000;">(</span> *n > <span style="color: #000000;">0</span> <span style="color: #000000;">)</span><br /> <span style="color: #000000;">{</span><br /> <span style="color: #00C800;">if</span><span style="color: #000000;">(</span> <span style="color: #000000;">(</span> ucChar & 0xc0 <span style="color: #000000;">)</span> != 0x80 <span style="color: #000000;">)</span><br /> <span style="color: #00C800;">return</span> <span style="color: #00C800;">FALSE</span>;<br /> *uc = <span style="color: #000000;">(</span> *uc << <span style="color: #000000;">6</span> <span style="color: #000000;">)</span> | <span style="color: #000000;">(</span> ucChar & 0x3f <span style="color: #000000;">)</span>;<br /> <span style="color: #000000;">(</span> *n <span style="color: #000000;">)</span>--;<br /> <span style="color: #00C800;">return</span> <span style="color: #00C800;">TRUE</span>;<br /> <span style="color: #000000;">}</span><br /><br /> *n = <span style="color: #000000;">0</span>;<br /> *uc = ucChar;<br /> <span style="color: #00C800;">if</span><span style="color: #000000;">(</span> ucChar >= 0xc0 <span style="color: #000000;">)</span><br /> <span style="color: #000000;">{</span><br /> <span style="color: #00C800;">if</span><span style="color: #000000;">(</span> ucChar < 0xe0 <span style="color: #000000;">)</span><br /> <span style="color: #000000;">{</span><br /> *uc &= 0x1f;<br /> *n = <span style="color: #000000;">1</span>;<br /> <span style="color: #000000;">}</span><br /> <span style="color: #00C800;">else</span> <span style="color: #00C800;">if</span><span style="color: #000000;">(</span> ucChar < 0xf0 <span style="color: #000000;">)</span><br /> <span style="color: #000000;">{</span><br /> *uc &= 0x0f;<br /> *n = <span style="color: #000000;">2</span>;<br /> <span style="color: #000000;">}</span><br /> <span style="color: #00C800;">else</span> <span style="color: #00C800;">if</span><span style="color: #000000;">(</span> ucChar < 0xf8 <span style="color: #000000;">)</span><br /> <span style="color: #000000;">{</span><br /> *uc &= 0x07;<br /> *n = <span style="color: #000000;">3</span>;<br /> <span style="color: #000000;">}</span><br /> <span style="color: #00C800;">else</span> <span style="color: #00C800;">if</span><span style="color: #000000;">(</span> ucChar < 0xfc <span style="color: #000000;">)</span><br /> <span style="color: #000000;">{</span><br /> *uc &= 0x03;<br /> *n = <span style="color: #000000;">4</span>;<br /> <span style="color: #000000;">}</span><br /> <span style="color: #00C800;">else</span> <span style="color: #00C800;">if</span><span style="color: #000000;">(</span> ucChar < 0xfe <span style="color: #000000;">)</span><br /> <span style="color: #000000;">{</span><br /> *uc &= 0x01;<br /> *n = <span style="color: #000000;">5</span>;<br /> <span style="color: #000000;">}</span><br /> <span style="color: #000000;">}</span><br /> <span style="color: #00C800;">return</span> <span style="color: #00C800;">TRUE</span>;<br /><span style="color: #000000;">}</span><br /><br /><br /><span style="color: #00C800;">HB_FUNC</span><span style="color: #000000;">(</span> HB_UTF8ASC <span style="color: #000000;">)</span><br /><br /><span style="color: #000000;">{</span><br /><br /> const char * pszString = hb_parc<span style="color: #000000;">(</span> <span style="color: #000000;">1</span> <span style="color: #000000;">)</span>;<br /><br /><br /><br /> <span style="color: #00C800;">if</span><span style="color: #000000;">(</span> pszString <span style="color: #000000;">)</span><br /><br /> <span style="color: #000000;">{</span><br /><br /> HB_SIZE nLen = hb_parclen<span style="color: #000000;">(</span> <span style="color: #000000;">1</span> <span style="color: #000000;">)</span>;<br /><br /> USHORT wc = <span style="color: #000000;">0</span>;<br /><br /> int n = <span style="color: #000000;">0</span>;<br /><br /><br /><br /> <span style="color: #00C800;">while</span><span style="color: #000000;">(</span> nLen <span style="color: #000000;">)</span><br /><br /> <span style="color: #000000;">{</span><br /><br /> <span style="color: #00C800;">if</span><span style="color: #000000;">(</span> ! utf8tou16nextchar<span style="color: #000000;">(</span> <span style="color: #000000;">(</span> unsigned char <span style="color: #000000;">)</span> *pszString, &n, &wc <span style="color: #000000;">)</span> <span style="color: #000000;">)</span><br /><br /> <span style="color: #00C800;">break</span>;<br /><br /> <span style="color: #00C800;">if</span><span style="color: #000000;">(</span> n == <span style="color: #000000;">0</span> <span style="color: #000000;">)</span><br /><br /> <span style="color: #00C800;">break</span>;<br /><br /> pszString++;<br /><br /> nLen--;<br /><br /> <span style="color: #000000;">}</span><br /><br /> hb_retnint<span style="color: #000000;">(</span> wc <span style="color: #000000;">)</span>;<br /><br /> <span style="color: #000000;">}</span><br /><br /> <span style="color: #00C800;">else</span><br /><br /> hb_errRT_BASE_SubstR<span style="color: #000000;">(</span> EG_ARG, <span style="color: #000000;">3012</span>, <span style="color: #00C800;">NULL</span>, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS <span style="color: #000000;">)</span>;<br /><br /><span style="color: #000000;">}</span><br /><br /><span style="color: #00D7D7;">#pragma</span> ENDDUMP</div>[/code:32iwsqm5]
EMG
|
AscW() function
|
Latin's fine. However, this function returns incorrect Unicode Cyrillic characters
|
AscW() function
|
Can you send me a sample showing the problem, please?
EMG
|
AscW() function
|
Working correctly for me with this test:
[code=fw:2u3b65fi]<div class="fw" id="{CB}" style="font-family: monospace;"><br /> <span style="color: #00C800;">local</span> n, c<br /><br /> n := 0xE100<br /> c := HB_UTF8CHR<span style="color: #000000;">(</span> n <span style="color: #000000;">)</span><br /><br /> ? HB_UTF8ASC<span style="color: #000000;">(</span> HB_UTF8CHR<span style="color: #000000;">(</span> n <span style="color: #000000;">)</span> <span style="color: #000000;">)</span> == n <span style="color: #B900B9;">// --> .T.</span><br /> ? HB_UTF8CHR<span style="color: #000000;">(</span> HB_UTF8ASC<span style="color: #000000;">(</span> c <span style="color: #000000;">)</span> <span style="color: #000000;">)</span> == c <span style="color: #B900B9;">// --> .T.</span><br /> </div>[/code:2u3b65fi]
|
AscW() function
|
I didn't understand. There is a character with a code of 128 (1 byte) If you convert this character to Unicode it will consist of 2 bytes and its code will be 1040. How can I do this through the HB_UTF8ASC function() ?
|
AscW() function
|
Sorry, I'm not familiar with Unicode. Just give me a sample showing the problem and I'll see what I can do.
EMG
|
AscW() function
|
From the beginning, we are going in the wrong direction. I am sorry for this deviation.
This is not conversion to and from UTF8 but of WideChar. (16bit char encoding).
Windows internally works with WideChar, i.e., 64 bit (little endian) characters.
In 8bit notation
"AB" is "4142" in hex
In 16bit notation
"AB" is "41004200" in hex
|
AscW() function
|
So, what's the point?
EMG
|
AscW() function
|
BIN2W( cWideString ) should give the value equivalent to AscW()
|
AscW() function
|
This small program demonstrates that BIN2W() works like AscW()
[code=fw:jekzyezc]<div class="fw" id="{CB}" style="font-family: monospace;"><span style="color: #00D7D7;">#include</span> <span style="color: #ff0000;">"fivewin.ch"</span><br /><br /><span style="color: #00C800;">function</span> Main<span style="color: #000000;">(</span><span style="color: #000000;">)</span><br /><br /> <span style="color: #00C800;">local</span> cUtf8, cWide, nAsc<br /><br /> cUtf8 := <span style="color: #ff0000;">"?"</span><br /> ? cUtf8<br /> cWide := UTF8TOUTF16<span style="color: #000000;">(</span> cUtf8 <span style="color: #000000;">)</span><br /> nAsc := BIN2W<span style="color: #000000;">(</span> cWide <span style="color: #000000;">)</span><br /> ? nAsc<br /> ? <span style="color: #ff0000;">"Proof"</span>, HB_UTF8CHR<span style="color: #000000;">(</span> nAsc <span style="color: #000000;">)</span><br /><br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">nil</span><br /> </div>[/code:jekzyezc]
|
AscW() function
|
So, what about HB_UTF8ASC()? Do we need it?
EMG
|
AscW() function
|
[quote="Enrico Maria Giordano":32ivdfk6]So, what about HB_UTF8ASC()? Do we need it?
EMG[/quote:32ivdfk6]
We need it.
This may not be what Mr. Natter is looking for but we need it in xHarbour.
Harbour has both HB_UTF8CHR() and HB_UTF8ASC().
But xHarbour has only HB_UTF8CHR() but not HB_UTF8ASC().
Addition of this function to xHarbour will be useful.
|
AscW() function
|
Done. Please try xHarbour build 10253.
EMG
|
AscW() function
|
Thank you.
FWH is now using HB_UTF8CHR(). There is no problem either with Harbour or xHarbour.
Till now there is no need to use HB_UTF8ASC().
But, if and when the need arises, what shall we do? There will be many users of older versions of xHarbour. Looks like we need to force them to upgrade xHarbour.
But what about xharbour.com users? They will get unresolved externals issue.
|
AscW() function
|
They can use this code:
[code=fw:3rsshez9]<div class="fw" id="{CB}" style="font-family: monospace;"><span style="color: #00D7D7;">#pragma</span> BEGINDUMP<br /><br /><br /><span style="color: #00D7D7;">#include</span> <span style="color: #ff0000;">"error.ch"</span><br /><span style="color: #00D7D7;">#include</span> <span style="color: #ff0000;">"hbapierr.h"</span><br /><br /><br /><span style="color: #00C800;">static</span> BOOL utf8tou16nextchar<span style="color: #000000;">(</span> UCHAR ucChar, int * n, USHORT * uc <span style="color: #000000;">)</span><br /><span style="color: #000000;">{</span><br /> <span style="color: #00C800;">if</span><span style="color: #000000;">(</span> *n > <span style="color: #000000;">0</span> <span style="color: #000000;">)</span><br /> <span style="color: #000000;">{</span><br /> <span style="color: #00C800;">if</span><span style="color: #000000;">(</span> <span style="color: #000000;">(</span> ucChar & 0xc0 <span style="color: #000000;">)</span> != 0x80 <span style="color: #000000;">)</span><br /> <span style="color: #00C800;">return</span> <span style="color: #00C800;">FALSE</span>;<br /> *uc = <span style="color: #000000;">(</span> *uc << <span style="color: #000000;">6</span> <span style="color: #000000;">)</span> | <span style="color: #000000;">(</span> ucChar & 0x3f <span style="color: #000000;">)</span>;<br /> <span style="color: #000000;">(</span> *n <span style="color: #000000;">)</span>--;<br /> <span style="color: #00C800;">return</span> <span style="color: #00C800;">TRUE</span>;<br /> <span style="color: #000000;">}</span><br /><br /> *n = <span style="color: #000000;">0</span>;<br /> *uc = ucChar;<br /> <span style="color: #00C800;">if</span><span style="color: #000000;">(</span> ucChar >= 0xc0 <span style="color: #000000;">)</span><br /> <span style="color: #000000;">{</span><br /> <span style="color: #00C800;">if</span><span style="color: #000000;">(</span> ucChar < 0xe0 <span style="color: #000000;">)</span><br /> <span style="color: #000000;">{</span><br /> *uc &= 0x1f;<br /> *n = <span style="color: #000000;">1</span>;<br /> <span style="color: #000000;">}</span><br /> <span style="color: #00C800;">else</span> <span style="color: #00C800;">if</span><span style="color: #000000;">(</span> ucChar < 0xf0 <span style="color: #000000;">)</span><br /> <span style="color: #000000;">{</span><br /> *uc &= 0x0f;<br /> *n = <span style="color: #000000;">2</span>;<br /> <span style="color: #000000;">}</span><br /> <span style="color: #00C800;">else</span> <span style="color: #00C800;">if</span><span style="color: #000000;">(</span> ucChar < 0xf8 <span style="color: #000000;">)</span><br /> <span style="color: #000000;">{</span><br /> *uc &= 0x07;<br /> *n = <span style="color: #000000;">3</span>;<br /> <span style="color: #000000;">}</span><br /> <span style="color: #00C800;">else</span> <span style="color: #00C800;">if</span><span style="color: #000000;">(</span> ucChar < 0xfc <span style="color: #000000;">)</span><br /> <span style="color: #000000;">{</span><br /> *uc &= 0x03;<br /> *n = <span style="color: #000000;">4</span>;<br /> <span style="color: #000000;">}</span><br /> <span style="color: #00C800;">else</span> <span style="color: #00C800;">if</span><span style="color: #000000;">(</span> ucChar < 0xfe <span style="color: #000000;">)</span><br /> <span style="color: #000000;">{</span><br /> *uc &= 0x01;<br /> *n = <span style="color: #000000;">5</span>;<br /> <span style="color: #000000;">}</span><br /> <span style="color: #000000;">}</span><br /> <span style="color: #00C800;">return</span> <span style="color: #00C800;">TRUE</span>;<br /><span style="color: #000000;">}</span><br /><br /><br /><span style="color: #00C800;">HB_FUNC</span><span style="color: #000000;">(</span> HB_UTF8ASC <span style="color: #000000;">)</span><br /><span style="color: #000000;">{</span><br /> const char * pszString = hb_parc<span style="color: #000000;">(</span> <span style="color: #000000;">1</span> <span style="color: #000000;">)</span>;<br /><br /> <span style="color: #00C800;">if</span><span style="color: #000000;">(</span> pszString <span style="color: #000000;">)</span><br /> <span style="color: #000000;">{</span><br /> HB_SIZE nLen = hb_parclen<span style="color: #000000;">(</span> <span style="color: #000000;">1</span> <span style="color: #000000;">)</span>;<br /> USHORT wc = <span style="color: #000000;">0</span>;<br /> int n = <span style="color: #000000;">0</span>;<br /><br /> <span style="color: #00C800;">while</span><span style="color: #000000;">(</span> nLen <span style="color: #000000;">)</span><br /> <span style="color: #000000;">{</span><br /> <span style="color: #00C800;">if</span><span style="color: #000000;">(</span> ! utf8tou16nextchar<span style="color: #000000;">(</span> <span style="color: #000000;">(</span> unsigned char <span style="color: #000000;">)</span> *pszString, &n, &wc <span style="color: #000000;">)</span> <span style="color: #000000;">)</span><br /> <span style="color: #00C800;">break</span>;<br /><br /> <span style="color: #00C800;">if</span><span style="color: #000000;">(</span> n == <span style="color: #000000;">0</span> <span style="color: #000000;">)</span><br /> <span style="color: #00C800;">break</span>;<br /><br /> pszString++;<br /><br /> nLen--;<br /> <span style="color: #000000;">}</span><br /><br /> hb_retnint<span style="color: #000000;">(</span> wc <span style="color: #000000;">)</span>;<br /> <span style="color: #000000;">}</span><br /> <span style="color: #00C800;">else</span><br /> hb_errRT_BASE_SubstR<span style="color: #000000;">(</span> EG_ARG, <span style="color: #000000;">3012</span>, <span style="color: #00C800;">NULL</span>, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS <span style="color: #000000;">)</span>;<br /><span style="color: #000000;">}</span><br /><br /><span style="color: #00D7D7;">#pragma</span> ENDDUMP</div>[/code:3rsshez9]
EMG
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.