Other icon

Functions of type eOtherFunction work on a whole file, passed as a string array of source lines. The function returns the number of lines it changed.


Cancel handling inside refactoring functions

If a refactoring function (especially of the eOtherFunction and eOtherFunctionAll types) loops over many lines or files, it can let the user cancel without waiting for the loop to finish. Use:

Get pbUserCancelRequested of ghoEngine to bCancel

and leave the loop when it returns True. Never call Get Cancel_Check of ghoEngine from inside a refactoring function. That is the engine's own cancel handling: it closes the status panel and shows the confirmation dialog, and calling it from a function uses up the cancel request without anyone noticing. The engine then cannot see the cancel, and the program seems to hang while it continues with the remaining files. pbUserCancelRequested only reads the state and changes nothing, so the engine's own cancel check between files still works.


AddFunctionReturnsKeyword

Adds the required "Returns <type>" to a legacy Function declaration that does not have it (compile error 4392).

Older compilers accepted a declaration without it, such as "Function Verify_Exit_Application"; a modern compiler does not, which is why an application created with an old wizard can get many 4392 errors.

The return type is determined from the function's code: a Function_Return of a string, a number or True/False gives the type directly, and a variable name is looked up among the function's local variables. When there are several Function_Return lines, the types are combined: Integer and a decimal number give Number, and anything combined with a String gives String.

When the type cannot be determined, the declaration gets "Returns Integer" and a TODO (DFRefactor) comment for you to review. That always compiles, because any return type compiles where a declaration without one fails, and the runtime converts the value for the caller.

A declaration that continues on the next line with ';' is read as a whole. If it already has Returns on the next line, it is not changed; otherwise the Returns is added to the last line.

Group: Modernization

Fixes compiler message(s): 4392


ChangeAmbiguousCallToGet

Fixes error 4544 by changing calls in expressions of a method with an ambiguous return type into Get statements, without changing any declarations. Enter the method name or names as the function's parameter.

Error 4544 is reported when one message name is declared with different return types in the workspace, for example a container class and a DEO that both declare Function Value. The compiler cannot determine the type of a call in an expression, and reports every one of them. A few declarations can cause hundreds of errors, in files that have nothing to do with those classes.

Example: If (Value(oFoo,"k") = 1) becomes three lines, with a Variant variable declared where the call was:

Variant vDfrGet1

Get Value of (oFoo) ("k") to vDfrGet1

If (vDfrGet1 = 1)

Caution: the call is now made before the rest of the expression is evaluated, so for a call with side effects, this changes what the code does. The other way to fix the error is to rename the few conflicting declarations, or give them the same type. That is a much smaller change, but a design decision that only the code's owners can make, which is why this function is a suggestion.

Comment lines, lines that continue a statement, calls without an object, and lines with unbalanced parentheses are not changed. Nested calls are changed from the innermost one outwards.

Group: Modernization


ChangeBeginEndConstraint

Converts legacy Begin_Constraints / End_Constraints blocks into a modern OnConstrain procedure.

Everything in the block (declarations, Get, If and Else lines with the Constrain lines they control, and any Report_* lines) is moved, unchanged and in the same order, into 'Procedure OnConstrain', which starts with 'Forward Send OnConstrain'. Nothing is reordered, because, for example, a Report_Index parameter can depend on code earlier in the block.

Comments are kept, and blank lines are removed. A block without a matching End_Constraints is not changed. An End_Constraints without a Begin_Constraints, where the start has already been changed to Procedure OnConstrain, is changed to End_Procedure.

Group: Modernization

Fixes compiler message(s): 4533


ChangeCmdlineCommandToFunction

Replaces the obsolete "Cmdline <var>" command, which reads the next command-line argument, with the cCommandLine class.

Each line becomes "Move (NextCmdLineArgument()) to <var>". NextCmdLineArgument() is a small function that is added at the top of the file. Like the old command, it returns the next argument each time it is called, and "" after the last one.

Why a helper function is needed: the old command read the next argument on every call, one after the other, while cCommandLine.Argument(i) reads the argument with a given number. Which number a line needs depends on the code around it, typically a While loop that reads until the value is empty. NextCmdLineArgument() goes through Argument(1..n) and returns "" after the last argument, just as the old command did, so such a loop still ends the way it always did.

What is added at the top of the file: Use cCommandLine.pkg, a global counter and NextCmdLineArgument() itself. It is protected by #IFDEF, so running the function twice on the same file does not add it twice.

Limitations: only the exact form of the command with two words is converted. A variable that happens to be named Cmdline elsewhere in a line, and the rare form with a length argument, are not changed.

The old command still compiles without any message in modern DataFlex, so the compiler does not report it. Analyze Source finds it.

Group: Modernization


ChangeDfTimerTocTimer

Converts legacy 'Object ... is a dfTimer' objects to the modern cTimer class.

The class is changed, Auto_Start_State, Auto_Stop_State and Timer_object are removed, Timeout becomes piTimeout, the parameters of OnTimer are removed, and Timer_Active_State becomes pbEnabled in the whole file.

