I have the following pdfMake code block in my ionic app:
pdfMake.createPdf(docDefinition).getBase64(function (encodedString) {
pdfEncoded = encodedString;
console.log(pdfEncoded);
this.sendValue(pdfEncoded);
}
The error I am getting is:
Cannot read property 'sendValue' of undefined.
What do I need to do to call the sendValue() function? I am able to console.log the value of pdfEncoded but unable to pass the value to a function. Can someone let me know what I am doing wrong.
Thank you,
A
One reason of the error maybe because the keyword 'this' might be undefined inside your function(block). Check for that and see if the error is because of that and if it is try this :
let $this = this
And then inside your function use it as:
$this.sendValue(pdfEncoded);
Related
I want to set up the Linea Pro to charge the phone if the phone's battery gets low and I'm having a tough time mainly because all the examples are shown in objective-C still and not in Swift.
The manual says:
#param enabled TRUE to enable charging, FALSE to disable/stop it
#param error pointer to NSError object, where error information is stored in case function fails. You can pass nil if you don't want that information
#return TRUE if function succeeded, FALSE otherwise
*/
and the code provided is the following:
-(BOOL)setCharging:(BOOL)enabled error:(NSError **)error;
So in Swift I first tried this:
self.scanner.setCharging = true
but that gives me the following error:
Cannot assign to property: 'setCharging' is a method
So I tried this:
self.scanner.setCharging(true)
which gives me this error:
Call can throw, but it is not marked with 'try' and the error is not handled
Interesting because apparently I have to build it in a function called "setCharging" I think, but I have no idea what and how it wants me to set up the try and catch to, and quite frankly where am I opposed to get this information from?
I think it should be along these lines or something, but I'm not clear on the specifics :
func setCharging(_ enabled: Bool) throws -> Bool {
do {
try
//something goes here I'm not sure what
} catch {
//and then maybe something here on that to do with error
print("some error")
}
}
The answer was provided to me by the manufacturer. It is unnecessary to create a function with the same name as the API, APIs can be called anywhere in the code with the exception of handling error. So in this case I just have this directly in my code not in a function and it just works. (Since I have my scanner.connect code inside a viewWillAppear block, the code to start charging was too early to be called in there, so I placed it inside of a viewDidAppear block).
The following is the code:
do{
try self.scanner.setCharging(true)
}catch let error as NSError{
NSLog("Operation \(error as Error)")
}
Xcode 8/Swift 3
Can anyone please tell me why I am getting this "expected declaration" error? The use of delegates answered my last question perfectly without getting this error.
Googling other "expected declaration" problems suggests function calls etc being in the wrong place but I don't think thats the case here - I have tried placing delegate?.loadFirstView(viewFromModel: firstView) in a separate function and then calling that function but I just get the same error. See the screenshot below:
Thanks in advance!
P.S: below is a screenshot of when my use of a delegate worked perfectly.
Third Screenshot with delegate call in a separate function:
You have the code (delegate?.loadFirstView(viewFromModel : firstView)) in the wrong place in the class. So move it to any function.
In your working screenshot, the code is written inside the updateClock()method, thus working without any error.
class modelClass{
var delegate : LoadFirstViewProtocol?
let firstView = "First view loaded"
func testing()//Write here user defined method named
{
delegate?.loadFirstView(viewFromModel: firstView)
}
}
So I have an "assertion failed" error message when I want to run my program. I understand that it means that somewhere a condition that should be true isn't but I don't know how to correct that.
The error concerns the following line :
_AFXWIN_INLINE BOOL CEdit::SetReadOnly(BOOL bReadOnly)
{ ASSERT(::IsWindow(m_hind)); return (BOOL)::SendMessage(m_hWnd, EM_SETREADONLY, bReadOnly, 0L); }
So I get that it's about the "Read Only" condition, but I don't know where to correct that.
I am new in C++, so sorry if I forgot to put important information in my question.
Thanks in advance!
The OnInitDialog function contains a call to the base class function
CDialog::OnInitDialog();
Move your calls to SetReadOnly to after that line. The edit control variables are only initialized after that line.
Thank you for your help! Finally, after going through the whole code line by line, I realized in DoDataExchange I mixed up and put twice the same variable at some point instead of two different ones ... So I don't really know how that got me that error but I thought I'd keep you updated in case someone makes the same absent-minded mistake and gets that error :)
Hi I have just started using C++ today, and I am working on checkboxes. I have tried using CheckBox1->Checked in an if statement or whatever, but it isn't working.
The error is:
Error 2 error C2227: left of '->Checked' must point to class/struct/union/generic type
EDIT: The Code is:
void function ()
{
if (1001->Checked)
{
Sleep(2000);
}
}
Without seeing some of your code, it's very difficult to offer targeted assistance.
However, that error message usually comes about because the item you're de-referencing is not a pointer.
Check to ensure it's of the correct type. It should be something along the lines of:
tCheckBox *CheckBox1;
One possibility is that you've declared it not as a pointer to the checkbox but as a checkbox itself:
tCheckBox CheckBox1;
Note the lack of the asterisk there that would otherwise mark it as a pointer. In that case, you would use CheckBox1.Checked rather than CheckBox1->Checked, if it's allowed by the framework (this isn't standard C++ since that beast has no concept of GUI libraries).
If that doesn't help, please post the code so we can offer better suggestions.
Update:
if (1001->Checked) ?????
1001 is not a pointer - it's not a variable of any description, it's an integer constant.
You need to declare and use a variable of some description. First step is, I think, to read up on the documentation for your framework and/or get some sample code that does compile and work, basing your initial work of that.
Use CButton::GetCheck() to determine the state of the checkbox - like so...
CButton* pButton = (CButton*) GetDlgItem(IDC_CHECKBOX_RESOURCE_ID);
if ( BST_CHECKED == pButton->GetCheck() )
{
// button is checked
}
I am very new to SSL , Actually I would say I know nothing about it.
I am using the method "SSL_CTX_new" to create an SSL_CTX object. The method returns null.The documentation says I can check the error stack in order to get the cause for this.
So I have the function "int SSL_get_error(SSL *s,int ret_code)" which (as I understand) I have to use in order to get the error message. the documentation of the method says nothing about the first parameter of the function. It only says that the second ("ret") parameter should be equal to the return code from the failed operation which can be any of the following :
SSL_connect(), SSL_accept(), SSL_do_handshake(), SSL_read(), SSL_peek(), or SSL_write()
So now I am having two problems. The first is that I didn't use any of those functions but rather use SSL_CTX_new that doesn't return any kind of return code (it returns a pointer to SSX_CTX object) So i don't know what to put as the "ret" parameter. The second problem is that I don't know what does the first parameter mean and what should I put there , because the doc says nothing about it.
You need a valid context to create the SSL object.
Since you can't create a context you can't use SSL_get_error.
Try using ERR_print_errors to see what's gone wrong
#include "openssl/err.h"
...
SSL_CTX * ctx = SSL_CTX_new(....);
if(!ctx) {
ERR_print_errors_fp(stderr);
//throw or return an error
}
I just had a read of the SSL docs. If you need to programatically get the error code / error string you should use the ERR_get_error and ERR_error_string functions.
Have a look here and here
As per http://www.mail-archive.com/openssl-users#openssl.org/msg51543.html, you may be missing a call to SSL_library_init(). Adding this before the SSL_CTX_NEW(..) call fixed the NULL value problem for me.