I am trying to add items to a ComboBox so the user has a choice of what constant to run a calculation with but I cant seem to add items to a ComboBox without an error.
CComboBox *m_YM = (CComboBox *)GetDlgItem(IDC_COMBO1);
I have tried:
m_YM->AddString("Wood");
m_YM->Items->Add("Wood");
m_YM.InsertString(0, "Wood");
All throw errors. Compiler tells me that:
The argument type is incompatible with LPCTSTR.
No idea what is the meaning.
The important thing is the middle T of LPCTSTR, which means it will automatically decide if your string is Unicode or plain old ASCII, but the string needs to be input properly.
Recommended reading: What are TCHAR, WCHAR, LPSTR, LPWSTR, LPCTSTR (etc.)?
Try to put an L before or enclosing inside _T(...). Example: L"Wood" or _T("Wood")
Related
A bit of a trivial question, but it got my interest.
I often edit my code on the fly, or in other words, when in debug mode. I do this so I can quickly check the edits I have made for performance.
When in debug mode, one can neither remove nor alter Dim statements without countering the warning message:
This action will reset your project, proceed anyway?
I assume this is due to the compiler having stored variables in the memory in a manner specific to their data types, something which presumably can't be altered while the code is 'running'.
I have noticed, however, that adding a declaration in break mode can be done without any issues. Trying to remove or edit this line then once again throws the warning message.
Why is it possible to add but not to remove/edit declarations in break mode?
I strongly assume that the VBA runtime prevents you from modifying existing entries in the symbol table. Consider you have done something like
Dim i as Integer
i = 3
Debug.print i
You set a breakpoint to the Print-statement and change the type of i to String - what should the runtime do with the content of i? Implicitly convert it to a String? And what should happen if a conversion is not possible?
Adding a new entry into the symbol table doesn't do any harm because it doesn't modify anything that was done previously, so the runtime allows you to do so.
Btw: If you remove Option Explicit (I know you & me never do this...) and assign a value to an (undeclared) variable: This variable is now put into the symbol table and if you try to add a Dim-statement now, you will get the This action will reset...-message.
It appears that if you open a Workbook that declares even a single Public Function in its project with the 'Notify Before State Loss' VBE option enabled, VBE will prompt you with the "This action will reset your project, proceed anyway?" message as soon as you attempt altering the declaration line of this function. Probably because Excel somehow "loads" a variable that will hold the returned value...
got here Delphi 10.3 Update 1. On the Form I have a ADOQuery which has a Field named ExtraText this field is TWideStringField .
In my Programm I assign it like this :
PrintPosQueryRack.Value:=PrintPosQueryExtraText.Value;
if I hover the cursor over PrintPosQueryRack.Value I get System.WideString
if I hover the cursor over PrintPosQueryExtraText.Value I get System.String
I really-really don't understand why . The PrintPosQueryRack is a Calculated Field , which I Created as plain string . Because I as far as I know in later Delphi versions string is Unicode (UnicodeString) in Delphi .
I also have a variable here strRack : string . If I assign it to PrintPosQueryRack.Value ( which is System.WideString ) , I get the same Warrning .
I can "fix" this by changing the strRack : string to strRack : AnsiString
and by changing the PrintPosQueryExtraText.Value to PrintPosQueryExtraText.AnsiString .
But I am kinda lost here .
Thank you .
TL;DR: Use WideString as the type for your calculated field. StringFields are internally based on AnsiString.
If you make a field of type String, (ftString), you get a TStringField. Its value is still the "old" AnsiString. This is probably for compatibility reasons.
That is, it depends on the NEXTGEN define, which basically means the for classic desktop applications TStringField.Value is still an AnsiString, while for iOS and Android apps written in Delphi, it is indeed a (unicode) String.
But that is only for the Value property. You can also use the explicit AsString, AsWideString or AsAnsiString properties. Those properties are available for any field type, but the value you give or get is translated to and from the internal type of the field. For TStringFields, that type is still AnsiString, regardless how you set the value.
For unicode values, use WideString or WideMemo fields.
A haxe function has some parameters whose default values I'd like to use, so I don't need to import anything (they're basic types underneath). If they were last in the parameter order, I could get away with just not including them. But they're first, before some defaults I do want to override.
I'm not allowed to null them on native. _ doesn't compile (I don't think it's meant for this context.) Am I forced to import and copy the defaults in verbatim, or is there another way?
I tried .bind(_, ...)() but that gives Usage of _ is not supported for optional non-nullable arguments.
That error comes from the argument having a non-nullable type (Int, Float or Bool on a static target). If this function is part of your code and not some library, you could just make it nullable with Null<T> or ?.
As long as the arguments are nullable, Haxe also allows you to simply skip them if they are distuingishable (i.e. the type of the value passed must be different from the one(s) you want to skip). This means you don't have to use bind() or explicitly pass null. See the fourth example on the manual's Optional Arguments page.
If making the arguments nullable isn't an option for you in this particular case, you're probably going to have to copy the defaults (although I'm sure it's possible to come up with a clever macro solution for this).
I have added the CString value in CPtrList. And using Find function. When I try to Find the CString value using Find method of CPtrList, I always got NULL position.
Below is my code to add the CString value in CPtrList ptrFolderPath:
CString sTemp;//
ptrFolderPath.AddTail(new CString (sTemp));
While searching I using below code:
POSITION pos = ptrFolderPath.Find(sPath.GetBuffer(sPath.GetLength()));
here sPath is a CString.
But the pos value is always NULL.
Any idea, where I am missing?
The key point is a line in the MSDN Help for CPtrList::Find(): "Note that the pointer values are compared, not the contents of the objects."
When your code calls "new CString (sTemp)" a new CString object is created, and what is returned (and added to the CPtrList) is the pointer value - the location in memory of your new CString. Let's say, for example, this is at memory location 0x001234500.
Your code that calls Find() is passing in the address of character buffer, but, even if this contains the same string characters as your above CString, its location in memory will be completely different. Since you're not passing in 0x0012234500 (in this example), you don't find the entry you expect.
Given what you appear to be trying to do, CPtrList is probably not the appropriate container type - something like CStringList would be more suitable, since there comparisons are done by value (i.e. the contents of the string) not by pointer.
If all this doesn't make sense, I'm afraid that you need to spend some time reading up on pointers, and concepts such as the difference between equality (two different objects that have the same value) and identity (different references to the same object)
I have an EditText object (et_travel) on my screen that's asking for miles traveled. I grab that data like this:
float travel = Float.parseFloat(et_travel.getText().toString());
if(travel > 40000){
I just discover that if someone puts 40000 in the EditText, everything works fine, but if they put 40,000 (adding a comma to the number), I force close on the float travel = ...statement.
How can I evaluate the number without having a problem from the user adding a comma?
Is this in Java? It appears to be, but I'm wondering if I'm mistaken. Regardless, I would suggest you remove all of the characters from the string that are not of a numeric type. A way to do this may be using a regular expression.
A way to do this in Java may be the following:
String input = et_travel.getText().toString();
input = input.replaceAll("[^0-9]", "");
float travel = Float.parseFloat(input);
...
This way, you strip anything that is a non-numeric value from the string first, and then attempt to do your work. Obviously do some error checking before this (like input is not null and such). One change that is needed however is that you may need to maintain the '.' character (if you're given non-integer values). This would require changing the first regex a bit.
Check here: http://download.oracle.com/javase/1.5.0/docs/api/java/lang/String.html#replaceAll(java.lang.String, java.lang.String)
What you need is some validation on the input. Before converting the string into a float parse the string. If there are any ','s then remove them. If there is just junk then reject the input, otherwise someone could put a word or anything else in the input and cause havoc in your program.
Check out
inputType to restrict user input
android:inputType="number"