Import Class Code from Text File

I feel stupid like I should know this but I can’t figure it out.

How do you import an entire class that you have in a text file into Xojo? When I try importing it, I just get an alias to the file. Is there some extra formatting or something that needs to be used?

Just so I am clear - how do you import something like this where you can look at an example project code on Christian’s site:


You might need to change the extension on the file if it isn’t what Xojo expects. I don’t know what the correct extension is at the moment but if you export an existing class to a text file you can see what it should be.

Yeah it’s xojo_code but when I import, it’s just the class name and nothing else that gets imported (ie: no properties, methods or anything else).

When it imports, are you getting an empty class (small blue box icon) or a external item (document icon, name in italics)?

Depending on how I do it, I get either one…

Edit: I’m not so sure this post is relevant, text projects don’t allow external .xojo_code items. Perhaps they borked something…

Xojo text format is very sensitive. You may not always be able to copy and paste code directly from external sources and try to trick the IDE by shoving it into a .xojo_code file.

If it’s an important chunk of your own code, you may want to open a text editor and start just moving it piece by piece now. I was able to successfully drag a .xojo_code file written by the IDE into the navigator using 2022r2. You could try using the older version like I do, but I suspect this might be a problem with some assumptions about the text format being more simple than it is.

To answer your question about MBS examples specifically, the best solution for MBS examples is to open the project files from the download package. You can download them separately if necessary.

Yeah, the MBS one was just an example. This was another place where I got code. I’m not trying to use an external item but to import it. If you look at .xojo_code files, there’s all sorts of #Tag lines around every different method, event, etc. It looks like these are needed. It does appear you can’t just import raw code into Xojo.

How would the IDE know where to put it, even if you could “just import it” ?

You had said you’d gotten the name-in-italics item, which is an external item. The IDE should be automatically importing .xojo_code directly and not allowing you to reference it as an external. It may be the internals of the document confused the IDE as to what it was though… that’s just speculation :upside_down_face:

FWIW, it’s more than just the #tags, the nesting and spacing is important too. It’s a bit more sensitive than it looks, one of the reasons ARGen would generate XML projects.

Thanks all. I guess it’s not so simple then… :smiley:

The text file must be like this:

a) class definition (in this example the class is “clsSentinel”)

#tag Class
Protected Class clsSentinel

b) Protected Property definition:

  #tag Property, Flags = &h1
    Protected RS_Sentinel As RecordSet
  #tag EndProperty

c) Public Property definition:

  #tag Property, Flags = &h0
    Snt_ID As Integer
  #tag EndProperty

d) Private Property definition

  #tag Property, Flags = &h21
    Private mRecordFound As Boolean
  #tag EndProperty

e) Computed Property definition:

  #tag ComputedProperty, Flags = &h0
        #tag Getter
              Return mRecordFound
            End Get
        #tag EndGetter
        RecordFound As Boolean
  #tag EndComputedProperty

f) Private Method definition:

  #tag Method, Flags = &h21
    Private Sub ClearProperties()
    // Inizializzazione proprietà

    Snt_ID = 0
    Snt_FolderName = ""
    Snt_DistFromJobStart = 0
    Snt_RowNumber = 0
    Snt_DateTime = Nil
    Snt_Type = ""

    ' ReDim Record(-1)

    Dict = Nil

    mRecordFound = False

  End Sub
  #tag EndMethod

g) Public Method definition:

  #tag Method, Flags = &h0
    Function Delete() As Boolean
      // Cancellazione record tabella Sentinel

      Dim RS As RecordSet
      Dim SQL As String

      SQL = "DELETE FROM Sentinel WHERE 1 = 1 " 

      SQL = SQL + " AND Snt_ID = " + Cstr(Snt_ID)


       // errore ritornato dal Database
      If DB_SQLServer.Error Then
        mPropErrMessage = DB_SQLServer.ErrorMessage
        Return False
        Return True
      End If

    End Function

  #tag EndMethod

h) at the end of the class:

End Class
#tag EndClass