It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 12 years ago.
This is something I am not at all familiar with.
I want to try to make a simple form with 4 edit boxes, 2 at the top, 2 at the bottom, and a button. Basically what I want to do is type a couple of things in the top two boxes that are related to each other.
When I have them both filled in I click on the button and it saves this information in a database, preferable an external file (doesn't have to be text, I think it would be better if not). So I can do that a couple of times. Saving from the edit fields into a database.
Then when I type one of the words saved in one of the edit fields at the bottom it automatically types the other word in the last edit field. The form should remember to connect to the database every time it's opened so that when I open it another time I can still work the edit fields.
Can anyone advise me on how to do this?
What you are looking for is known as a dictionary, if I understand you correctly. In other languages it is known as an associative array or sometimes a hash.
You are going to want a modern version of Delphi, I'd guess 2010 or XE. If you can't access those then you'd need a 3rd party library, or a home grown based off a TStringList. In fact TStringList can operate in a dictionary like mode but it's a bit clunky.
You declare the dictionary as follows:
dict: TDictionary<string,string>;
You can add do it as follows:
dict.Add(box1.Text, box2.Text);
The first parameter is the key. The second is the value. Think of this as an array but indexed with a string rather than an integer.
If you want to recover a value then you use:
dict[key];
In your case you would write:
box4.Text := dict[box3.Text];
If you want to save to a file then you would iterate over the dict:
var
item: TPair<string,string>;
...
for item in dict do
AddToTextFile(item.Key, item.Value);
I've ignored all error handling issues, dealing with adding keys that already exist, asking for keys that are not in the dict, and so on. But this should give you a flavour.
I'd recommend reading up on associative arrays if you aren't already familiar with them. I'm sure there will be a page on Wikipedia and you would do worse than read an tutorial on Python which is sure to cover them – the issues are really the same no matter what language you consider.
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I hv a lot of data that format like this:
『 No.1
introduction:
explanation:
Parts1:
Parts2:
..
..
parts8.
No.2
introduction:
explanation:
....
....
....
....
No.100
...
』
I am setting up of my app's model that hold the data as NSMutableDictionary.
So that i can find the data by input a key.
The problem is that there is a lot of data(over 500 sets), Can i have a efficient ways to insert the data without "boring typing"?????
please help.
thank You!^_^"
Create either a JSON file or a property list file and use the built-in JSON or property list parsing facilities to read the file. Much better than building your own parser.
They way I would approach this problem is to open your file in a text pad and change all the : to pipes |. Now you have a pipe delimited file that you can use to parse.
No.1 introduction| explanation| Parts1| Parts2| parts3| (this is on line1)
No.2 introduction| explanation| Parts1| Parts2| parts3| (this is on line2)
Now put this file into a string and go over line by line to parse the string. Get each of the values put them in an array and then save the array in your NSDictonary with a key value. I will try to search for some sample code. From here you know
array(0) is - No.1 introduction
array(1) is - explanation
...
Check this post NSString tokenize in Objective-C
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
What Happens when Null is set to NSString? and saved in NSUserDefaults?? Will it crash since it treats it like a deallocated instance??
Now, if what you MEANT to say is "What happens when you set a NSString pointer to Null", that depends a bit on what you mean by "Null" (which is not a standard Objective-C term).
By "Null" you could mean either "nil" (which has C aliases of "null" and "NULL") or you could mean an NSNull object.
"nil" is a "null pointer" -- all zeros. This means that the pointer does not reference any object. "NSNull" is an object class whose only ("singleton") instance is used to represent "nothing", even though there is a real object representing this.
You can readily set a NSString pointer (ie, something declared NSString *) to nil. (Note, no quotes around "nil"!) This makes the pointer "empty".
You can also, with a cast, set an NSString pointer to point to the NSNull object, though this isn't commonly done.
(And, of course, you can set an NSString pointer to an "empty string" -- #"". This is a real string of zero length, and is not really related to nil/null.)
Since "local" variables (variables declared inside a method) are not implicitly zeroed by the compiler when the method is entered, it's often good practice to explicitly set declared pointers to nil on method entry, so that, if they don't eventually get set (but do get referenced), they will not contain "garbage" that can produce mysterious errors.
You are mixing metaphors. First, sprinkle around some NSLog messages reporting on the object type, before saving then on retrieval (NSStringFromClass[obj class]). You did not make it clear if you are using a C based SQLite interface or Core Data with a SQLite backing store, so update your question.
Lastly, if you message an object of class A with messages that only class B responds to, you will get exceptions pointing that error out. A dealloced error is totally different, and indicates your memory management is faulty. To track down the latter error, enable Zombies and break on any message send to one (many Q&As on how to do that here).
How can I write a routine in ESQL/C which will initialize to 0 (zero) all numeric fields (smallint, decimal, etc) and to a space the other fields in a table?
You asked this question on one of the IIUG (International Informix Users Group) mailing lists, and received answers there.
As I mentioned when I responded this morning, you need to think rather carefully about some of the types you don't mention. Zeroing a DATE sets it to 1899-12-31. Zeroing an INTERVAL makes sense (though you don't do it by setting all bytes zero; a similar comment applies to DECIMAL and MONEY and related types). Zeroing a DATETIME generates an invalid value. And BYTE, TEXT, BLOB, CLOB have separate sets of issues.
Setting character fields to a space is easy enough. Setting integer fields of various sorts to zero is also easy enough.
You can look at the code in either Art Kagel's utils2_ak package or in my SQLCMD package, both available from the IIUG Software Archive. They have code that cover many of the situations you're likely to encounter.
If they're not sufficient to help, then you need to show the code you're having problems with, explaining what is happening, what you want to happen, and (if appropriate) any messages your getting that are preventing it happening.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have two clusters as a class which has
Cluster : class
DocumentList : List<Document>
centroidVector : Map<String,Double>
Now the problem is that when the query is searched it is parsed as a file and then made into a document object , added to documentIndex and its index is constructed along with other documents . I did that because it had to go through the same procedure i.e tokenizing ,stemming etc. But now i want to implement query search in a specific cluster with which the query vector is most similar with , i.e dot product ~ 0.5 -1 . So i would have to take a dot product between the query vector and the cluster vector to do that. But i dont know how to implement it because the index is created in memory and is not stored in the database. Still in the process of doing that .
Thank you
Clustering is not meant for searching (i.e. indexing etc.). It is an analysis step meant to find possible unknown structure within your data set, not to retrieve information faster.
You can exploit the structure sometimes for faster search, but then you need an index that can make use of this.
Just do an index right away if you want to do similarity search! Then try to improve the index by doing some clustering before.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
What is the correct way to implement the "find as you type" behavior on a TComboBox descendant component whose style is csOwnerDrawFixed?
Use a TTimer (let's call it timIncSearch). Set (at design time) the following properties:
Enabled:=False;
Interval:=400; //empirically found - it's the delay used in Windows Explorer
...and in OnTimer you'll wrote your searching engine. Be sure that the first line here will be timIncSearch.Enabled:=False; Also because you use csOwnerDrawFixed perhaps it's better to enforce a repaint of your control.
As an aside, - just guessing because you didn't give us many details - perhaps you must hook OnEnter and OnExit events to custom open and close the DropDown list. (Normaly, this is achieved by setting the AutoDropDown property accordingly)
In your ComboBox.KeyPress you'll write
with timIncSearch do
begin
Enabled:=False;
Enabled:=True;
end;
...also take care here, perhaps you must have a 'case Key of' construct to handle the #13 separately (or whatever).
Other hints:
depending on your situation, perhaps you must hook (also?) the OnKeyDown (if you want to process special keys like eg. BackSpace, Del, Arrows etc. - taking in account that the event repeats itself while the key it's pressed down) and/or OnKeyUp (if you want to do similar processing as above but without taking in account the keyboard's key auto-repeat feature).
First you need to decide whether you need "*my_string*" or "my_string*" functionality, meaning deciding if you would search inside the strings or just from the beginning.
When you have figured that out, then you would have to buld the index of all the words entered in the combo box and search it after every keystroke.
I don't think that handling OnTimer is a right approach. I would rather use "OnChange" or similar.
You could do it with sorted (dupignore) TStringList, or maybe build the index using hash tables (the implementation is up to you).
The architecture depends on the max no of strings your combo could contain. If it is a significant number than you could use hash tables (one hash Cardinal pointing to multiple indexes : array, TList...)