Difference between revisions of "FpDebug-Watches-Intrinsic-Functions"

From Lazarus wiki
Jump to navigationJump to search
Line 29: Line 29:
  
 
= CC(instance) {ChildClass} =
 
= CC(instance) {ChildClass} =
 +
 +
Type-casts an object (class instance) to the instantiated class type.
 +
 +
 +
E.g. "Sender: TObject" is by default evaluated as TObject. ":CC(Sender)" will find the actual class of the instance and the result will be e.g. a TButton or TForm.
 +
":CC(Sender)" is the same as either writing "TForm(Sender)" or "TButton(Sender)", but automatically adapts to the correct type.
 +
 +
 +
Simply watching ":CC(Sender)" returns the same result as checking the "Use instance class" checkbox in the watches properties.
 +
 +
The difference between ":CC()" and "Use instance class" is
 +
* "Use instance class" will not allow you to write "Sender.FOwner"
 +
* The intrinsic can be used: ":CC(Sender).FOwner"
 +
: The "Use instance class" checkbox can then be used on the result of ":CC(Sender).FOwner"
 +
* ":CC()" can be nested: ":CC(:CC(Sender).FOwner).FHint"
 +
 +
 +
":CC()" takes exactly one argument. If the argument is not an object, or can not be typecasted, then it is passed through. E.g. ":CC(1)" just return "1".

Revision as of 12:21, 9 September 2022

About

LazDebuggerFp has some build in helper functions. They can be included in any watch using the pascal function calling syntax. The result is calculated internally be the debugger.

To avoid clashed with identifier names in the debugged target app, such intrinsic functions require a ":" prefix by default. E.g. ":length(s)".

Settings

The prefix can be chosen or switched off. In the property grid of the debugger backend setup the option "IntrinsicPrefix" can be found.

  • ipColon
    Require a ":" as prefix
  • ipExclamation
    Require a "!" as prefix
  • ipNoPrefix
    Don't require a prefix.
    If function calling is enabled for the watch, the intrinsic takes precedence, and may hide a call-able function in the target app. (Use the & to bypass the intrinsic and trigger function eval. E.g.: "&length()")

Length(String-or-array)

Returns the length of an array or string.

See FpDebug#Strings_(vs_PChar_and_Array_of_Char) for info about string types in the debugger.


CC(instance) {ChildClass}

Type-casts an object (class instance) to the instantiated class type.


E.g. "Sender: TObject" is by default evaluated as TObject. ":CC(Sender)" will find the actual class of the instance and the result will be e.g. a TButton or TForm. ":CC(Sender)" is the same as either writing "TForm(Sender)" or "TButton(Sender)", but automatically adapts to the correct type.


Simply watching ":CC(Sender)" returns the same result as checking the "Use instance class" checkbox in the watches properties.

The difference between ":CC()" and "Use instance class" is

  • "Use instance class" will not allow you to write "Sender.FOwner"
  • The intrinsic can be used: ":CC(Sender).FOwner"
The "Use instance class" checkbox can then be used on the result of ":CC(Sender).FOwner"
  • ":CC()" can be nested: ":CC(:CC(Sender).FOwner).FHint"


":CC()" takes exactly one argument. If the argument is not an object, or can not be typecasted, then it is passed through. E.g. ":CC(1)" just return "1".