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 1 Wil van Antwerpen
3 1 Wil van Antwerpen
In recent versions of DataFlex you do not have to use the Self notation when addressing objects.
4 1 Wil van Antwerpen
5 1 Wil van Antwerpen
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 1 Wil van Antwerpen
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 1 Wil van Antwerpen
16 1 Wil van Antwerpen
The latter form is much easier to read for most human beings, so it is a preferred notation style.
17 1 Wil van Antwerpen
18 1 Wil van Antwerpen
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 1 Wil van Antwerpen
20 1 Wil van Antwerpen
The refactoring method will popup a message box that asks you if you want to change the line of code.
21 1 Wil van Antwerpen
In it's most bare form it does that for each change.
22 1 Wil van Antwerpen
23 1 Wil van Antwerpen
As this is fairly invasive, you can tick a checkbox to remember specific objects.
24 1 Wil van Antwerpen
25 1 Wil van Antwerpen
So if you already decided to rewrite (oMyNewForm(Self)) into oMyNewForm then it remember that particular choice.
26 1 Wil van Antwerpen
27 1 Wil van Antwerpen
You can also keep the current lining out of the code by replacing the "wiped" out part of the code replaced with spaces.
28 1 Wil van Antwerpen
29 1 Wil van Antwerpen
## Why all the questions?
30 1 Wil van Antwerpen
31 1 Wil van Antwerpen
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 3 Wil van Antwerpen
36 3 Wil van Antwerpen
~~~
37 3 Wil van Antwerpen
Object oTest is a cObject
38 3 Wil van Antwerpen
  Property Handle phoTestObject
39 3 Wil van Antwerpen
  Set phoTestObject to Self
40 3 Wil van Antwerpen
  Procedure Hello
41 3 Wil van Antwerpen
    Showln "Hello"
42 3 Wil van Antwerpen
  End_Procedure
43 3 Wil van Antwerpen
  
44 3 Wil van Antwerpen
  Send Hello of (phoTestObject(Self))
45 3 Wil van Antwerpen
End_Object
46 3 Wil van Antwerpen
~~~
47 3 Wil van Antwerpen
48 3 Wil van Antwerpen
When you change the Send Hello line into:
49 3 Wil van Antwerpen
50 3 Wil van Antwerpen
~~~
51 3 Wil van Antwerpen
  Send Hello of phoTestObject
52 3 Wil van Antwerpen
~~~
53 3 Wil van Antwerpen
54 3 Wil van Antwerpen
Your code no longer compiles.