A dfTimer that started by itself (it never sets Auto_Start_State to False) does not start by itself as a cTimer, so 'Set pbEnabled to True' is added for it.

Objects that use Timer_Message, or the parameters of OnTimer, are not changed, but get a TODO comment, because those need to be changed by hand.

Group: Modernization

Fixes compiler message(s): 4537


ChangeExternalFunctionCallers

Changes the code that calls a Windows API, so that it uses a modern Struct instead of a byte buffer.

The Type block is commented out, not deleted. A Struct with the same member names and the types that the Windows SDK uses is added instead, including the padding between members that a legacy Type block cannot describe.

Then every line that used the buffer is changed: ZeroType, Put..At, GetBuff and GetAddress become struct assignments, member access and AddressOf.

This fixes a 64-bit error that the compiler does not report. A legacy block that declares 4 bytes where Windows reads 8 makes the struct too short, and the API then writes past its end.

The Type is found by its name, or by its member names when the name does not match the SDK. A match by member names is reported in the run notes, so that you can check that it is the right struct.

Every use of the buffer must be one that this function can change. If one line cannot be recognised, the whole Type is left unchanged, and the run notes name that line.

A Type that DataFlex's Dftypes.pkg declares, but for which DataFlex has no Struct (DEVMODE, DEVNAMES), becomes a Struct that is copied member by member into DfTypesStructs.pkg in the workspace's AppSrc folder, and a Use of that file is added.

Group: x64 + Unicode


ChangeFloatingPopupMenuToCodeJock

Converts a FloatingPopupMenu or dbFloatingPopupMenu object (the legacy right-click menu) to a cCJContextMenu, with one item object for each menu item.

The object keeps its name, so every 'Set Floating_Menu_Object to (x(Current_Object))' and 'Send Popup to (x(Current_Object))' line still works.

On_Item and Add_Item lines become item objects; a line that continues with ';' is read as a whole. A standard message (Prompt, Request_Save ...) becomes the cCJ* class that comes with DataFlex, with its own translated caption. The program's own message becomes a cCJMenuItem that sends it to the object with the focus, as the legacy menu did, or to the target named after 'to'.

A Property declaration is kept, and a Set Aux_Value line is commented out with a note. Msg_None becomes pbControlBeginGroup on the next item, and Status_Help becomes psToolTip.

For a dbFloatingPopupMenu, its ten inherited items come first, as the standard DEO classes. A Popup procedure in the object is kept, with 'Set Shadow_State Item N' changed to pbEnabled of the Nth item.

The legacy object is commented out below the new one, never deleted, and the Use lines that the item classes need are added.

Not converted, each with a comment that gives the reason: any other procedure or function of its own, an If statement around the items, an object inside the menu, or a caption that is an expression. A subclass is converted by ConvertPopupMenuSubclassToCodeJock instead.

The converted menu needs the program's cCJCommandBarSystem when it runs.

Group: Modernization

Fixes compiler message(s): 4537


ChangeIfchangeCommandToAttribute

Replaces the obsolete Ifchange command with a read of DF_FILE_CHANGED and the test it was used for.

Example: Ifchange pay gosub logchange becomes Boolean bDfrFileChanged / Get_Attribute DF_FILE_CHANGED of pay.File_Number to bDfrFileChanged / If bDfrFileChanged gosub logchange

The Boolean is declared once in each method, just above where it is first used. The indentation, the command after the test and any comment at the end of the line are kept as they are.

Review the result. Both forms have been tested to report the same condition, and the new form is the one the DataFlex framework itself uses. But this is the only converter that adds a declaration to the method, and it has not yet been run on real code.

Lines that are not changed get a TODO comment with the reason: a line that continues a statement with ';', a command outside a procedure or function, a statement that continues on the next line, and a file argument that is not a plain table name. An Ifchange that is not the first word on its line is never changed.

Group: Modernization

Fixes compiler message(s): 4533


ChangeLegacyClassToModern

Replaces a legacy class with its modern equivalent: the object declarations, the Use line and renamed members. A parameter controls what is replaced, so one function can be used for any third-party package that is now part of DataFlex.

The parameter starts with 'Old=New', optionally followed by 'use:a.pkg=b.pkg', 'get:Old=New', 'send:Old=New' and 'set:OldProp=NewProcedure' (a property that became a procedure).

Anything it cannot identify is reported instead of guessed, and a subclass never gets a new base class.

Group: Modernization


ChangeLegacyTypeToWinStruct

Replaces a legacy Type byte buffer with the Struct that DataFlex now includes for the same Windows API. This is the modern way, and it works with Unicode, which a String buffer did not.

The String declaration gets the new type, and the ZeroType line is removed, because a local Struct is already empty, as the compiler's message also says. Put and GetBuff become Move statements, and <Type>_size becomes SizeOfType(<Struct>). AddressOf is not changed, because the API needs the struct's address.

The change is made only where DataFlex actually includes the replacement Struct, checked against the compiler you are moving to: the struct must exist there, and every field that the code uses must exist in it.

