Regular Expression Search in Visual Studio 2010 - regex

I'm not sure if this is possible within VS, but I'm working with a massive VB.NET file that needs to log every function call for debug purposes. Problem is, that not every function has the Log command in it. I'm trying to use RegEx to find the function definitions that do not have a log within them.
This would NOT be a match:
Public Function Test1() as Boolean
Log.Tracelog("Test1()")
Return True
End Function
This WOULD be a match:
Public Function Test2() as Boolean
Return False
End Function
The closest I've come is using the following:
(function|sub|property) .*\n.*~(Log\.t)
In my own mind, it should work, but no matter how I word it, it's still pulling every function as a match, even those that have the "Log.Tracelog" call in the function.
Is there anyway I can search to find the latter case?

Try this:
(function|sub|property) .*\n~(.*Log\.t)
I moved .* from just before the ~() (preventmatch) to just inside it.

Why not use the debug.WriteLine methods for the functions you want logged. You can also use the stack to get the method name:
Private Function test1() As Boolean
Debug.WriteLine(New System.Diagnostics.StackTrace().GetFrame(0).GetMethod.Name)
Return False
End Function
Then the messages only output when debugging and only in the methods you want.

Related

why vba can't successfully call dll that's written in c++?

I got a c++ demo that has successfully called the API written in c++, now am trying to call those API from excel VBA. I've done quite a bit research but still not able to link them together.
Basically there's a API(TapQuoteAPI.dll) export function like this in demo
'TapQuote.h
TAP_DLLEXPORT const TAPICHAR *TAP_CDECL GetTapQuoteAPIVersion();
in demo c++ solution(TapQuoteAPI_Demo), i include the 'TapQuote.h' in demo.cpp,
the cout<<GetTapQuoteAPIVersion()<<endl; is successfully called, and result is print.
but when it comes to call this function in excel vba, i keep failing.
I tried to directly use the TapQuoteAPI.dll in excel like this, but not working.
Declare Function GetTapQuoteAPIVersion Lib "D:\Proejct\WIN32\TapQuoteAPI.dll" () As String
Then I also try to build another dll function with a deFile.def from TapQuoteAPI_Demo.dll since i successfully call it within the c++ demo.
Declare Function GetTapQuoteAPIVersion Lib "D:\Proejct\WIN32\TapQuoteAPI_demo.dll" () As String
also failed.
Could anyone shed some lights for me please?

Calling an xll UDF from VBA

I would like to call one of my User Defined Function from VBA.
My User Defined Function is declared in C++:
XLOPER12*WINAPI HelloWorld()noexcept{
THROWS();
static XLOPER12 res=[](){
static std::array<wchar_t,13>str={
11,'H','e','l','l','o',' ','W','o','r','l','d','\0'};
XLOPER12 tmp;
tmp.xltype=xltypeStr;
tmp.val.str=str.data();
return tmp;}();
return &res;}
This is a simplified version of a real function from the field which can either return a String or a double or even arrays. Of course here I am only returning a String but this limit the return type of my UDF to LPXLOPER12.
I can successfully register my function with xlfRegister specifying a pxTypeText of "U$". I can then call my UDF from Excel:
=HelloWorld()
And it works!
If I try to call my function from VBA as suggested here:
Sub macro_test()
Dim hw As Variant
hw = Application.Run("D:\Path\MyAddIn.xll!HelloWorld")
End Sub
I get an error message from Application.run:
Run-time error '1004': Application-defined or object-defined error
If I try to call my function from VBA as suggested here:
Private Declare PtrSafe Function HelloWorld Lib "C:\Path\MyAddIn.xll" () As Variant
Sub macro_test()
Dim hw As Variant
hw = HelloWorld()
End Sub
I get an empty result instead of "Hello World".
What am I doing wrong ?
Miscellaneous pieces of information:
Using Excel 2013
Using VS 2017 15.5
Using the first method (Application.Run), VBA does not call my function (I cannot step into my function with the debugger).
Using the second method, VBA calls my function (I can step into my function with the debugger).
Using the second method, when I add xlbitDLLFree to my xltype, function xlAutoFree12 is not called, which makes me think that somehow the return value is not understood properly by VBA.
If your XLL is loaded and its UDFs are registered so that=HelloWord() in a cell works then you should just be able to call it from VBA like this (unless there is a problem with parameterless string functions)
var=Application.run("HelloWorld")
You can also use Evaluate
var=Application.Evaluate("=HelloWorld()")
I tested my REVERSE.TEXT XLL function like this and it worked correctly.
Sub testing()
Dim var As Variant
var = Application.Run("REVERSE.TEXT", "Charles")
var = Application.Evaluate("=REVERSE.TEXT(""Charles"")")
End Sub
Reverse.Text is registered using UQQ$ (there are 2 parameters , the Text and the Number of characters)

ActionListener Expression value for RichButton in ADF

