I have a strange behavior when debugging in Visual Studio 2017 with the preview of variables, if a variable-name is used more than ones, in different scopes.
Here is a simple sample:
private void Test()
{
var values = new List<int> {1, 2, 3, 4, 5, 6, 7, 8};
if (values.Count > 20)
{
var a = 0;
a = values[5];
}
else
{
var a = 0;
a = values[5];
}
}
The bebugger preview told me, that "a" in the second scope is zero.
If i change the variable in the bottom scope to "b" everything works fine...
Is that the normal behavior of the debugger? Cant remember...
Seems like Fody caused this behavior. After deinstalling Fody, the debugger works as expected!
Fody (Version 1.29.4) / PropertyChanged.Fody (Version 1.52.1)
Related
I know the method getIndex() was introduced in version 4.5 but we are currently unable to update our CKEditor version as it is tied to an enterprise software package. Is there a way to mimic the getIndex() function in CKEditor versions prior to version 4.5?
If you are referring to CKEDITOR.tools.getIndex(), you can just use JavaScript's own Array.prototype.findIndex() (not for Internet Explorer though):
function isBigEnough(element) {
return element >= 15;
}
[12, 5, 8, 130, 44].findIndex(isBigEnough);
// index of 4th element in the Array is returned,
// so this will result in '3'
I've noticed that Qt's Q_FOREACH macro doesn't play well with certain features of Visual Studio:
IntelliSense detects it as a function declaration: every Q_FOREACH is displayed as a function/method in the class viewer. Fortunately this answer solves that problem.
Code formatting also detects it as a function declaration (Edit > Advanced > Format Document). For example, for my current format style:
void foo() {
Q_FOREACH (auto action, actions){ (action);
}
for (int i = 0; i < 10; ++i) { (i);
}
}
is formatted as
void foo()
{
Q_FOREACH(auto action, actions)
{
(action);
}
for (int i = 0; i < 10; ++i) {
(i);
}
}
instead of
void foo()
{
Q_FOREACH (auto action, actions) {
(action);
}
for (int i = 0; i < 10; ++i) {
(i);
}
}
Is there any way to fix it? The cpp.hint hint used to solve the first problem related to IntelliSense is already applied and hasn't helped with the format.
PS: I'm working with Visual Studio Professional 2017 and using Visual Studio Add-in 2.1.1 for 2017 (beta 10.03.2017, downloaded from https://download.qt.io/development_releases/vsaddin/).
Update: To give some additional context, we've just started the migration from VS 2010 to VS 2017. Currently we've only migrated the IDE, toolsets are still on 2010, where the natural replacement, the C++11 range-for, is not available for that version of the C++ compiler.
Up to know, some of the members of the team have been using AStyle (and its VS plugin) for code formatting, which deals with this situation (and other Qt related things) in a more or less acceptable fashion. I began to study the possibility of migrating to the native code formatter and found this, that's why I posted this question.
Related questions that haven't solved my problem:
Broken indentation for Qt-specific constructions in Visual Studio
Yes. The fix is very simple: don't use that macro. It's unnecessary. Use range-for instead. You want to write:
void foo()
{
for (auto action : actions)
action->doSomething();
}
I recently updated to Xcode 7, beta 3.
And I've run into some issues, I can't seem to find any questions for on SO.
When I run my application, i get 3 errors:
Use of unresolved identifier 'kCGBlendModeMultiply'
Use of unresolved identifier 'kCGLineCapRound'
Use of unresolved identifier 'kCGLineJoinMiter'
However the 2 latter ones, disappear, although I assume they will show up after the first one is fixed (hence why I included it in this question).
I didn't see anything in the release notes about these being removed? So I'm a bit stuck at what to do. I tried rewriting the lines of course, but the 3 things I used don't show up as options anymore. In case that they are just gone in the latest Swift 2.0, what can I use instead?
Here's the code for the first error.
func alpha(value:CGFloat)->UIImage
{
UIGraphicsBeginImageContextWithOptions(self.size, false, 0.0)
let ctx = UIGraphicsGetCurrentContext()
let area = CGRect(x: 0, y: 0, width: self.size.width, height: self.size.height)
CGContextScaleCTM(ctx, 1, -1);
CGContextTranslateCTM(ctx, 0, -area.size.height)
CGContextSetBlendMode(ctx, kCGBlendModeMultiply)
CGContextSetAlpha(ctx, value)
CGContextDrawImage(ctx, area, self.CGImage)
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return newImage;
}
Here's the code for the 2 latter errors:
for layer in [ self.top, self.middle, self.bottom ] {
layer.fillColor = nil
layer.strokeColor = UIColor.whiteColor().CGColor
layer.lineWidth = 4
layer.miterLimit = 4
layer.lineCap = kCALineCapRound
layer.masksToBounds = true
let strokingPath = CGPathCreateCopyByStrokingPath(layer.path, nil, 4, kCGLineCapRound, kCGLineJoinMiter, 4)
layer.bounds = CGPathGetPathBoundingBox(strokingPath)
layer.actions = [
"strokeStart": NSNull(),
"strokeEnd": NSNull(),
"transform": NSNull()
]
self.layer.addSublayer(layer)
}
Any help would be greatly appreciated! :)
This should work:
CGContextSetBlendMode(ctx, CGBlendMode.Multiply)
... or even just this:
CGContextSetBlendMode(ctx, .Multiply)
If you Ctrl-click on CGContextSetBlendMode and then from its declaration jump (in the same way) to declaration of CGBlendMode then you will see:
enum CGBlendMode : Int32 {
/* Available in Mac OS X 10.4 & later. */
case Normal
case Multiply
case Screen
case Overlay
// ...
}
Similarly, the other line that produces the error should be changed to:
let strokingPath = CGPathCreateCopyByStrokingPath(layer.path, nil, 4, .Round, .Miter, 4)
I am a complete beginner in coding. I managed to get some working code in Playground but once I moved to building a project nothing worked.
This is for OS X.
I have used the following simple lines of code in Playground and AppDelegate contexts. It runs and outputs to the console without error in Playground but returns an error in AppDelegate.swift - Expected declaration for the " for num in availcrop" line with a red arrow under the f in for.
var availcrop = [0, 1, 2, 3, 4, 5, 6, 7]
for num in availcrop
{
var ran = 1000+randInt(2000)
availcrop[num] = ran
println(availcrop[num])
}
- the println is not planned for the project. Just in the Playground for testing
Both have imported Cocoa. One runs and the other crashes. In Playground the array name avail crop is blue implying it is recognised I suppose. In the AppDelegate.swift it remains grey.
Once you're dealing with classes and objects, code generally needs to be inside some method so that it can be invoked by name.
Try:
func printRandoms {
// Your code here
}
The bottom of the page is truncated when printed. (Approx 1/2 to 1").
This printing problem does not seem to be specific to Flash (printing certain PDFs also yields this problem), but that is where we found it.
The problem does not occur in older versions of OS X, but does occur in the most recent versions (10.5.5 and up). Not sure where the line is. The same application on Windows works fine.
It happens in Safari and Firefox.
Our Flash CS3 (AS2) application uses the PrintJob object to send pages to the printer. The pages are supposed to be letter-sized. On Windows they are letter-sized and print fine. But on the Mac, the pages are truncated. When the browser Print dialog comes up, if you change paper size to A4, the document prints fine. IT IS NOT SUPPOSED TO BE A4.
What is going on?
Here is a fraction of our printing code:
private function runPagePrintJob(pages:Array):Void {
var pj:PrintJob = new PrintJob();
if (pj.start()) {
var paperHeight:Number = this.pointsToPixels(pj.pageHeight);
var paperWidth:Number = this.pointsToPixels(pj.pageWidth);
for (var i:Number=0; i<pages.length; i++) {
var mc:PrintablePage = pages[i];
var xScale:Number = paperWidth / mc._width;
var yScale:Number = paperHeight / mc._height;
if ((xScale < 1) || (yScale < 1)) {
mc.setScale(Math.min(xScale, yScale) * 100);
}
mc.setBGSize(paperWidth, paperHeight);
var xMin:Number = 0;
var xMax:Number = paperWidth;
var yMin:Number = 0;
var yMax:Number = paperHeight;
pj.addPage(mc, {xMin:xMin, xMax:xMax, yMin:yMin, yMax:yMax}, {printAsBitmap:true});
}
pj.send();
}
delete pj;
this.close();
}
private function pointsToPixels(pts:Number):Number {
return pts/72*System.capabilities.screenDPI;
}
Have you tried this with more than one printer model? I've seen similar problems that have been the result of a buggy printer driver.