A buffer that is used in any other way, that is declared on the same line as other variables, or that is used with two different Types is not changed, and the run notes say so. The change is made completely or not at all.

Group: x64 + Unicode


ChangeObjectFunctionCallToGet

Replaces calls of object methods in an expression (Name(Self, args)) with the Get command (Get Name args to dest), which DataFlex 26 requires.

The simple form 'Move (Name(Self[, simple args])) to dest' is changed automatically, for methods declared without Global in the same file. Every other use (inside a larger expression, with complex arguments, not in a Move, or where the first argument is not Self) gets a TODO comment for a manual change.

Calls of global functions, and names that cannot be found in the file, are not changed, and neither is a Move into an indicator such as Found, because Get cannot write to an indicator.

Examples: 'Move (FormatValue(Self, sRaw)) to sOut' becomes 'Get FormatValue sRaw to sOut', and 'Move (RowCount(Self)) to iN' becomes 'Get RowCount to iN'.

Why this matters: the expression form compiles until a DataFlex release adds a function with the same name (for example Split, which comes with the cRegEx class in DataFlex 26). The call then uses DataFlex's own function, the number of arguments or the return type no longer match, and you get error 4379 or 4544. The Get form sends a message to the object, so it uses the workspace's method again.

Group: Modernization

Fixes compiler message(s): 4544


ChangeObsoleteClassNames

Replaces an old DataFlex class name with its current name, which is the same class.

Example: Class cMyControl is a DFControl -> Class cMyControl is a DfBaseControl

It covers the 27 old names that DataFlex still defines (Message, BaseClass, DFObject, DFPanel, ImageList ...), after 'is a', after 'for' in a method header, in RefClass(), and as U_ names.

Group: Modernization


ChangeObsoleteMethodTarget

Replaces an obsolete 'for' target in a method header: for DFDesktop becomes the Desktop keyword, and for Desktop and for BaseClass become for cObject, which is the same class.

Example: Procedure Exit_Application for BaseClass -> Procedure Exit_Application for cObject

Group: Modernization

Parameter: "cObject, Desktop"

Default: cObject

What for Desktop and for BaseClass become; cObject - for cObject, the same class: nothing changes,

Desktop - the Desktop keyword, for a method meant for the desktop: it changes which objects understand it.

for DFDesktop always becomes the Desktop keyword.


ChangeParsePathPairToExtractFilePath

Replaces the legacy way of splitting a path in three parts with one modern call: "Get Parse_Path x to sPath" and "Get Parse_Drive x to sDrive" become "Get ExtractFilePath x to sPath", and any "(sDrive + sPath)" becomes sPath.

This is not a simple rename, because ExtractFilePath alone does not return the same as Parse_Path, which removes the drive, removes the separator at the end, and checks the disk.

Before and after:

Get Parse_Path <spec> to <sPath> -> Get ExtractFilePath <spec> to <sPath>

Get Parse_Drive <spec> to <sDrive> -> (line deleted)

... (sDrive + sPath) ... -> ... sPath ...

Note: the old code returned the folder without a separator at the end, and ExtractFilePath returns it with one. Where that text is shown to the user, the extra separator is visible; no code is added to remove it.

When the drive variable is used in a way that cannot be fully checked, nothing is changed, so a conversion is never left half done.

Group: Modernization

Fixes compiler message(s): 4534


ChangeReplaceDirectiveToDefine

Replaces the legacy '#REPLACE <name> <value>' compiler directive with the modern 'Define <name> for <value>'. The indentation, the comment at the end of the line, and the column of the value are kept, so a block of aligned constants stays aligned.

Example: #REPLACE CP_UTF8 65001 // UTF-8 -> Define CP_UTF8 for 65001 // UTF-8

Only what a Define can safely express is converted: a name that is not a reserved word, is not CURRENT$WORKSPACE and starts with a letter, with a fixed value (a number, a negative number, or a string in quotes).

Not changed, because they are text substitutions rather than constants: a value that is a name or an expression in parentheses, part of a macro, a reserved word as the name, CURRENT$WORKSPACE, the #HEADER section, and Language_*.inc files, which DataFlex uses to compile translated applications.

A TODO comment "// TODO (DFRefactor): NOT converted - ..." is added where a line looks convertible but is not: inside an Enum_List, where a Define with a value would renumber the entries below it; where the value is unquoted text with spaces; and where the file tests the name with #IFDEF or #IFNDEF, which do not see a #REPLACE but do see a Define.

Group: Modernization


ChangeStrLenToExpression

Replaces the legacy STRLEN variable with an expression based on the string command before it.

After 'Pos x in s' or 'Replace x in s with y', a read becomes (Length(s) - Pos(x, s) + 1), the length from the found position to the end, or Length(s) + 1 when nothing was found. After Right or Mid it becomes their count argument.

A method that only uses strlen as a temporary number gets a local variable instead (Integer iStrLen; a value that is written but never read goes to iVoid).

