Suppress false positive warning for retriggering a Windows timer - code-analysis

I wish to retrigger a Windows timer using a VCL6 TTimer object. I'm doing this by toggling the Enabled property, this of course can be confusing, but I added a comment about this. For Cppcheck I added a comment as well in its language:
m_pTimer->Enabled = false;
// die "doppelte Zuweisung" sorgt für einen Neustart des Timers
// cppcheck-suppress redundantAssignment
m_pTimer->Enabled = true;
...but it obviously doesn't help, I still see this style warning:
Variable 'Enabled' is reassigned a value before the old one has been used.
What am I doing wrong?

For the command line version inline suppressions must be enabled through the command line switch --inline-suppr. For details refer to the manual.
For the GUI version you have to activate inline suppressions through the preferences dialog (Menu Edit->Preferences, tab General, Enable inline suppressions).

Related

Change text by Command with VS-Code-Extension

I want to implement a second code formatting. This formatting should be executable by an additional command.
I have already registered a DocumentFormattingEditProvider and that is fine.
vscode.languages.registerDocumentFormattingEditProvider({ language: 'sosse' }, {
provideDocumentFormattingEdits(document: vscode.TextDocument) {
return formattingAction(document);
},
});
But in my case I need a second formatting action for one-liners, which is executed by an command.
I thought about using:
vscode.commands.registerCommand(command, callback)
But I don't know how to access and change the document.
But I don't know how to access and change the document.
There's a special variant of registerCommand() that I think is exactly what you're looking for: registerTextEditorCommand(). From the API docs:
Text editor commands are different from ordinary commands as they only execute when there is an active editor when the command is called. Also, the command handler of an editor command has access to the active editor and to an edit-builder.
That means the callback gets passed an instance of a TextEditor as well as a TextEditorEdit.

PyDev custom code complete plug-in only detects every other key stroke