We have a business need to collect specific bindings in every JSF page. and we do that inside overridden ViewHandlerWrapper class
I use the below code inside renderView method to get the whole expression value property for every RichInputText and it's work fine for me
ValueExpression valExp = Inputcomponent.getValueExpression("value");
String ExpressionString = valExp.getExpressionString();
output was: #{binding.EmployeeId.inputValue}
When I do the same against RichButtin I got null value as following:
ValueExpression valExp = Btncomponent.getValueExpression("actionlistener");
String ExpressionString = valExp.getExpressionString();
What is the wrong in my last peace of code?
Obtaining a ValueExpression form a RichInputText works because, as the name suggests, it evaluates to a value, which may or may not be an EL expression, let alone a method.
On the other hand, a RichButton does not really have to evaluate to something; rather, it aims to invoke behavior (i.e. a method), from which you would want a MethodExpression - though in this case, the closest we get to it is a MethodBinding.
Luckily, UIXCommand, a superclass of RichButton, provides two methods from which you can obtain your action listeners:
public final MethodBinding getActionListener()
From the MethodBinding returned, you can invoke getExpressionString() so you can get what you wanted - such as some actionListener EL string like #{binding.bean.actionListenerMethod}.
public final ActionListener[] getActionListeners()
Might be worth mentioning, though there is not much merit for this in your use case. It simply returns the listeners on which you can manually process the events.

Delphi 10.1 - Wrong Match.Value in TMatchEvaluator when calling TRegEx.Replace()

I've found one bug with latest Delphi 10.1 Berlin (and in 10.2 Tokyo too).
If you call TRegEx.Replace with TMatchEvaluator specified, you may got wrong TMatch inside Evaluator function. In Delphi XE-XE5 it seems works good.
Evaluator:
function TForm1.EvaluatorU(const Match: TMatch): string;
var
lChar: Word;
lMatchVal: string;
begin
Result := '';
lMatchVal := Match.Groups[1].Value;
lChar := StrToIntDef('$'+lMatchVal, 0);
if lChar <> 0 then
Result := Char(lChar);
end;
Call:
Result := TRegEx.Replace('\u0418\u0443, \u0427\u0436\u044d\u0446\u0437\u044f\u043d', '\\u([0-9a-f]{4})', EvaluatorU, [roIgnoreCase]);
First call of Evaluator will bring right TMatch.Value (or TMatch.Group[].Value) context, but second call will bring wrong Match.Value to callback function(
Do you have some idea about workaround?
I going to check this issue on TPerlRegEx class, maybe something wrong is in wrapper (TRegEx) functions.
Update: with TPerlRegEx Replacement with callback function (OnReplace) works good...
Update2: it seems there is a bug in TPerlRegEx. It returns wrong GroupOffsets. On First call of OnReplace callback this value is correct. Next calls returns +1 offset more than needed. But call of TPerlRegEx.Groups returns correct subgroup value...
Last update and solution found:
I've found a problem in TPerlRegEx.UTF8IndexToUnicode function optimization.
There are LastIndex*/LastIndexResult* fields used to optimize sequential call of function with same params. But after replacement made via callback functions and when MatchAgain is called into TPerlRegEx.ReplaceAll function, this can make a bad trick(
Simple solution is copy System.RegularExpressionsCore.pas from \source\rtl\common to your project directory and replace call of TPerlRegEx.UTF8IndexToUnicode to deprecated unoptimized UTF8IndexToUnicode function... Or clear this internal fields somewhere in ClearStoredGroups function for example.
upd. Here is my embarcadero quality central issue.

Lua: Redirect extern function definitions to a specified table

I have one file "example.lua":
local function manipulate(something)
return string.rep(something, 3) -- repeats the given string
end
function apiFunction(somethingelse)
return manipulate(somethingelse)
end
and another files (main.lua) task is to "load"/"do" it:
loadAPI("example.lua", "externAPI") --< the part i need help with
externAPI.apiFunction("Test") --> should return TestTestTest
the thing that should happen is, that example.lua gets executed just like
dofile("example.lua")
but everything globally "defined" within example.lua (in this case the apiFunction) moves to the new generated global "externAPI" table and the rest (ie. manipulate) is hidden and only available from inside the example.lua file.
I've seen this bahaviour before in the minecraft mod "ComputerCraft" in which there is a function called "os.loadAPI("/somepath/sha-2") and it would define the definitions in the sha-2-chunk in the due to the name specified "sha-2"-table.
I've been searching for this sort of scoping/redirecting stuff for a while but there are no solutions putting the stuff into the new table.
I've been thinking of parsing the _G table after new indexes and move those to the new table but I'm sure there are some lua-magicians out here that know a much cleaner, better working solution to this.
All this is in one C lua_state* , so if there are any solutions adding this loadAPI function in C/C++ and just registrating it at the state this would be fine, too.
I've also looked at "require", but didn't seem to understand whether it does what I need.
Using Lua 5.2.3
Hope i didn't forget anything.
Thanks in advance :)
~InDieTasten
Try this:
function loadAPI(f,g)
_G[g]=setmetatable({},{__index=_G})
loadfile(f,"bt",_G[g])()
end
loadAPI("example.lua", "externAPI")
print(externAPI.apiFunction("Test"))