Functions Pos() and Replace() never set strlen, so a read after a converted command already had an outdated value. Such a read is converted the same way, and named in the run notes.

After Replace, the value only exists before the replacement, so a plain 'Move strlen to x' is moved above the Replace line; any other form keeps its line, with a TODO comment.

A read also keeps its line, with the reason in the TODO comment, when no string command comes before it in the method, when that command is conditional or not supported (Sysdate, File_Size, Page, Index_Def), when a value it uses changes in between, when a block boundary lies in between, or when the method passes strlen to a Right or Mid without a count. The string command line itself is kept, because it may still set Found.

Group: Modernization


ChangeStrMarkToExpression

Replaces the legacy STRMARK variable with an expression based on the string command before it.

After 'Pos x in s' or 'Replace x in s with y', a read becomes Pos(x, s), which is 0 when nothing was found, as before. After Left, Pad, Insert or Mid it becomes their count or position argument.

A method that only uses strmark as a temporary number gets a local variable instead (Integer iStrMark; a value that is written but never read goes to iVoid).

Functions Pos() and Replace() never set strmark, so a read after a converted command already had an outdated value. Such a read is converted the same way, and named in the run notes.

After Replace, the value only exists before the replacement, so a plain 'Move strmark to x' is moved above the Replace line; any other form keeps its line, with a TODO comment.

A read also keeps its line, with the reason in the TODO comment, when no string command comes before it in the method, when that command is conditional or not supported (Sysdate, File_Size, Page, Index_Def), when a value it uses changes in between, when a block boundary lies in between, or when the method passes strmark to a Left, Mid or Pad without a count. The string command line itself is kept, because it may still set Found.

Group: Modernization


ChangeStructMemberLegacyTypes

Changes a Struct member of type Word, Byte or Long to UShort, UChar or Integer: the same size, in a type that DataFlex 26 knows.

Word, Byte and Long are field types of legacy Type blocks. In a Struct, DataFlex 26 reads "Word wYear" as an unknown command (error 4298), the Struct is then empty (error 4545), and every use of its members fails.

Converters before 2026-11-12 copied the field types of a legacy Type into the Struct they created, so a converted Type can contain them, and so can a Struct written by hand.

Before: Word StructSize

After: UShort StructSize

Only member lines between Struct and End_Struct are changed, and only the type word.

Group: x64 + Unicode

Fixes compiler message(s): 4298


ConvertGosubToProcedure

Converts legacy Gosub subroutines to global procedures, but only the ones that can be converted safely.

A subroutine with simple flow (plain Gosub_Return lines, no Goto out of it) that only calls other convertible subroutines becomes 'Procedure <label>_Sub GLOBAL ... End_Procedure'. 'Gosub X' becomes 'Send X_Sub', 'Gosub_Return' becomes 'Procedure_Return', and 'ON..GOSUB' becomes a Case block of Send calls.

Subroutines that cannot be converted are not changed; GosubGotoReport shows why.

Variables at file level that a converted subroutine uses become Global_Variable declarations, with a comment for you to review. Nothing is renamed or deleted. The text of comments, report images and multi-line strings is never read as code.

Limitation: a shared variable that is declared inside a converted subroutine becomes a local variable of that procedure. If another converted subroutine also uses it, make it global by hand.

This is a first, careful version: check the result on a real Gosub workspace. The change can be undone from the backup.

Group: Modernization


ConvertPopupMenuSubclassToCodeJock

Converts a workspace subclass of FloatingPopupMenu (the legacy right-click menu) to a subclass of cCJContextMenu: Class MyPopup is a FloatingPopupMenu becomes Class MyPopup is a cCJContextMenu.

  • The class gets its own Add_Item and Item_Count. Code that fills the menu while the program runs (Send Add_Item of hoMenu ...) and code that shows it (Send Popup) are not changed.
  • A small item class, MyPopupItem, is added above the class. Add_Item creates one item object for each call. A selected item sends its message to the object that has the focus, as the legacy menu did; the function ItemMessageTarget in the class is where you change that.
  • An Add_Item with Msg_None and no text was a separator: the next item starts a new group.
  • Use cCJCommandBarSystem.pkg is added when the file does not already have it.

The class is converted only when it contains nothing but Construct_Object and End_Construct_Object with Add_Item and Property lines. A class that contains more is not changed, and the run notes explain why.

Not converted: any other FloatingPopupMenu message that the code sends to the menu (Delete_Data, Shadow_State, Aux_Value ...). Such a line still compiles, but fails when it runs, so look for these lines yourself. This is why the function is listed for review and is not selected automatically.

A dbFloatingPopupMenu subclass is not converted. The menu needs the program's cCJCommandBarSystem when it runs.

Group: Modernization


ConvertWinAPIDeclarationTypes

Corrects the parameter and return types of External_Function declarations to match the Windows SDK: an Integer or DWord where the API uses a pointer becomes Pointer, Handle or Longptr.

This fixes a 64-bit error that the compiler does not report: a declaration written for 32-bit compiles without errors as 64-bit, but cuts off the address when the program runs.

