Project

General

Profile

TH3-Drop Self » History » Version 3

Wil van Antwerpen, 06/04/2019 11:33 PM

1 1 Wil van Antwerpen
# Drop Self
2
3
In recent versions of DataFlex you do not have to use the Self notation when addressing objects.
4
5
Eg.
6 2 Wil van Antwerpen
7 1 Wil van Antwerpen
~~~
8 2 Wil van Antwerpen
Get Value Of (oMyNewForm(Self)) to sValue
9 1 Wil van Antwerpen
~~~
10
can be written as
11 2 Wil van Antwerpen
12 1 Wil van Antwerpen
~~~
13 2 Wil van Antwerpen
Get Value Of oMyNewForm to sValue
14 1 Wil van Antwerpen
~~~
15
16
The latter form is much easier to read for most human beings, so it is a preferred notation style.
17
18
The refactoring option "Drop Self" helps you to find and rewrite all the object notations that use the legacy self style and suggests to change them into the variant without Self. Hence the name.
19
20
The refactoring method will popup a message box that asks you if you want to change the line of code.
21
In it's most bare form it does that for each change.
22
23
As this is fairly invasive, you can tick a checkbox to remember specific objects.
24
25
So if you already decided to rewrite (oMyNewForm(Self)) into oMyNewForm then it remember that particular choice.
26
27
You can also keep the current lining out of the code by replacing the "wiped" out part of the code replaced with spaces.
28
29
## Why all the questions?
30
31
The reason you get the message box is because our parser can not detect everything at this stage.
32 3 Wil van Antwerpen
For example if you use a property to reference an object then the Self notation is required.
33 1 Wil van Antwerpen
34 3 Wil van Antwerpen
Here's a code example of when you cannot remove the Self.
35
36
~~~
37
Object oTest is a cObject
38
  Property Handle phoTestObject
39
  Set phoTestObject to Self
40
  Procedure Hello
41
    Showln "Hello"
42
  End_Procedure
43
  
44
  Send Hello of (phoTestObject(Self))
45
End_Object
46
~~~
47
48
When you change the Send Hello line into:
49
50
~~~
51
  Send Hello of phoTestObject
52
~~~
53
54
Your code no longer compiles.