[Gambas-bugtracker] Bug #2745: Provide a way to know if a class or object is in fact a structure

bugtracker at gambaswiki.org bugtracker at gambaswiki.org
Mon May 15 18:26:37 CEST 2023


http://gambaswiki.org/bugtracker/edit?object=BUG.2745&from=L21haW4-

Comment #7 by Brian G:

This is getting a little strange. I actually don't care in the end how Gambas writes the data.
My Examples previously were used to identify that internally the interpreter does know if an object is 
a struct defined in the application.

Here is the scenario of the app being used.

If I define a Structure

struct MyStruct 
   fox as boolean
   cat as boolean
   dog as boolean
   name a string
end struct

Gambas created a class called MyStruct
This class can be instantiated anywhere.

I can also create a gambas class

class MyClass
   Dog as boolean
   cat as boolean
   fox as boolean
   name as string
public sub _write(mystream as stream)
    ' process and send data
end
Public sub _read(mystream as stream)
    ' receive and process data
end
end class

This class can be instantiated anywhere, and know how to transmit and receive itself.
Unlike structures which can not be told how to transmit and receive itself.

I have a generic class called transport that can send objects and receive objects it knows the stream etc
It knows nothing about the actual application classes etc. So can not use class names to identify what they are.

class SafeTransport

public sub _new(theStream as string)

   ' open and prepare the stream, tcp probably
end

public sub Send(MyObject as object) as boolean

    ' send the data object to other side adding headers etc needed to id info on other side
    ' it is here that I need to identify the object as a gambas defined structure to
    ' provide special handling of the data, unlike I do for gambas classes I can not add the _read/_Write
    ' format for the data.
end

Public sub Receive() as object

   ' Receive the incoming data read the id info and create the object

   return 

end class

I guess if we could add a _Read/_Write procedure to a structure definition that would work too.

struct MyStructure
   dog as boolean
   cat as boolean
   fox as boolean
   name as string
   public sub _write(f as stream)
     ' write all the data
   end
   Public sub _read(f as stream)
     ' read all the data(f as stream)
   end
end struct




More information about the Bugtracker mailing list