Declare a class like a new type of variable


I am trying to create a class like a type in Delphi for example.

I have a class like this one:
t_info: code: integer word: string end class

And I want to create an array of array of t_info: t_table(col, line) of t_info.
But I do not find how to declare t_table.

Thank you.


You add a class in the project and name it t_info.
Than you add two properties, one “code as integer” and one “word as string”.

In code you can make an array like this:

dim t_table() as t_info

than you can append items:

dim i as new t_info i.code = 123 i.word = "hello" t_table.append i

Hello Christian,

I am really sorry but my question was incomplete (copy-paste is dangerous).

My Class:
code: integer
word: string
end class

And then I have a new Class : t_table = Array(col, Line) of t_info

And finally my variable:
Dim Table As t_table

My problem is to declare t_table as a type or a class.
In fact it is like I would create a new kind of variable like String, Integer, …

I hope that is clear now.

Thank you.


What part of Christians explanation did you not understand? We can try an explain it differently
Unless you are doing this in a language other than Xojo???

Have a look at the examples. Most should have at least one class. Arrays are defined by adding () after the definition. “dim s as string” is a normal variable. “dim s(-1) as string” is an array. You do the same as classes. For properties you can omit the -1.

Yes I can create classes and declare variables but here it is different for me.

I have a class of class :

t_table(,) As t_info
and Dim s As t_table.
I do not know how to declare t_table.
I use it in Delphi by declaring as a type: t_table = array(col, line) of t_info and then my variable as t_table.

I hope it is more clear.

syntax and info about using multidimensional arrays

you cant make an array a “type”

you could define a class that CONTAINS an array

I also think that may be what you need.

How about this…

' A 5x5 table Dim t_table(4, 4) As t_info t_table(1, 3) = new t_info

On the other hand, if t_table is a class that behaves like an 2-dimensional array, you could add a pair of operator_subscript methods to your class

[code]Public Function Operator_Subscript(row as integer, column as integer) as t_info
// Retrieve the value and return it here
End Function

Public Sub Operator_Subscript(row as integer, column as integer, assigns newValue as t_info)
// store the newValue in here
End Sub[/code]

Then you could use it like this:

dim t_table as new my_t_table t_table(1,3) = new t_info

Subtle different except that in this case you’re responsible for storing the data. You could use an array, an in-memory sqlite database, or whatever you need it to be.

@Greg: the guy needs to crawl before he can sprint.

@Benot Bouillon: please upload your Xojo code to Dropbox and similar and tell us where your problem is.

As I don’t know Delphi, I just offered another avenue to try which might match what he’s looking for.

Operator_Xxxx methods are a great way to make a class behave like a type, and since that’s what he was asking for, why would you give anyone grief for mentioning it?

Thank you for your help.

So I have understood one thing that it is impossible to make an array a “type”.
So I have tried without success to create a list of list of points.
I have several curves of points.
I want to put each point of each curve in different lists
So I have:

Class Coord (x As Integer, y As Integer) for the points. Class List_Pts (Pts() As Coord) List of the points of 1 curve Dim Lists_Pts As List_Pts

But I don’t know how to initialize Lists_Pts and put some coordinates into Pts.

Lists_Pts = New List_Pts ??????????????? Lists_Pts(0).Pts(0).x = .... Lists_Pts(0).Pts(0).y = .... Lists_Pts(0).Pts(1).x = .... Lists_Pts(0).Pts(1).y = .... Lists_Pts(1).Pts(0).x = .... Lists_Pts(1).Pts(0).y = .... Lists_Pts(1).Pts(1).x = .... Lists_Pts(1).Pts(1).y = ....

I hope it is clear or maybe there is a way to make it differently.


You can use param array in your constructor (both for a list (array) of points and for a list of integer but in this case you have to check what to do if you use an odd number of parameters)

It is maybe clear in your mind but not in mine.

[code]class List_Pts
property pts() as xojo.core.point //since exists I used this instead of your class coords
Public Sub constructor(paramarray points() as Xojo.Core.Point) //Constructor from an undetermined list of points
for i as integer=0 to points.Ubound
pts.Append points(i)
End Sub
Public Sub Constructor(paramarray points() as integer) //Constructor from an undetermined sequence of x and y coordinates
for i as integer=0 to points.Ubound Step 2
if (i+1)<=points.Ubound then
pts.Append new Xojo.Core.Point(points(i), points(i+1))
end if
End Sub

//Your stuff
end class[/code]

So you can create as:

dim lp1 as new List_Pts(0, 0, 1, 0, 2, 5)


dim lp2 as new List_Pts(new xojo.core.point(0, 0), new xojo.core.point(1, 0), new xojo.core.point(2, 5))

Thank you Antonio,

I can create a list of points but you learn me a cleaner way to do it.
For info I had create “Coord” because “xojo.core.point” or “Realbasic.point” are not recognized, I dont know why, I have Real Studio 2010 Release 2.
But now I have to create a list of those lists of points.
Imagine that you have several curves in your picture.
So I put in the first curve the points that I detect in the picture, so I have Curve(1) with the first list of points.
And then for the following curves: Curve(2) with 24 Points, …, Curve(n) with m points.
I cant create that variable or class Curve.

Dim List_Pts() As Variant List_Pts.Append(... your curve 1 list ...) List_Pts.Append(... your curve 2 list ...)

If I understood your problem, you have an array with the coordinates. In this case you need a third kind of constructor that’s the same as the one with paramarray without the paramarray keyword.

Public Sub Constructor(points() as integer) //Constructor from an array of x and y coordinates
  for i as integer=0 to points.Ubound Step 2
    if (i+1)<=points.Ubound then
      pts.Append new Xojo.Core.Point(points(i), points(i+1))
    end if
End Sub

you can rewrite the original one as:

Public Sub Constructor(paramarray points() as integer) //Constructor from an undetermined sequence of x and y coordinates
End Sub

In this way you can create from a list o coord object, a list of integer or an array of integer (create the same for coord objects is trivial)
Your class can be used to create your curve array:

dim curves() as List_Pts curves.append new List_Pts(0, 0, 1, 0, 2, 5) curves.append new List_Pts(new coords(0, 0), new coords(1, 0), new coords(2, 5)) dim sample() as integer sample.append 0 sample.append 0 sample.append 1 sample.append 0 sample.append 2 sample.append 5 curves.append new List_Pts(sample)

If you need to subclass your point list to give, for example a color or other information you can:(so we have a prop localColor as color)

class coloredCurve subclass of ListPts Public Sub constructor(c as Color, coordinates() as integer) localColor=c super.constructor(coordinates) end sub
… and the same for the other constructor variant

if you need a class to contain all the curves
class Curves
property theCurves() as List_Pts
public sub add(c as List_Pts)
theCurves.append c
end sub
end class

So you can use:

dim c as new Curves c.add new List_Pts(0, 0, 1, 0, 2, 5) c.add new coloredCurve(, 0, 0, 1, 0, 2, 5)

Hello Antonio,
I become crazy, I translated more than 6000 lines of code of my previous language and I am blocked with this kind of classes and after that I have to solve another problem with linked lists to hope to see my program finally working.
To summarize, nothing works.
I simplify by keeping one way to declare my class.

Public Sub Constructor(paramarray points() as integer) //Constructor from an undetermined sequence of x and y coordinates self.constructor(points) End Sub

“self.constructor(points)” is not recognized so I am already blocked.
I read on Internet that “Point” as been introduced with release 2011.