Implementing missing VFP functions

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

User avatar
Chris
Posts: 4870
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Implementing missing VFP functions

Post by Chris »

Robert,
robert wrote:Chris,
Chris wrote:
No you're right, there's an issue here. The Binary type itself is a STRUCTURE (so it's being passed by value), but it holds its data internally in a byte array (so a reference type) and when you convert the Binary value into a BYTE array in your first local assignment, then the conversion returns that exact internal array. Maybe the best way is to return a new copy of the array instead, will log an incident on that to be looked at.
Given the fact that the binary type is a value type it indeed makes sense to return a copy of the byte array as well (in other words, to make it a really immutable type).
Agreed, I made the change. Not sure if also the constructor that accepts a byte array needs to use a cloned buffer as well. If this constructor is supposed to be called only from the compiler emitted code for literals and from within the class code, then there's no point I think.

Btw, I think you accidentally increased the assembly version (not only the file version) of the runtime to 2.8.0.0 instead of 2.6.0.0.
Chris Pyrgas

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

Implementing missing VFP functions

Post by Karl-Heinz »

Guys

there are a few options to create a Binary

Code: Select all

    VAR bArr := BYTE[]{5}
    
    bArr[1] := 104  // "h"
    bArr[2] := 111  // "o"
    bArr[3] := 117  // "u"
    bArr[4] := 115  // "s"
    bArr[5] := 101  // "e"

    
    ? 0h686F757365
    ? (BINARY) bArr 
    ? (BINARY) "house"  
    ? BINARY { bArr }  
//  ? BINARY { "house" } // that´s not possible 

Now the question: If such a string constructor would be part of the Binary implementation, something like Binary { "House" } works, right ?

Code: Select all

CONSTRUCTOR (c as STRING )
	IF String.IsNullOrEmpty ( c )
		THROW NullError()
	ENDIF
	self:_value := RuntimeState.WinEncoding:GetBytes(c)

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

Implementing missing VFP functions

Post by robert »

Karl Heinz,
Adding such a constructor is no problem at all. In fact I'll map the implicit converter to call the same constructor to keep the logic in one place.
Important to realize is that the mapping between characters and bytes only works for lower ascii characters. Accented characters and characters from other character sets will not map like that. They will be replace with a question mark when translated.

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

Implementing missing VFP functions

Post by Karl-Heinz »

Hi Robert,

yes, i´m aware of the problems. If e.g. Chris creates a byte array with some special greece chars included i won´t be able to see on my machine the correct string presentation if i simply use RuntimeState.WinEncoding:GetString( bArr).

i asked about the string constructor because it´s possible to do this:

Code: Select all

VAR binExpression := (BINARY) "äöüß" 

Code: Select all


? (STRING) binExpression  // äöüß 

? RuntimeState.WinEncoding:GetString( binExpression:Value  ) // äöüß
regards
Karl-Heinz
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

Implementing missing VFP functions

Post by Karl-Heinz »

Hi Robert,

forgot to mention, but maybe it´s already known ?.

What´s missing is the IsBinary() function.

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

Implementing missing VFP functions

Post by robert »

Karl-Heinz ,

I have added that function as well.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
atlopes
Posts: 83
Joined: Sat Sep 07, 2019 11:43 am
Location: Portugal

Implementing missing VFP functions

Post by atlopes »

Going back to Chris's question, here is a list of common VFP functions that I think would signify an advancement if implemented from scratch or recreated to match VFP's behavior closer:
  • EMPTY() and EVL() (I'm not forgetting this, Matt)
  • ISNULL()
  • ALINES()
  • TRANSFORM() (verify formats) and TTOC()
  • TEXTMERGE()
  • STREXTRACT()
  • XMLTOCURSOR() and CURSORTOXML()
  • AERROR(), at least to support SQL* functions
  • GETFILE(), PUTFILE() and LOCFILE()
Because of how this thread evolved, I worked on the BIT* functions. I will propose them in a separate thread.
Post Reply