Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 8 Next »

Question: How can I remove an application function and replace calls to it with something different?

Answer:

First of all, an option that should be considered is to keep your original calls as is, but to fine tune the implementation to use .NET by hand. Then, use a Author/Replace or related command to to swap in in your fine-tuned code.  

However, if you really want to change the calls, You may add some refactoring commands to your translation script.  In the <compile> section of the script, do a remove/remove-stubout with a migPattern.  This will rework the calls. Then, after the <analyse> section, use refactor/remove-delete to remove the original. Something like this.
Example1: Here is an example you can try using our ScanTool sample:

<Compile Project="%SrcPath%">
<refactor>
<remove identifier="ScanToolLib.readNode" migStatus="stubout" migPattern="%1d.ReadXMLNode(%2d))" />
</refactor>
</Compile>
<Analyse />
...
<refactor>
    <remove identifier="ScanToolLib.readNode" migStatus="delete" />
</refactor>
...
<Author>

Since the methods to be refactored are in a module, these rules will be needed for each VBP that uses the module – unless you moved the module to an IDF using the SharedFile command. 

Example 2: I have a Declare in a SharedFile, that I want to migrate to a Framework call:

Vb6
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
...
Sleep 500

We want no declaration and calls like this:

...
System.Threading.Sleep(500);

To make things more interesting this Declare was in a module that was shared throughout the system;  the declaration is being moved into a host project using the Shared

<Compile Condition="%SrcName%=='AppCommon'">
   <Refactor>
      <Migrate id="GlobalDeclarations.Sleep" nPram="2" migName="System.Threading.Sleep" migStatus="external" />
   </Refactor>
</Compile>

Changes the calls in AppCommon as expected

The Migrate command also adds a migName to the FromCode IDF generated for the translation:

FromCode\AppCommon.dll.xml

      <method id="Sleep" migName="System.Threading.Sleep" type="Void">
         <argument id="dwMilliseconds" type="Integer" status="ByVal"/>
      </method>

The migName attribute alters calls made to the method the codes that reference AppCommon.DLL.

Note that in this case, a "migrated" declaration is authored in the generated DLL code; it must be removed with an Author\Fix.

<Author Condition="%SrcName%=='AppCommon'">
<Fix host="%SrcName%" name="PostEdit">
   <Replace name="Remove GlobalDeclaration.Sleep">
   <OldBlock><![CDATA[
         [DllImport("kernel32")]
         public static extern void System.Threading.Sleep(int dwMilliseconds);
   ]]></OldBlock>      
   </Replace>
</Fix>



  • No labels