One corrected declaration works for both 32-bit and 64-bit, because DataFlex sets the size of its pointer types for each, so no #IFDEF is added.

The declaration's name, entry point and DLL are kept, so the calls still compile, and an ANSI ("...A") declaration stays ANSI. Changing it to the wide ("...W") version is a separate decision.

Only APIs in the Win32 catalogue are changed. A declaration is not changed, and the run notes say why, when its number of parameters differs from the SDK, or when the API needs different declarations for 32-bit and 64-bit. A declaration that is already correct is not changed, so a second run changes nothing.

Group: x64 + Unicode


ConvertWinAPITypeToStruct

Changes legacy Win32 'Type ... End_Type' blocks to modern Structs, with the member types from the Windows SDK. The type name and all member names are kept, so existing X.member references and AddressOf() calls still compile.

Only Types in DFRefactor's Win32 catalogue are changed, and only when the member names match the SDK exactly. Other Types are not changed, and each one is reported in the run notes with the member that did not match, so a file where nothing was changed still shows why.

Only the declaration is changed, and only when the code around it does not need to change too. Byte-level access (Put, GetBuff, Offset_of_Field, ZeroType) is never changed; TypeToStructReport lists those lines for manual migration.

When the names match, the corrected member types are what matters: a legacy Word where the SDK uses a pointer is exactly the kind of 64-bit error this function finds. When the names are different, the legacy block has combined members that the SDK keeps in a nested struct, so the block is not changed.

Group: x64 + Unicode


DeclareRefactoredIndicators

Declares the legacy named indicators that the indicator converters change into Boolean variables, but that have no 'Indicator X' declaration. Without a declaration, the converted (X) or Move ... to X would refer to a name that does not exist.

Each declaration is a Global_Variable Boolean, protected by #IFNDEF and added at the top of the file. The function reads the code as it was before the conversion, so it must run in the same run as the converters; it is selected automatically with them.

Built-in indicators (Found, FindErr, Err), SELECT, and names that are already declared with 'Indicator X' in the same file are skipped.

It also renames other uses of these indicators in expressions to the name with the gb prefix. A use such as 'If (not(Login_Successful)) Begin' is already valid Boolean syntax, so no converter changes it, but after the declaration has been renamed, it would refer to a name that no longer exists.

Names in strings and comments, and File.Field references, are never renamed. A method that declares a local variable or a parameter with the same name is not changed.

Running the function twice is safe: the #IFNDEF protection means that a declaration is never added twice, and never clashes with the declarations that ChangeIndicatorToBoolean adds, so warning 4390 cannot occur.

Group: Modernization


DefineSelectMacro

Defines the 'Select' macro indicator that remains when ChangeLegacyIndicators or ChangeSquareBracketsIndicators converts a legacy [Select] with the eModernizeSelect setting.