I have an Eclipse plug-in that I created to add Code Completion entries. I configured Eclipse to automatically show code completion as I type (Windows | Preferences | PyDev | Editor | Code Completion | Request completion on all letter chars and '_'?). At first when I typed I kept getting the templates showing instead of my code completion entries, so I removed all the templates ( Windows | Preferences | PyDev | Templates --selected all, then "Remove"). Now when I type it works properly for every other key pressed. For example, when I type 'print', the code completion list drops down with my entries as expected when I press 'p'. However, when I press 'r', the list disappears. When I press 'i' the list shows again, but disappears when I press the next key ('n'), etc. Is this a Pydev defect, or am I doing something wrong? It works fine for the templates and other default code completion, just not for my plug-in. Here is a code snipped of a watered down version of my code:
//...
public class MyPlugin implements IPyDevCompletionParticipant
#Override
public Collection<Object> getGlobalCompletions(CompletionRequest arg0,
ICompletionState arg1) throws MisconfigurationException {
String replacementString = "{" + arg0.qualifier + "}";
int replacementOffset = arg0.documentOffset - arg0.qlen;
int replacementLength = arg0.qlen;
int cursorPosition = arg0.documentOffset;
String displayString = arg0.qualifier;
final IContextInformation contextInformation = new ContextInformation(
"displayStr", "message");
String additionalProposalInfo = "additionalProposalInfo";
final String bundle = "com.github.EclipseChameleonPlugins";
final org.eclipse.swt.graphics.Image image = new org.eclipse.swt.graphics.Image(getDisplay(), locateFile(bundle, "icons/smiley.gif").getPath());
arg0.showTemplates = false;
final CompletionProposal proposal = new CompletionProposal(
replacementString, replacementOffset, replacementLength,
cursorPosition, image, displayString, contextInformation, additionalProposalInfo);
List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
// ADD IT...
proposals.add(proposal);
final Collection<Object> returnProposals = new ArrayList<Object>(
proposals);
return returnProposals;
}
I have searched Google and StackOverflow, and have seen very little about code development for PyDev plug-ins, and nothing that mentions or addresses this issue.
Here are a few of the links I have looked at, but none have answered my question:
Auto-completion in PyDev
Code completion for custom modules not working with PyDev
pydev remote debuging - code completion in interactive console?
Well, plain PyDev behaves as expected for me (i.e.: the code completions appear on all the key strokes).
Now, let's see if we can track it down a bit better:
instead of removing the templates, what you should do is go to the preferences > pydev > editor > code completion (ctx insensitive and common tokens) and disable the 'use common tokens auto code completion?'.
The reference code for you to follow is: com.python.pydev.codecompletion.participant.ImportsCompletionParticipant and com.python.pydev.codecompletion.ctxinsensitive.CtxParticipant (i.e.: the IPyDevCompletionParticipant interface -- as you're doing already)
I think the main issue you're having is because you're not implementing the additional extensions for completions (to validate its context and keep it there) -- either you can make your own subclass of org.python.pydev.editor.codecompletion.AbstractPyCompletionProposalExtension2 or you can use org.python.pydev.editor.codecompletion.PyLinkedModeCompletionProposal (just constructing it with the proper parameters -- I believe it supports having a null IToken -- and you can pass an image to it which will be used if the token is null).
You should probably not mess with the CompletionRequest at that point (when it gets there to an extension it should be considered immutable -- even if it's not in reality).

Elm Graphics.Input

I'm trying to run the Elm input examples from this page. Specifically, the Text Field example, and I'm getting an error saying that the Graphics.Input module is missing.
I've got this in a file called Main.elm:
import Graphics.Input as Input
main = let (field, state) = Input.field "Type here!"
in lift2 display field state
display field state =
field `above` asText state
If I run elm-server and navigate to localhost:8000, I get the error
Your browser may not be supported. Are you using a modern browser?
Runtime Error in Main module:
Error: Module 'Graphics.Input' is missing. Compile with --make flag or load missing module in a separate JavaScript file.
The problem may stem from an improper usage of:
Input.field, above
Compiling the project with elm --make Main.elm gives me
elm: Graphics/Input.elm: openFile: does not exist (No such file or directory)
Is there something extra I need to do to install the Graphic.Input?
Additional Notes:
I'm running this on a Debian machine, and installed it using cabal install elm fairly recently (Jun 15 2013). The current version is labeled Elm-0.7.1.1.
If I hop into the chromium JS prompt and poke around, it turns out there's no Elm.Graphics.Input module, but there is an Elm.Input. There isn't a function called field, there's a similar looking one called textField, but it isn't trivially interchangeable.
Running this:
import Input
main = let (field, state) = textField "Type here!"
in lift2 display field state
display field state =
field `above` asText state
gives me the error
Your browser may not be supported. Are you using a modern browser?
Runtime Error in Main module:
TypeError: a is undefined
The problem may stem from an improper usage of:
above
The Graphics.Input package is new in version 0.8. So, since you're running version 0.7, that explains your problem.
0.8 was released somewhat recently, but it's definitely been out longer than June 15th, so you probably just forgot to cabal update before installing it. Running cabal update now and then updating elm to 0.8 should fix your issue.

How can I get stacktrace for Adobe AIR global runtime errors in non-debug mode?

The new version AIR gives us the ability to globally capture run time errors and handle them. The problem is that it doesn't have the stacktrace or any helpful information about the error other than the error id and error message and name. For example it may tell me that a null pointer exception has happened but it will not tell me where or which method or anything. The debug version of the runtime gives us all of that but when the app is deployed to customers it is not running on the debug version so none of the useful information is available. I was wondering if this group has any suggestions on how to enable better logging of errors in an AIR app for better supportability of the product. Any suggestions?
I have a little hack to get line numbers too. :)
make a listener to get uncaught errors. I do it in my main class:
private function addedToStageHandler(event:Event):void {
loaderInfo.uncaughtErrorEvents.addEventListener( UncaughtErrorEvent.UNCAUGHT_ERROR, uncaughtErrorHandler );
}
for example my listener with error.getStackTrace():
private function uncaughtErrorHandler( event:UncaughtErrorEvent ):void
{
var errorText:String;
var stack:String;
if( event.error is Error )
{
errorText = (event.error as Error).message;
stack = (event.error as Error).getStackTrace();
if(stack != null){
errorText += stack;
}
} else if( event.error is ErrorEvent )
{
errorText = (event.error as ErrorEvent).text;
} else
{
errorText = event.text;
}
event.preventDefault();
Alert.show( errorText + " " + event.error, "Error" );
}
Add additional compiler argument: -compiler.verbose-stacktraces=true
Create the release build.
now the little hack:
Mac:
Go to the installation location where you have your .app file. Right click and choose show package content. Navigate to Contents ▸ Resources ▸ META-INF ▸ AIR. There you can find a file called hash. Duplicate the hash file and rename it to debug. Open the debug file with some text editor and remove the content. Done now you get the stack trace + line numbers.
Windows:
Browse to its install directory in a file explorer. Navigate to {app-folder}▸META-INF▸AIR▸. Here you can find a file called hash. Duplicate the hash file and rename it to debug. Open the debug file with some text editor and remove the content. Done now you get the stack trace + line numbers.
If you can't find the hash file, just create an empty file without file extension and call it debug.
Tested with Air 3.6!
No way until new version of AIR supports it. It doesn't now because of performance issues, rendering global handler almost useless. I'm waiting for it too, because alternative is logging everything yourself, and this is very time consuming.
The compiler option:
compiler.verbose-stacktraces=true
should embed stack information even in a non-debug build.
About the compiler option.
I develop with IntelliJ IDEA 14. In my build options i have also "Generate debuggable SWF". Maybe thats the reason why its working. Check my attachment.
Grettings

Crystal reports 11 RDC (COM API) displays printer dialog even when I tell it not to prompt

I'm using Crystal Reports 11's RDC (COM) API to print. My code looks like this:
HRESULT res = m_Report->SelectPrinter(b_driver, b_device, b_port);
if (FAILED(res)) return res;
// For these calls, the #import wrapper throws on error
m_Report->PutPrinterDuplex(dmDuplex);
m_Report->PutPaperSize(dmPaperSize);
m_Report->PutPaperSource((CRPaperSource)pdlg->GetDevMode()->dmDefaultSource);
if (m_Report->GetPaperOrientation() == crDefaultPaperOrientation)
m_Report->PutPaperOrientation(crPortrait);
VARIANT vfalse;
VariantInit(&vfalse);
vfalse.vt=VT_BOOL;
vfalse.boolVal=0;
res = m_Report->PrintOut(vfalse);
However, at the end of all this, crystal reports still shows its own printer selection dialog - but only for some reports, it seems. Why does crystal reports show a print dialog even when I pass false for promptUser? And how, then, can I suppress crystal reports' internal printer selection dialog and force it to use my values?
Edit: Whoops, CR11, not CR9.
Some further information:
The reports that work properly (ie, do not show the print dialog) are generated internally using the RDC API; we create a new report object, import subreports into it, then print the result. No problem there.
The reports that do not work properly (ie, force the print dialog to open) have been created with a previous version of crystal reports; however, opening and saving the report does not seem to help.
Sample reports in the Crystal Reports installation directory show the same problem.
I tried reproducing with VBScript; however, the result was that nothing was printed at all (no dialog, no nothing):
Set app = CreateObject("CrystalRuntime.Application.11")
Set report = app.OpenReport("C:\Program Files\Business Objects\Crystal Reports 11.5\Samples\en\Reports\General Business\Inventory Crosstab.rpt")
report.PrintOut(True)
rem Testing with a True parameter to force a print dialog - but no printout and nothing appears (no error either though)
First, let me preface that I'm not a C/C++ programmer, so I'm not able to test the code--my interaction w/ the SDK has been with the VB and .Net interface over the years.
I found the following code from BO's devlibrary:
// A dummy variant
VariantInit (&dummy);
dummy.vt = VT_EMPTY;
HRESULT hr = S_OK;
// Specify the path to the report you want to print
_bstr_t ReportPath("c:\\Program Files\\Business Objects\\Crystal Reports 11.5\\Samples\\En\\Reports\\General Business\\Inventory.rpt");
_variant_t vtEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR);
// Instantiate the IApplication object
m_Application.CreateInstance("CrystalRuntime.Application.115");
//Open the Report using the OpenReport method
m_Report = m_Application->OpenReport(ReportPath, dummy)
//Print the Report to printer
m_Report->PrintOut(dummy, dummy, dummy, dummy);
Does it work? It should print the report with its 'default' printer settings and without prompting.
You wrote:
However, at the end of all this,
crystal reports still shows its own
printer selection dialog - but only
for some reports, it seems.
Generally speaking, I've found that Crystal tends to ignore commands to suppress dialogs if it thinks something is missing. I've found this to be true with the parameter dialog. Perhaps it apply to this situation as well. I would ask what is different about the reports that cause the dialog to be generated. There is a 'no printer' option that can be set. Perhaps this is the common thread.
Do you have access to the VB6 IDE? If you write the equivalent commands using VB6's interface, does the prompting occur?
You might also investigate using the CRPE32.dll instead of the report-designer control. To be honest, I don't know if the RDC wraps the CRPE DLL or is an entirely-separate code base.
Turns out it was a bug in my code after all - I'd previously put in a wrapper for the RDC API to fix certain other bugs we were having; due to the large number of methods in the IReport interfaces, I wrote a script to generate pass-through stubs for the methods I wasn't interested in. Turns out that script was passing in bogus values for parameters with default values. Oops! Fixing the wrapper code fixed the bug here.