[Gambas-devel] Passing things

Benoit Minisini gambas at ...20...
Sun May 11 12:57:58 CEST 2003


Le Dimanche 11 Mai 2003 03:35, Ken Schrock a écrit :
> I am having trouble passing data between objects, classes, forms, etc.
>
> To add an element to a listbox
> Pop up a new form for entry, ok so far
>
> But in Form2 if one tries to pass data to Form1 with
> Form1.Listbox1.Add(whatever) it says it can't find ListBox1
> It appears the controls, if created by the IDE, aren't made public
> And there seems to be no option in the properties box to do so
>
> Call a public function - Says it isn't static - Make it static
> It says you can't use dynamic things in a static function
>
> Ok guys, give me a hint here

Hi Ken,

You should have posted this mail on the user mailing-list. This is list is for 
people who are developing Gambas, not developing WITH Gambas !

Controls are not public, they are private. This way, the bad old VB developer 
must adopt a cleaner way of writing its program :-)

Forms are not self-instanciable. I.e. if you have a form Form1, then Form1 is 
the name of the class, not the name of an instance !

Here is a bad example of how to solve your problem, but easy to understand:

MyForm1 = NEW Form1
MyForm1.Show

*** In MyForm1:

MyForm2 = NEW Form2(MyForm1)
MyForm2.ShowModal()

...

PUBLIC SUB AddToListBox(sElt AS String)

  ListBox1.Add(sElt)

END

*** In MyForm2:

PRIVATE MyForm1 AS Form1

PUBLIC SUB _new(hForm AS Form1)

  MyForm1 = hForm

END

...

MyForm1.AddToListBox(TextBox1.Text)


Here is a better way to do that:

*** In Form1:

sElt = Form2.Run()
IF sElt THEN ListBox1.Add(sElt)

*** In Form2

STATIC sResult AS STRING

STATIC PUBLIC FUNCTION Run() AS STRING

  DIM hForm AS Form2

  hForm = NEW Form2
  IF NOT hForm.ShowModal() THEN RETURN
  RETURN sResult

END

...

PUBLIC SUB btnCancel_Click()

  ME.Close()

END

PUBLIC SUB btnOK_Click()

  sResult = TextBox1.Text
  Me.Close(TRUE)

END

Regards,

-- 
Benoit Minisini
mailto:gambas at ...1...




More information about the Devel mailing list