My configuration:
Delphi XE
Firebird 2.1
IBObjects 4.9.12
Windows 7 64bits
I get an exception when I try to set a value to a IBOQuery parameter ("Could not convert variant of type (UnicodeString) into type (Double)").
The exception is raised from TIB_Column.SetAsVariant procedure in IB_Components.pas (line 42795). To create this situation, just try to pass a string to a date parameter:
myQuery.paramByName('mydate').AsString := DateToStr(IncDay(Now,5));
During last 25 days I'm trying to solve this situation, but in IBO support list I've got no answers.
Someone have an idea?
IBObjects's architecture is converting(at a moment of execution) all parameters, fields, etc to String or Variants. If your 'mydate' parameter is 'DateTime'(numeric) type then you must fill it up with a corespondent type value. Is not logic to fill an 'numeric' type parameter with a string...
try this
myQuery.paramByName('mydate').AsDateTime:= Now+5; //is the same as David's answer.
or
myQuery.paramByName('mydate').AsFloat:=Now+5; //or IncDay(Now,5)
Best regards,
Radu
Related
I have defined a MySQL database with a table that includes a field of type varchar(128), I call it fieldinquestion. I use a query to access this field, which usually works nicely. However, when I assign a string to the field, I get an error that I don't understand.
try
Self.FDQuery1.FieldByName('fieldinquestion').AsString:='Hello There'; //or something similar.
except
---> error: 'Could not convert variant of type (String) into type (Double)'
aDataType:=Self.FDQuery1.FieldByName(GCssValidationDisplay).DataType; --datatype is ftString
end;
In the try..except clause, this causes an error, but a verification for the datatype shows it is a string!
Any ideas?
Let's imagine that I have created the stored procedure in SAP HANA database and would like to have optional out parameter with text type, like error details. As I have read to achieve this I should use some default value thus I have done like this:
PROCEDURE "myProcedure"
(
IN inSomeParameter BIGINT,
OUT outResult INTEGER, -- output, result of the operation
OUT outErrorDetail NVARCHAR(32) default ''
)
Unfortunately build failed with the following error:
OUT and IN OUT parameters may not have default expressions
So, I decided to try with null, but it failed the same way. Later I changed the type to integer just to try and it failed exactly same way again.
In the same time this works:
PROCEDURE "myProcedure"
(
IN inSomeParameter BIGINT,
OUT outResult INTEGER, -- output, result of the operation
OUT outErrorDetail TABLE(errorDetails NVARCHAR(32)) default empty
)
but it feels like a huge overkill - to make a table to return only one text value.
Do you have any suggestion how to add optional output parameter?
SQL Script in its current state doesn’t allow for optional OUT parameters.
Why don’t you just set the OUT parameter default value in the procedure body right before the code?
This adds boilerplate code, but you could also use it to convey explicit success messages.
I have to access several functions of a DLL written in c from Delphi (currently Delphi7).
I can do it without problems when the parameters are scalar
(thanks to the examples found in this great site!), but I have been stuck for some time when in the parameters there is a pointer to an array of Longs.
This is the definition in the header file of one of the functions:
BOOL __stdcall BdcValida (HANDLE h, LPLONG opcl);
(opcl is an array of longs)
And this is a portion of my Delphi code:
type
TListaOpciones= array of LongInt; //I tried with static array too!
Popcion = ^LongInt; //tried with integer, Cardinal, word...
var
dllFunction: function(h:tHandle; opciones:Popcion):boolean;stdcall;
arrayOPciones:TListaOpciones;
resultado:boolean;
begin
.....
I give values to aHandle and array arrayOPciones
.....
resultado:=dllFunction(aHandle, #arrayopciones[0]);
end;
The error message when executing it is:
"Project xxx raised too many consecutive exceptions: access violation
at 0x000 .."
What is the equivalent in Delhpi for LPLONG? Or am I calling the function in an incorrect way?
Thank you!
LONG maps to Longint, and LPLONG maps to ^Longint. So, you have translated that type correctly.
You have translated BOOL incorrectly though. It should be BOOL or LongBool in Delphi. You can use either, the former is an alias for the latter.
Your error lies in code or detail we can't see. Perhaps you didn't allocate an array. Perhaps the array is incorrectly sized. Perhaps the handle is not valid. Perhaps earlier calls to the DLL failed to check for errors.
I am using the code below in C++Builder XE4 VCL 32bit. I am using the Indy components, version 10.6.0.497.
I have been using IdHTTP->Get() with HTTP addresses that have now changed to HTTPS. I believe I need to create a TIdSSLIOHandlerSocketOpenSSL component and add it to TIdHTTP as its IOHandler.
When I try to do this, the code below gives the error:
E2451 Undefined symbol 'TIdSSLIOHandlerSocketOpenSSL'
The error is on the code, std::auto_ptr<TIdSSLIOHandlerSocketOpenSSL>.
I am not sure why TIdSSLIOHandlerSocketOpenSSL is undefined, because I have Indy installed and can use TIdSSLIOHandlerSocketOpenSSL as a traditional component from the component palette.
Can anyone show me how I can set this code up to use HTTPS addresses?
std::auto_ptr<TIdSSLIOHandlerSocketOpenSSL> Local_IOHandler( new TIdSSLIOHandlerSocketOpenSSL( NULL ) );
//error: E2451 Undefined symbol 'TIdSSLIOHandlerSocketOpenSSL'
//error: E2299 Cannot generate template specialization from 'std::auto_ptr<_Ty>'
std::auto_ptr<TIdHTTP> Local_IdHTTP( new TIdHTTP( NULL ) );
Local_IdHTTP->Name="MyLocalHTTP";
Local_IdHTTP->HandleRedirects=true;
Local_IdHTTP->IOHandler=Local_IOHandler;
TStringStream *jsonToSend = new TStringStream;
UnicodeString GetURL = "https://chartapi.finance.yahoo.com/instrument/1.0/CLZ17.NYM/chartdata;type=quote;range=1d/csv/";
jsonToSend->Clear();
try
{
Local_IdHTTP->Get(GetURL, jsonToSend);
}
catch (const Exception &E)
{
ShowMessage( E.Message );
//error: IOHandler value is not valid
}
When I try to do this the code below gives the error E2451 Undefined symbol 'TIdSSLIOHandlerSocketOpenSSL'
Add #include <IdSSLOpenSSL.hpp> to your code.
I am not sure why 'TIdSSLIOHandlerSocketOpenSSL' is Undefined because I have Indy installed and can use 'TIdSSLIOHandlerSocketOpenSSL' as a traditional component from the compoenent pallet?
Dropping a component onto your Form at design-time auto-generates any necessary #include statements for you. TIdSSLIOHandlerSocketOpenSSL is no different.
That being said, once you get that fixed, you cannot assign a std::auto_ptr itself to the IOHandler. You need to use its get() method to get the object pointer:
Local_IdHTTP->IOHandler = Local_IOHandler.get();
And you should consider using std::auto_ptr for your TStringStream as well:
std::auto_ptr<TStringStream> json( new TStringStream );
Local_IdHTTP->Get(GetURL, json.get());
// use json as needed...
Though in this situation, I would suggest using the overloaded version of TIdHTTP::Get() that returns a String instead, there is no benefit to using a TStringStream:
String json = Local_IdHTTP->Get(GetURL);
// use json as needed...
I was under impression that in F# the following two lines are supposed to give identical results:
let a = string v
let a = v.ToString()
It is implied that v is an object. It turns out that if v is a System.Guid the first line just throws an exception:
System.FormatException occurred
Message="Format String can be only \"D\", \"d\", \"N\", \"n\", \"P\", \"p\", \"B\" or \"b\"."
Source="mscorlib"
StackTrace:
at System.Guid.ToString(String format, IFormatProvider provider)
InnerException:
I can certainly deal with Guids separately, the question is what other objects will give me the same trouble? Should I avoid using the string operator at all?
In my case the object potentially can be anything
This is a bug that is (will be) fixed in the next release.
(In general, it should work; the bug is because System.Guid does not respond to the IFormattable "G" specifier, despite the fact that the docs for IFormattable say that all implementers must implement the "G" specifier. So it's actually kinda a bug in System.Guid, but the F# library will work around this bug in its 'string' operator in the next release.
In short, you can use this operator safely, except for Guid right now, but that will be fixed soon. In the meantime you can special-case Guid.)