On Sat, 28 Jun 2014, Orionis wrote:
> Hi, I'm starting to investigate this control. This is my first question, but
> more will follow
> I have an Editor called 'edit' loaded with some text; I want to recover each
> single line to parse them.
> 
> This is an example of code:
> [code]
> Dim lineObj As Variant
> Dim sRow As String
> 
>    For cnt = 0 To edit.lines.Count - 1
>       lineObj = edit.Lines[cnt]
>       sRow = CStr(lineObj)
>    Next
> [/code]
> I get an "Type mismatch errror: wanted String, got  .Editor.Line instead" at
> line 'sRow =...'
> First question: why the CStr, which should accept a Variant, complies on
> this value?
> 

.Editor.Line is a virtual class which means that it does not represent a
distinct object but merely a state of another object. (This is totally
different from the "virtual" keyword in C++!) You cannot hold a reference
to virtual objects, so you cannot put them into Variant reliably either or
convert them, etc..

> Later;
> In the documentation I found this example:
> [code]
> Dim hEditor As Editor
> Dim hEditorLine As .Editor.Line
> hEditorLine = hEditor.Lines [ Line As Integer ]
> [/code]
> This is completely wrong from my test:
> *Dim hEditorLine As .Editor.Line* gives an "Unexpected . "
> Removing the initial dot (so, *As Editor.Line*) does not recognize the type
> 

Your interpretation is not the way in which the documentation should be
read. As I said above, virtual objects cannot be referenced, so you cannot
declare a variable of a virtual class type (as you have noticed). The
documentation syntax above just tells you what type the return value is
and thereby provides a link to its documentation.

I agree that the fact that it indeed declares a variable of that type (of
which you cannot declare variables actually) is a bit confusing but once
you've seen this pattern, you're in the know. Virtual class names, by
convention, start with the "." character.

> At the end: how can I get a single line as string from the Editor?
> 

Virtual objects mimic the way real objects work, i.e. they have properties
and methods. (Virtual objects are never single values because in this case,
there would not be a virtual class in the first place.)

In this particular case you get the text of the i-th line by:

  edit.Lines[i].Text

Regards,
Tobi

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to