You are not logged in.

Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

OlimilO

Intermediate

  • "OlimilO" is male
  • "OlimilO" started this thread

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

1

Monday, February 9th 2009, 12:30pm

How to cast?

Hi,

uhh I am trying around a couple of minutes now.

a could not figure it out.

how to cast in Jabaco from an base object to a derived specialised object?

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
Public Sub Command1_Click()
   
   Dim b1 As CommandButton
   Dim b2 As CommandButton
   Dim obj As Object
   
   b1 = Me.Command1
   
   Msgbox b1.Caption
   
   obj = b1 ' OK
   
   b2 = obj ' no! of course this does not work:
   'the error in english:
   'Compile error. Class: 'Form1' line: 15
   'Type mismatch. Found 'VB/CommandButton' but 'java/lang/Object' is required!
 
   'the error in german:
   'Fehler in 'Form1' Zeile 15
   'Eine Konvertierung von 'VB/CommandButton' nach 'java/lang/Ojbect' ist nicht möglich!
   'I think the translation should be the other way around isn't it?
   'Eine Konvertierung von 'java/lang/Ojbect' nach 'VB/CommandButton' ist nicht möglich!
   
   ' But how to cast?
   
   ' Java-syntax would be something like:
   'b2 = (Commandbutton)obj
   ' does not exist in Jabaco
   
   ' VB.NET-Syntax would be:
   'b2 = DirectCast(obj, CommandButton) 
   'or
   'b2 = TryCast(Obj, CommandButton)
   ' both does not exist in Jabaco
   ' i found also the cast- method
   'b2 = System.getClass.cast(obj) 
   ' but how to use it in Jabaco?
   
   Msgbox b2.Caption
   
End Sub


many thanks in advance

greetings

OlimilO

birosys

Trainee

  • "birosys" is male

Posts: 48

Date of registration: Feb 9th 2009

Location: Mladenovac, Serbia

Occupation: Programming

Hobbies: Programming

  • Send private message

2

Monday, February 9th 2009, 2:39pm

Type Casting

here is code

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Public Sub Command1_Click()
   
   Dim b1 As VB#CommandButton
   Dim b2 As VB#CommandButton
   Dim obj As Object
   
   b1 = Me.Command1
   
   Msgbox b1.Caption
   
   obj = b1 ' OK
   b2 = Cast(obj,vb#CommandButton)
   Msgbox b2.Caption
   
End Sub


Cheers!

Milan

OlimilO

Intermediate

  • "OlimilO" is male
  • "OlimilO" started this thread

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

3

Monday, February 9th 2009, 4:36pm

Hi birosys,

many thanks :thumbup:

"Warum in die Ferne schweifen, sieh das Gute liegt so nah." :rolleyes:

greetings

OlimilO

birosys

Trainee

  • "birosys" is male

Posts: 48

Date of registration: Feb 9th 2009

Location: Mladenovac, Serbia

Occupation: Programming

Hobbies: Programming

  • Send private message

4

Monday, February 9th 2009, 8:24pm

You are welcome :)

Rate this thread
WoltLab Burning Board