What is the use of Structure ByteValue() method?

Can anyone please help me understand the function of ByteValue() method in Structure Datatype

I don’t know, nor am I ever likely to want to know. An awful lot of that stuff exists to enable you to interact with third party libraries written in C or a similar language. Something probably 90% of us won’t do.

When learning XOJO you can safely ignore all of that stuff.

1 Like

More or less exactly as James said.
The main use of structures is to interact with a 3rd party (or the OS) API where a method might use a structure to deliver some data.

Consider a structure a MemoryBlock of a defined size where the position inside the block defines how to interpret the data. Like 10 characters followed by a Double followed by an Integer – you get the idea. A structure helps to get the respective data out of the memoryblock.

That littleEndian flag you see in the structure methods goes back to the time when Apple used PowerPC CPUs and not Intel-typed as currently. One CPU type used BigEndian encoding, the other littleEndian. Which means the order of bytes was reversed. And in order to interpret double correctly, you have to know in which order to read the 8 bytes that define it. (On Intel CPUs that’s all littleEndian).

So, as James said: Unless you are going to interact with APIs by Declares, you can simply ignore all that structure stuff.

P.S.: And the use of the ByteValue method is to convert the contents of the structure into a byte array, or feed it from one. Which to me sounds like a very special case, but possibly had some practical use in the time it was created. I never used it.

1 Like

Well, one assumes that having created a structure, it will be necessary to initialise it before passing it into the OS or whereever. And vice versa.

1 Like

Yes i just keep learning whatever comes in my way :man_facepalming: , btw i really want to know how to use third party libraries and how to make them. Can you help? :smile:

Im still a novice so i couldn’t understand how to interact with OS API. Can you please tell me? :slight_smile:

You don’t need to initialize a structure. Unlike a class instance, you don’t need to use New with a structure. When you say

Dim s as MyStructure

It allocates the memory for the structure. You never have to say New MyStructure (nor can you).

There are 2 ways of setting the values in a structure in Xojo code. You can pass it a String or an Array of Byte() values. The ByteValue method allows you do do

dim bytearray() as Byte
bytearray = MyStructure.ByteValue

or

dim bytearray() as Byte = array(&h20, &h21, &h22)
MyStructure.ByteValue = bytearray

I can’t think of many reasons why you would do this, but it does allow you to treat the structure as individual bytes instead of the usual structured data.

1 Like

I do not know your general IT background.
If you are a novice in programming in general, I would encourage you to gather more practical experience with Xojo first.

Like James pointed out, the majority of Xojo users does not know (or shys away from) using declares. Which I personally see as a pity, because you can learn enormous amounts from reading and using the OS APIs. But it is one of the most sophisticated features in Xojo and can become overwhelming when you are new to programming.

I can anyway point you to some information and possibly even send you slides from a session about declares I once held, but if you should feel that it’s getting over your head, put it away for a while and gather more experience.
You should definitely return to it sooner or later. It is absolutely worth learning, and you can not even expand Xojo’s abilities but your insight into modern OS principles and programming languages in general.

1 Like

Understood . thank you for making it simple :slight_smile:

Yes please i would like to read those slides. Can you please email them to me:

Im really very curious.

And yes im really a novice in programming , but do have knowledge of some Java
But never worked with OS level APIs

ranacoder96@gmail.com

Do you use a Mac? I created them in Keynote and could send the whole presentation file with extended Speaker text.
(Having a Mac or Linux machine is recommended for this topic anyway. Windows declares are mostly awful!)

1 Like

sorry to burst the bubble but i have windows. But i can install linux if you want , if that will help me learn them better

No, no, don’t change your system. Just the session was built around Mac declares which are much easier to grasp and handle IMHO. If you feel that you really want to get into that topic, @Eugene_Dakin wrote an eBook about Windows declares which will help you get the practical experience which my lesson cannot, because, Mac.

1 Like

Okay , how can i get the book and what is the books name. Thank you for helping me

That’s “I wish I knew how to implement declares with Xojo on Windows” (2 versions available. API 2 is for current Xojo) in xdev library.

1 Like

Thank you very much. :slight_smile:

There is a lot you can do with Xojo without needing declares. That’s an advanced concept which you should eventually explore, but don’t let that distract you from learning Xojo. I would classify Structures as a “you don’t need this but it’s available if all else fails” thing. It’s more important to understand classes and events.

1 Like

Not, really I have not done system programming since about 1995!

To start with you need to be an experienced C/C++ programmer or an expert Delphi programmer, in on Windows. Because writing the kind of DLLs that play nicely with other applications in the Windows environment is not easy.

My advice would be to concentrate on core XOJO right now and rather than going through the documentation, set out to deliver a particular project. You will learn a lot more in trying to deliver a project in XOJO that you will in just going through the documentation, like you are doing. And you will have something to demonstrate to future employers etc going forward.

Put the project up on Github, Giblab, etc so that we can see it and give you feedback on your progress. There are a lot of very experienced software engineers up here and you can learn a lot from them, not just about XOJO, but what it takes to deliver a major piece of software.

If you don’t have a particular project in mind then look at one of the social coding sites and find a project to take on. Most are good causes.

1 Like

I totally agree with you Sir.

I respect everyone around here , just a misfit among all experieced people trying to understand a RAD software on my own. So Maybe … :cry:

But its like my childhood habit that “Before I cut the tree , I sharpen my axe for hours”.

So I am trying to learn reading the official docs. Yes i have learned quite enough now, will make a basic calculator now :slight_smile:

To reply directly to your question littleEndian and bigEndian are ways to store multibyte numbers in memory. For a description see Big Endian and Little Endian (tutorialspoint.com)

The difference is important if a Xojo program needs to exchange data buffers (byte blocks) with a system that requires a specific byte order. Then the buffer can be assembled in the expected way.

A use for this would be to communicate with microcontrollers. If your program is purely Xojo, there is no need to know that.