Hyperlink file:// error

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

trmpluym
Posts: 303
Joined: Tue Jul 15, 2014 6:52 pm
Location: The Netherlands

Hyperlink file:// error

Post by trmpluym »

I like to open a PDF on a local path. In Windows this is possible using a hyperlink with the file:// syntax.

For example:

file://c:\folder\20170444.pdf

This works everywhere Windows. For example in 'Eplorer' or 'Internet Explorer'

But when i try to use it in HMG i got an error:

wndArtikelen.hplBrochure.Address := 'file://c:\folder\20170444.pdf'

See:
2017-03-19 18_40_54-Program Error.png
2017-03-19 18_40_54-Program Error.png (17.68 KiB) Viewed 5734 times
This error is not correct, the URL is valid but it is not a http:// or https:// but a file:// URL.

Is it possible to make these kind of file URL's possible ?

Theo
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Hyperlink file:// error

Post by serge_girard »

Theo,

Please try with : 'file://c:\folder/20170444.pdf' (slashes in stead of backslashes!).
This works for me!

Serge
There's nothing you can do that can't be done...
trmpluym
Posts: 303
Joined: Tue Jul 15, 2014 6:52 pm
Location: The Netherlands

Re: Hyperlink file:// error

Post by trmpluym »

Thank you Serge, i tried both:

file://c:\folder/20170444.pdf

And

file://c:/folder/20170444.pdf

Same error :(
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Hyperlink file:// error

Post by serge_girard »

Theo,

And this: file:///C:/.... (3 slashes)

Serge
There's nothing you can do that can't be done...
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Hyperlink file:// error

Post by Pablo César »

I think that I am understanding what is happening with you Theo.

IMHO there is a logical mess in URI for accepting address in HMG control...

I have reported one of relative problems at: viewtopic.php?p=47915#p47915

And also I made some tricky equivalent to overcome certain shortcomings:

viewtopic.php?p=47955#p47955

Please ready carefully and see if helps you...
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
trmpluym
Posts: 303
Joined: Tue Jul 15, 2014 6:52 pm
Location: The Netherlands

Re: Hyperlink file:// error

Post by trmpluym »

Pablo César wrote: Mon Mar 20, 2017 12:53 pm And also I made some tricky equivalent to overcome certain shortcomings:
Your solution works like a charm Pablo :D (as always!)
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Hyperlink file:// error

Post by Pablo César »

I am happy to know it serves for you Theo. :)
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
trmpluym
Posts: 303
Joined: Tue Jul 15, 2014 6:52 pm
Location: The Netherlands

Re: Hyperlink file:// error

Post by trmpluym »

Pablo,

I was a little to early. When the property is set in the source it works well, like:

Code: Select all

@ 220,360 LABEL H14 VALUE "Word file"                             ACTION 'TEST.docx'   
But when i try to set the property programmaticly the same error occurs like:

Code: Select all

ACTION (SetProperty("Main_form","H07","ADDRESS",'TEST.docx'))
The error is: Control: H07 must have valid email or url defined. Program Terminated

I modified your demo with a SET ADDRESS button

Can you have a look ?

Thanks in advance,

Theo
Attachments
hyperlink.zip
(1.52 MiB) Downloaded 265 times
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Hyperlink file:// error

Post by Pablo César »

The main problem is that.

SetProperty in HMG for HYPERLINKs that wrongly forces to FileProtocolHandler mailto:, as said wrongly IMO because it should differentiate when is email address or a file or folder as URL.

You will see at i_UsrInit.ch in the pack that it makes the differance by when it contains "@".

IMHO, this is a little missunderstanding from HMG. I suppose that Roberto deals to make easier for emails but now have to connsidered there are other way to inform URL: HTTP, HTTPS, FTP, local files, email address.

Alias, when have to make mention not as URL we have to say as URIs instead, I guess.
( https://en.wikipedia.org/wiki/Uniform_R ... C_and_URNs )

For that reason I am using MySetAddressControlProcedure in user component.

Another bug I found is getting the procedure for address in HYPERLINKs and is wrongly comes as Nil... This I have adviced to Claudio here but he has not confirmed yet... :|

So, to solve your new assigning ADDRESS as file I guess you will need to replace:
Screen137.png
Screen137.png (14.78 KiB) Viewed 5627 times
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
trmpluym
Posts: 303
Joined: Tue Jul 15, 2014 6:52 pm
Location: The Netherlands

Re: Hyperlink file:// error

Post by trmpluym »

Hi Pablo,

I finaly found the time to dig into your code. I modified it to include the used form so i can use it as a universal replacement of the current HYPERLINK control.

Here the modified parts:

Code: Select all

*---------------------------------------------------------------------------------------------------------------------------------------------------------------*
Function MySetAddressControlProcedure(cForm, cCtrl, cURL) 

LOCAL bCode, nIndex:=GetControlIndex(cCtrl, cForm )

If ("@" $ cURL )
   bCode := {||ShellExecute(0, "open", "rundll32.exe", "url.dll,FileProtocolHandler mailto:" + cURL, ,1),ChangeColor(cForm,cCtrl,.F.)}
Else
   bCode := {||ShellExecute(0, "open", "rundll32.exe", "url.dll,FileProtocolHandler " + cURL, ,1),ChangeColor(cForm,cCtrl,.F.)}
Endif

_HMG_SYSDATA [ 6 ][nIndex] := bCode
_HMG_SYSDATA [ 8 ][nIndex] := cURL

Return Nil
*---------------------------------------------------------------------------------------------------------------------------------------------------------------*
STATIC Function ChangeColor(cForm,cCtrlName,lOn)

LOCAL nColor:=1
LOCAL aColorNow:={ {{000,000,255} , {102,000,153}} ,; // Conventional
                     {{000,000,102} , {153,153,204}} ,; // Blue
                     {{000,102,102} , {153,255,255}} ,; // Cyan
                     {{080,080,080} , {153,153,153}} ,; // Gray
                     {{000,153,000} , {000,051,000}} ,; // Green
                     {{204,000,204} , {102,051,102}} ,; // Margenta
                     {{204,000,000} , {153,051,051}} ,; // Red
                     {{255,255,000} , {153,153,000}} }  // Yellow

SetProperty(cForm, cCtrlName, "FONTCOLOR", aColorNow[nColor,If(lOn,1,2)])

Return Nil
*---------------------------------------------------------------------------------------------------------------------------------------------------------------*
Offcause many thanks again for helping me out !

I learned a lot from your example, for example the use of the i_UsrInit.ch file:

http://harbourminigui.com/hmgguide/user-components.htm

But i have an additional question.

For now i have to use the syntax below:

Code: Select all

@ 365,105 MyHYPERLINK hplBrochure VALUE "open" WIDTH 30 ADDRESS ""   
How can i also make the syntax below possible ?

Code: Select all

DEFINE MyHYPERLINK hplBrochure
ROW    365
COL    105
VALUE "open"
WIDTH  30
ADDRESS ""
END MyHYPERLINK
Theo
Post Reply