fbpx
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

Assign property by reference 02 Sep 2019 16:49 #10502

  • wriedmann's Avatar

  • wriedmann

  • Topic Author


  • Posts: 2300
  • Hi,

    I have a LOT of such statements in one of my X# applications:
    if oRow:HasRow( "produkt" )
      self:Produkt := oRow:GetString( "produkt" )
    endif

    Hoping to simplify that code I have tried to pass the property by reference, but in C# this is not allowed ( and therefore it is also not allowed in X#). Strangely VB.NET allows this....

    The only possibility seems to be to use Reflection.

    Maybe someone of you has a better idea how to solve this with an one-liner, without using Reflection.

    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    Last edit: by wriedmann.

    Assign property by reference 02 Sep 2019 17:05 #10503

  • robert's Avatar

  • robert


  • Posts: 1790
  • Wolfgang,
    Have you tried the preprocessor:
    Something like
    #command GETSTRING <oObject> <cColname> => IF <oObject>:HasRow(<(cColName)> ) ;;
                       SELF:<cColName> := <oObject>:GetRow(<(cColName)> ) ; ENDIF

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    Assign property by reference 02 Sep 2019 17:15 #10504

  • wriedmann's Avatar

  • wriedmann

  • Topic Author


  • Posts: 2300
  • Hi Robert,

    thank you yery much!

    This command works:
    #command SETSTRING <oProperty> <oRow> <cColname> => IF <oRow>:HasRow(<(cColName)> ) ;;
                       <oProperty> := <oRow>:GetString(<(cColName)> ) ; endif
    and the relative code:
    SetString self:Produkt oRow "produkt"

    Thank you very much!

    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    Assign property by reference 02 Sep 2019 17:32 #10505

  • wriedmann's Avatar

  • wriedmann

  • Topic Author


  • Posts: 2300
  • Hi Robert,

    this the entire method now:

    The statement has not only the advantage to keep the code shorter and much more readable, but also to make it more robust in case of future changes - it is much less error prone.
    Thank you again!
    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it
    Attachments:

    Please Log in or Create an account to join the conversation.

    Assign property by reference 02 Sep 2019 17:39 #10506

  • robert's Avatar

  • robert


  • Posts: 1790
  • Wolfgang,

    Nice.
    And if you had used Visual Studio, then the UDC keywords SetInt, SetString etc would have been shown in the keyword color.

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    Assign property by reference 02 Sep 2019 17:44 #10507

  • Chris's Avatar

  • Chris


  • Posts: 2033
  • robert wrote: Nice.
    And if you had used Visual Studio, then the UDC keywords SetInt, SetString etc would have been shown in the keyword color.


    Wolfgang knows how to do this in XIDE as well :)
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    Assign property by reference 03 Sep 2019 09:10 #10515

  • wriedmann's Avatar

  • wriedmann

  • Topic Author


  • Posts: 2300
  • Hi Robert,

    Visual Studio has several advantages over XIDE - I'm aware of that.
    But for me the speed and some of the advantages of XIDE over Visual Studio are much more important, so I prefer to continue with XIDE.
    And personally I see it as a big advantage that X# has also its own IDE, specially for people coming from VO.
    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    Assign property by reference 03 Sep 2019 10:50 #10518

  • robert's Avatar

  • robert


  • Posts: 1790
  • Wolfgang,

    I know. I was just teasing...

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1