Autore Topic: Domanda su Class.Load()  (Letto 374 volte)

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.723
  • Ne mors quidem nos iunget
    • Mostra profilo
Domanda su Class.Load()
« il: 02 Novembre 2014, 12:32:20 »
Riporto questa discussione:


" Class.Load allows you to create a reference to a named class.
Codice: gambas [Seleziona]
Dim TempClass as Class
TmpClass = Class.Load("myclass")

This works and I can get the names of the public instances of variables
and procedures

For each TmpString in TmpClass.Symbols
Message(TmpString)
Next

Is there a way to call a Procedure or Function from the named class and
pass it any parameters that it requires?

ie: if I have a procedure in a valid class I have created called Public
Sub DoSomething(InStr as string)
can I call this function from TmpClass somehow
(or is this just a 'read only' reference to the loaded class?)


I tried
Object.Call(TmpClass, "NameOfProcedure", TmpAry)
with TmpAry[] containing the name of a single string parameter I wish to pass.
This returns the error: "Can't find {NameOfProcedure} in Class 'Class'

Context: In each of my projects created classes, I have a standard
Procedure to save the applicable database table records to a binary file
called CreateBinaryFile(InPath as String)
This is the process I am trying to call for each class that I have created.

Cheers,
Ian Roper.
"


" Just one question ... have you exported those classes ?

tmpClass is just a class ... not an instanciate object

You need to call Object.New

Or just new

Codice: gambas [Seleziona]
Public Sub Main()
Dim hObj As Object
Dim sSym As String
For Each sSym In Classes["MyClass"].Symbols
  Print sSym
Next

hObj = Object.New("MyClass")

Object.Call(hObj, "CreateFile", ["Hi World"])

End


Fabien "


" Merci Fabien,
That solution worked very well.

I had thought that you only needed to export classes when using them for
a component ?
(from the Gambas Wiki on Components - Which is the only reference I can
find to exporting classes.)

One other question.
So what would Class.Load be used for ?

Ian.
"


" Well


A class is the caneva... a dead container

If you want to use it you must to make it alive to interact with it.

so a class is the description of what can be the object. An object is
an instanciated class


A static class then is a self instanciated class (like module).

Fabien
"
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »