Passing Fox arrays by ref or value

This forum is meant for questions about the Visual FoxPro Language support in X#.

Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

Passing Fox arrays by ref or value

Post by Karl-Heinz »

Robert,

how should a X# APrinters() signature look like ? From the VFP help:

Code: Select all

APRINTERS(ArrayName [, nValue])
Which X# signature do you prefer ?

Code: Select all

FUNCTION APrinters ( ArrayName , nValue ) AS DWORD CLIPPER 

or

Code: Select all

FUNCTION APrinters ( ArrayName AS __FoxArray , nValue := 0 AS DWORD ) AS DWORD


Should INTs be used instead of DWORDs ?

regards
Karl-Heinz
User avatar
robert
Posts: 4478
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Passing Fox arrays by ref or value

Post by robert »

Karl-Heinz ,
The signature is really not that important I think. This will most likely be used by people that have many, many untyped variables, so whatever you do, there will always be a runtime check needed.

If you declare the parameter as __FoxArray and a USUAL variable is used then there will be an automatic runtime error when the usual is of the incorrect type. When you do not declare it then you can have more control over the error message.

W.r.t. INT or DWORD: I personally prefer INT over DWORD, because signed ints are less likely to cause numeric overflows when you accidentally subtract 1 from a value of 0. This may happen in downto loops.
For unsigned ints you always have to be careful and have to consider if code is being compiled with overflow checking enabled or disabled.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

Passing Fox arrays by ref or value

Post by Karl-Heinz »

Hi Robert,

attached is a modified XSharpFoxProAPrinters.viaef with a revised APrinters() function. This is how the params are checked

Code: Select all

FUNCTION APrinters ( ArrayName , nValue) AS INT CLIPPER
LOCAL cPrinterName AS STRING 	
LOCAL iCount AS INT 
LOCAL oSearcher AS ManagementObjectSearcher

	Default ( @nValue , 0 ) 

	IF ( iCount := PrinterSettings:InstalledPrinters.Count ) > 0 
         
		IF ! IsArray( ArrayName ) .or. ( IsArray ( ArrayName ) .and. ! ArrayName IS __FoxArray ) 
			THROW ArgumentException {"parameter must be a Fox Array", nameof ( ArrayName ) }
		ELSEIF ! IsNumeric ( nValue ) 
			THROW ArgumentException {"wrong parameter type, must be numeric", nameof ( nValue ) } 
		ELSEIF nValue < 0 .or. nValue > 1 
			THROW ArgumentException {"parameter value must be either 0 or 1", nameof ( nValue ) } 
		ENDIF	

i also added a GetPrinter() function. The VFP GetPrinter() dialog doesn´t show e.g. "print rage" and "copies" groupboxes ás the .net PrinerDialog does. But OOB the .net Printerdialog can´t be customized to get a more VFP compatible appearance. i think: "better that than nothing" ;-)

regards
Karl-Heinz
Attachments

[The extension viaef has been deactivated and can no longer be displayed.]

User avatar
robert
Posts: 4478
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Passing Fox arrays by ref or value

Post by robert »

Karl Heinz,
Thanks. I will have a look at this after the weekend.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

Passing Fox arrays by ref or value

Post by Karl-Heinz »

Robert and Chris,

IMO, trying to use the .net PrinterDialog to mimic the dialog that VFP opens when the GetPrinter() is called doesn´t make sence. Attached is a core winform viaef that might be a replacement. Of course the text you see is not yet regionalzied, but as a quick view i attached two images. Fox.png shows the VFP dialog, and mine.png my dialog :-). For the moment the "Status" description shows numbers only. It would be interesting to know which other values than 3 do you see when you run the app.

btw. Chris, it´s a real pleasure to build winforms with XIDE !

regards
Karl-Heinz
Attachments

[The extension viaef has been deactivated and can no longer be displayed.]

Fox.png
Fox.png (23.76 KiB) Viewed 1399 times
mine.png
mine.png (19.64 KiB) Viewed 1399 times
User avatar
Chris
Posts: 4854
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Passing Fox arrays by ref or value

Post by Chris »

Glad you like it Karl-Heinz! Thanks for the code as well, I'm just not qualified to comment on what should be used, I'll just let Fox designers and/or Robert to decide on this.

.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

Passing Fox arrays by ref or value

Post by Karl-Heinz »

Guys,

1. Instead of a number you´ll see now one of the following values. However, I don't know if these descriptions match the descriptions that an english windows displays by default.

_oList:Add( "Stopped:" )
_oList:Add( "Unknown" )
_oList:Add( "Ready" )
_oList:Add( "Printing" )
_oList:Add( "Warmup" )
_oList:Add( "StoppedPrinting" )
_oList:Add( "Offline" )

2. If a printer was stopped, you´ll see now the number of waiting documents.

e.g.
"Stopped: 0 Documents waiting"
"Stopped: 2 Documents waiting"

3. The content of "Where" and "Location" is now handled properly.

regards
Karl-Heinz
Attachments

[The extension viaef has been deactivated and can no longer be displayed.]

Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

Passing Fox arrays by ref or value

Post by Karl-Heinz »

robert wrote:Karl Heinz,
Thanks. I will have a look at this after the weekend.

Robert
i noticed that the APrinters() function uses a wrong property. In the APrinters() sources the property name "Description" must be changed to "Comment".

regards
Karl-Heinz
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

Passing Fox arrays by ref or value

Post by Karl-Heinz »

a queston to the VFP community.

Is it already known that there´s a VFP GetPrinter() "easter egg" ?

1. start VFP
2. Enter in the command window "? GetPrinter()"
3. As expected, the focus is set to the combobox. Now press the <Tab> and then the <Space> or <Enter> key. Magic, isn't it ;-). There seems to be a hidden, but not disabled [Properties] button. I tried to open the additional dialog by mouse clicks inside the dialog area, but I did not succeed.
.
regards
Karl-Heinz
User avatar
kevclark64
Posts: 127
Joined: Thu Aug 15, 2019 7:30 pm
Location: USA

Passing Fox arrays by ref or value

Post by kevclark64 »

I didn't know about the phantom button. I assume you can't click it because it's located off-screen.

The GetPrinter dialog should have a properties button, though, so if you're recreating it I'd say definitely include it.
Post Reply