A protected definition of the SELECT macro (a Replace inside #IFNDEF) is added near the top of the file, after the Use and #Include lines and before the first line of code, so that it comes before every use of it.

A Use of OldFMACCommands.pkg is not added instead, because that package defines SELECT only when the REPORT command is used. A Select in a file without REPORT would then still not compile.

Run it together with those two functions, or after them. It does nothing when no Select is found, or when the definition is already there. In a file that already defines SELECT, for example one that uses the legacy REPORT command, the protected definition has no effect.

Strings, comments, blank lines and image sections are ignored, so a SQL SELECT in a string can never cause the definition to be added. Only the whole word is matched: Selected, Selection and Select_State are not.

Group: Modernization

Fixes compiler message(s): 4345


DropSurplusCallArguments

Removes the extra arguments at the end of an object method call, in the expression form Name(Self, args), when the call passes more arguments than the method declares.

DataFlex 19.1 and earlier accepted the extra arguments without checking, and the method never read them, so removing them changes nothing when the program runs. DataFlex 26 counts them and reports error 4379. Only the argument list is changed; the declaration is not.

Example: with fHeadValue declaring one parameter, 'Entry_Item (fheadvalue(Self, plandetail.ref, plandetail.porder))' becomes 'Entry_Item (fheadvalue(Self, plandetail.ref))'.

Not changed: a call whose extra argument contains another call (which could have side effects), a call that continues over several lines, and a call whose first argument is not Self. If the method was meant to receive the extra value, add the parameter by hand and do not run this function.

Group: Modernization


GuardAnsiExternalFunctionWithWide

Adds the wide ("...W") version of an ANSI ("...A") External_Function declaration next to it, with both inside one #IF version check, so that the same DataFlex name works in DataFlex versions before and after Unicode.

This is done only when DFRefactor's Win32 catalogue contains the wide version; its parameter types come from the Windows SDK. Calls to the function are not changed.

A declaration whose wide version is not in the catalogue is not changed. The wide name is never made by changing or removing the last letter, which would turn SetClipboardData into SetClipboardDatW. The wide version also uses different parameter types (LPCSTR becomes String, LPCWSTR becomes WString), so changing only the letter would compile, but pass the data in the wrong form.

Nothing is deleted: the original ANSI declaration is kept, and only the version check and the wide declaration are added around it.

When the target DataFlex already declares the same name itself (a second declaration is error 4390), a Use of that package is added instead of a wide declaration.

Group: x64 + Unicode


GuardDuplicateExternalFunctions

Puts the External_Function declarations in this file that the target DataFlex now declares itself inside an #IF (!@ <= version) check, so that the duplicate declaration is only compiled in older versions. This fixes error 4390, "already defined as an external_function", without changing any calls.

The change can be undone, and running it again changes nothing. A declaration that continues on the next line with ";" is protected as one block.

Group: Modernization

Fixes compiler message(s): 4390


GuardRedundantGlobalFunctions

Puts the global functions in this file that the target DataFlex now provides itself inside an #IF (!@ <= version) check, so that they are only compiled in older versions. This fixes the duplicate-global error 4390 without changing any calls.

The function is placed, unchanged and at its own indentation, between the version check and its #ENDIF. Nothing is deleted or rewritten; the change can be undone, and a function that already has the check is skipped when it runs again.

The "<=" includes the workspace's own version on purpose: that version must still compile its own copy, because the DataFlex function does not exist there (a "< 191" check would break a 19.1 application). If the version cannot be read, nothing is changed, rather than writing a wrong number into the source code.

Only top-level declarations with the GLOBAL keyword are changed, and only names that the target DataFlex itself includes. A method with the same name inside a class is not changed.

Caution: in the newer version, every call then uses DataFlex's own function, which can differ in code page, error handling or special cases. This is why the function is a suggestion to review, not an automatic fix.

Group: Modernization

Fixes compiler message(s): 4390


MakeFileAutonomous

Adds a 'Use <package>' for every class that a view, dialog, report, sort list, package or program creates objects of, so that the file does not depend on other files to compile.

Which package defines a class is read from the DataFlex installation and the workspace's own packages, never guessed from the class name.

The new Use lines are added after the last existing Use line, at the start of the line and without #IFDEF, so the order in which files are included does not change.

A class defined in the file itself needs no Use line. A class that is not found, or that is defined in more than one package (choosing the wrong one would compile the wrong code), is skipped, and the run summary names every class that was skipped.

Group: Modernization

Parameter: "ANY"

Default: vw;dg;rv;sl;pkg;src

The file extensions to act on, separated by ';' - leading dots optional; vw;dg;rv;sl;pkg;src - the default: views, dialogs, reports, lookup-lists, packages, programs, vw;dg - views and dialogs only.

A blank parameter falls back to the default. New Use lines land after the file's LAST existing Use, so the include order of everything already there is unchanged.

Fixes compiler message(s): 4345, 4328


RefactorBareGlobalsToGlobalVariable

Changes global variables that are declared with a plain command in a program file to Global_Variable declarations with the modern g-prefix names: 'String P_auto_login@ arg001' becomes 'Global_Variable String gsP_auto_login@ gsArg001', and every use in the file is renamed too (text in strings and comments is never changed).

A name that another file in the run uses without declaring it (a view, a report or a shared package) keeps its name, with a run note, because a new name would break that file.

The prefixes are String gs, Integer gi, Number gn, Date gd and Boolean gb. An existing one-letter type prefix is replaced (sCmdString becomes gsCmdString), and old size values (String arg1 1) are kept.

Only declarations at file level are changed. Local variables in procedures and functions, struct members, anything inside an object or class, existing Global_Variable lines, and a line that continues the line above it with ';' (such as a parameter of an External_Function on several lines) are not changed.

Group: Modernization


RefactorDbEditTocDbTextEdit

Converts dbEdit memo controls to cDbTextEdit. The class is changed on both 'Object ... is a dbEdit' and 'Class <sub> is a dbEdit' declarations, so the base class of a subclass is changed too.

Wrap_State becomes pbWrap in the converted object. Legacy properties without a modern equivalent (the scroll bar settings and Capslock_State) get a TODO comment for you to decide.

The function's parameter is 'OldEditClass,NewEditClass'. When it is empty, it is 'dbEdit,cDbTextEdit' plus the subclasses that the last Check found: their objects keep their class, whose base class is changed in its own file. 'dbEdit0,cDbTextEdit' converts the objects of that one subclass.

This is not only a change of class name, because the two classes come from different base classes (dbEdit from Edit and DfBaseEdit, cDbTextEdit from cTextEdit and DFBaseTextEdit). Only the properties they share are kept unchanged: Entry_Item, Server, Size and Location, the Label properties, Enabled_State, Read_Only_State, Value, Line_Count, peAnchors, Status_Help and the DEO verify_*_msg properties.

What differs: Wrap_State becomes pbWrap (not pbWordWrap), a text limit becomes piMaxChars, and the scroll bar settings and Capslock_State have no modern equivalent.

Group: Modernization

Parameter: "ANY"

Default: dbEdit,cDbTextEdit

Two comma separated class names;

MyDbEdit - dbEdit or a workspace subclass of it,

MycDbTextEdit - cDbTextEdit or a workspace subclass of it

Fixes compiler message(s): 4537


RefactorEditTocTextEdit

Converts the obsolete multi-line Edit control to cTextEdit. The class is changed on both 'Object ... is a Edit' and 'Class <sub> is a Edit' declarations, so the base class of a subclass is changed too.

Wrap_State becomes pbWrap in the converted object. Legacy properties without a modern equivalent (the scroll bar settings and Capslock_State) get a TODO comment.

Only the whole word Edit is matched, so a dbEdit object is never changed by this function; use RefactorDbEditTocDbTextEdit for those.

The function's parameter is 'OldEditClass,NewEditClass'. When it is empty, it is 'Edit,cTextEdit' plus the subclasses that the last Check found: their objects keep their class, whose base class is changed in its own file. 'MyEdit,cTextEdit' converts the objects of that one subclass.

Group: Modernization

Parameter: "ANY"

Default: Edit,cTextEdit

Two comma separated class names;

MyEdit - Edit or a workspace subclass of it,

MycTextEdit - cTextEdit or a workspace subclass of it

Fixes compiler message(s): 4537


RefactorWinReportTocWinReport2

Converts reports that use the obsolete WinPrint 1 class WinReport to the WinPrint 2 class cWinReport2. The class is changed on both 'Object ... is a WinReport' and 'Class <sub> is a WinReport' declarations; a subclass gets the new base class, and its objects keep the subclass name.

The obsolete 'Use Dfwinrpt.pkg' is replaced with 'Use cWinReport2.pkg', which also provides the WinPrint report commands (DFWriteLn, DFFont, headers, margins) and the WinPrintId global variable. This also fixes the errors that a WinPrint 1 view gets in a modern DataFlex, where Dfallrpt.pkg no longer includes WinPrint 1.

The function's parameter is 'OldReportClass,NewReportClass'; when it is empty, it is 'WinReport,cWinReport2'.

Group: Modernization

Parameter: "ANY"

Default: WinReport,cWinReport2

Two comma separated class names;

MyWinReport - WinReport or a workspace subclass of it,

MycWinReport2 - cWinReport2 or a workspace subclass of it

Fixes compiler message(s): 4537, 4345, 4328, 4298


RefactorWorkspaceTocApplication

Converts the legacy Workspace object (from Workspc.pkg, which modern DataFlex no longer includes) to a cApplication object, and adds the modern program structure around it.

'Object x is a Workspace' becomes 'Object x is a cApplication' (renamed to oApplication when nothing refers to it), and 'Set WorkspaceName' becomes 'Set psAutoOpenWorkspace to "<parameter>"'. Workspace properties without an equivalent are commented out with a TODO comment.

The obsolete Use Workspc.pkg, Use Std_Help.pkg, #REPLACE and Register_Object lines are commented out. The CodeJock menu bar packages, and the oHtmlHelp, peHelpType, oToolTipController and oCommandBarSystem objects, are added.

The AppClientArea client area becomes a ClientArea named oClientArea, and Use StdAbout.pkg is moved inside it, with an Activate_About procedure added.

Group: Modernization

Parameter: "ANY"

Default: Config.ws

The workspace config file for psAutoOpenWorkspace;

Config.ws - the DataFlex default,

MyApp.ws - a named workspace config file

Fixes compiler message(s): 4313, 4345, 4328


RemoveMultipleBlankLines

Removes consecutive blank lines when there are more of them than the number set in the function's parameter.

Group: Tidy Up

Parameter: 1, 2, 3, 4, 5, 6

Default: 2

Select max number of consecutive blank lines allowed in source files.


RemovePropertyPrivate

Removes the 'Private' keyword from Property declarations.

It is kept on a property that stores the value for a custom 'Procedure Set' or 'Function' with the same name, because there Private is needed to prevent a conflict with the custom method. The whole file is checked for such methods first.

Example: Property String pSel1 Private "" -> Property String pSel1 "" (the Private keyword goes).

Group: Modernization

Fixes compiler message(s): 4535


RemoveSelfFromObjectReferences

Removes (Self) from references to objects that are declared in the same file.

Example: Send Clear of (oCustomer_DD(Self)) -> Send Clear of (oCustomer_DD)

Only the names that the file declares with 'Object <name> is a' are changed, and only when no variable has the same name. Comments, strings, #COMMAND blocks and #HEADER sections are not changed.

Group: Tidy Up


RemoveUnusedLocals

Removes local variables that are declared but not used in procedures and functions.

Unused struct variables are not removed.

Files that contain #INCLUDE are skipped completely: an included file uses the same local variables as the file that includes it, so variables used there cannot be seen when one file at a time is scanned.

Group: Tidy Up


RenameCollidingClass

Renames a class that has the same name as a class that the newer DataFlex defines itself (error 4345, "should not be defined", on its Class line).

The Class declaration is renamed, and so is every "is a <Class>" (objects and subclasses), RefClass(<Class>) and "for <Class>" in the file. Nothing else that contains the word is changed.

Run it on all selected files, because references can be in any file. Set the parameter to OldName|NewName, or only OldName to add an X to the name.

Group: Modernization


RenameCollidingGlobalFunction

Renames a global function that has the same name as a function in the newer DataFlex (error 4390, where a version check cannot help).

The declaration, calls in expressions, and Get statements without 'of' are renamed. Get and Send ... OF <object> are never changed, because those call the class method that has the same name.

Set the parameter to OldName|NewName, or only OldName to add an X to the name. Run it on all selected files, because the calls can be in any file.

Group: Modernization


RenameSameNamedMethod

Renames a method that has the same name as an unrelated method with a different return type (error 4544), so that it gets a name of its own. Use this when giving them the same type would change what one of them returns (a function that returns text, changed to Integer, returns 0).

The function's parameter is OldName|NewName, or only OldName to add Text to the name.

The Function declaration (global or not), calls in expressions, and Get statements without 'of' are renamed in each file it runs on. Get and Send ... OF <object> are never changed.

Run it only on the file with the declaration that differs, as the guided Check does, so that the other declarations keep their names.

Group: Modernization


RetireOemTranslateState

Removes the obsolete Oem_Translate_State property (warning 4540: it has no effect in a Unicode DataFlex).

A "Set Oem_Translate_State ..." line is commented out, because nothing reads the property. A "Get ... to <var>" that is used by an If statement is commented out together with the whole If block, with a comment for you to review, because removing only the Get line would change the test so that the block always runs.

A Get line whose variable is also used elsewhere, whose If has an Else, or whose block cannot be determined is not changed, and is reported. Nothing is deleted; lines are only commented out.

Group: x64 + Unicode

Fixes compiler message(s): 4540


UnicodeBufferPairToString

Replaces the two-line buffer conversion from DataFlex 19.1, "Move (OemToUtf8Buffer((AddressOf(sVar)),(Length(sVar)))) to aBuf" followed by "Move aBuf to sVar", with the single line "Move (OemToUtf8(sVar)) to sVar". All four CharTranslate pairs are handled.

This removes the pointer, and the buffer that the old code never released.

The lines are changed only when both arguments name the same variable, the next line moves the buffer back to that variable, and the buffer is not used anywhere else.

Group: x64 + Unicode

Fixes compiler message(s): 4539


UnicodePointerToString

Unicode fix for compile error 4539, "Conversion from Pointer to String is not allowed, use PointerToString function".

Wraps the source of a plain "Move <pointer/address> to <string>" in PointerToString(). An Address source causes the same error, so it is handled too.

It also replaces the DataFlex 19.1 buffer call "Move (Utf8ToOemBuffer(sVar)) to sVar" with the version that returns a String (Utf8ToOem and the other three CharTranslate pairs).

Examples:

  • Move aBuf to sResult becomes Move (PointerToString(aBuf)) to sResult
  • Move (Utf8ToOemBuffer(sLine)) to sLine becomes Move (Utf8ToOem(sLine)) to sLine

A Move is changed only when the source is declared as a Pointer or Address and the destination as a String, in the same method. A buffer call is changed only when it has one argument, and both that argument and the destination are declared as Strings or String parameters. A line where the types cannot be determined from the declarations is not changed: a missed line does no harm, but a wrong change would.

A buffer call with two arguments (AddressOf and a length, which uses pointers on purpose) is never changed, and needs a manual migration.

Group: x64 + Unicode

Fixes compiler message(s): 4539


UnicodeStringToPointer

Unicode fix for compile error 4539, in the direction String to Pointer: changes a plain "Move <string> to <pointer>" into a call to MemCopy().

A line is changed only when the types of both variables are known from the declarations or parameters.

Before: Move <string var> to <pointer var>

After: Move (MemCopy(<ptr>, AddressOf(<str>), SizeOfString(<str>))) to iRFVoid

An Integer variable, iRFVoid, which receives the return value of MemCopy, is declared once in each method that needs it.

The number of bytes is calculated with SizeOfString, so the encoding is taken into account. The buffer's own ResizeArray line is not changed.

Group: x64 + Unicode

Fixes compiler message(s): 4539


Win64IntegerToLongPtr

64-bit fix for compile error 4539: a local Integer or DWord variable that holds a pointer becomes a LongPtr, as the compiler's message advises: "use Longptr instead of Integer".

Before: Integer iAddr

Move (AddressOf(sBuffer)) to iAddr

After: LongPtr iAddr

Move (AddressOf(sBuffer)) to iAddr

The source can be AddressOf() or a variable declared as Pointer or Address. When a declaration names several variables, the others keep their type, and a LongPtr line for the changed ones is added after it.

Only a variable declared in the same method gets the new type. A parameter, a global variable, a property, or a variable passed ByRef (&iAddr) is not changed; Win64PointerTruncation lists them for a manual fix. Only the plain form "Move <source> to <variable>" is recognised.

A LongPtr can be used everywhere the Integer was used: in calculations, Move statements, parameters and comparisons.

Group: x64 + Unicode

Fixes compiler message(s): 4539