TComboBox: add items in "reversed order" - combobox

TComboBox.Items.Add adds an item "at the end" of the list (at n+1 with n being the last index before edding the new item):
0: Item1
1: Itme2
2: Item3
3: New Item
But I want to add the item at n=0, with all the other items moving up one index:
0: New Item
1: Item1
2: Itme2
3: Item3
Currently I'm using this code, which works well:
ComboBox1.Items.Add(strSomeNewItem);
ComboBox1.Items.Move(ComboBox1.Items.Count-1,0);
I was just wondering if I overlooked a scenario in which it might cause problems?! Or maybe there is a better command I overlooked?!
(The Lazarus Component Library is currently down, so most of the links in my search engine come up with an error).
Cheers!

You can use Insert().
ComboBox1.Items.Insert(0, strSomeNewItem);

Related

array_search returns just 1 result

I´m starting to study PHP and I have a doubt in one lesson about array_search.
The teachers example shows "A peeple who got a 10" and as only one of the people got a 10 everything works fine, showing the person's name.
But I've been trying to use it to fetch more than one result. In this case I created this array, with 3 people taking 10:
$notas2=array(
"Ana"=>4,
"Misca"=>10,
"Chatuba"=>6,
"Jurandir"=>7,
"Musca"=>10,
"Mickey Mouse"=>10,
);
echo array_search(10,$notas2);
This code just returns "Misca". I tried a foreach, but it returned only "MiscaMiscaMiscaMiscaMiscaMisca". lol
foreach(array_search(10,$notas2)as $tirou10){
echo $tirou10;
}
Anyone can help-me?
Tanks.
array_search will export only first corresponding key. If you want to get all people who got 10 use array_keys($notas2, 10) it will return array and instead of echo use var_dump() or var_export()
The PHP function array_search only returns the first entry.

Choose a random SpriteNode out of an array?

I'm learning how to code and as a first project I thought it would be a good idea to create a little stone paper scissors game against the computer. The problem is, that obviously the computer may not show his choice, so I have to create a function, which makes a random picture x (I'm using Apple's smileys for it) appear on the position x on the screen.
So I have to:
random number between 1 and 3 var rN = GKRandomDistribution(lowestValue: 1, highestValue: 3)
let array = [opStone, opPaper, opScissors] //already declared as files
let choiceOp = array[rN]
choiceOp.position = CGPoint(x. ?, y: ?)
self.addChild(choiceOp)
In theory. The problem is, that Swift does not accept a GKRandom distributed number rN at the third step.
Do you have any ideas how I could do it?
In your step 3, you should call nextInt() on rN. GKRandomDistribution generates a new random number every time you call nextInt() based on the lowest and highest value you have given it at initialization. So your new code would be:
let choiceOp = array[rN.nextInt()]

Understanding Code block of helper.php in mod_menu of Joomla 3.x

I'm trying to understand the helper.php file in the mod_menu folder of Joomla 3.x. The section of code which I am looking it is where we come across the first isset call to check the values of our new introduced elements
In particular Im trying to figure out how $item->shallower is able to calculate the depth of the menu structure which differentiates from the deeper, It allows us to create lists in list elements via the default output template for this particular module.
// add these elements to each item
$item->deeper = false;
$item->shallower = false;
$item->level_diff = 0;
if (isset($items[$lastitem])) {
$items[$lastitem]->deeper = ($item->level > $items[$lastitem]->level);
$items[$lastitem]->shallower = ($item->level < $items[$lastitem]->level);
$items[$lastitem]->level_diff = ($items[$lastitem]->level - $item->level);
var_dump($items[$lastitem]->shallower);//(bool)true or false
var_dump($item->level);//string
var_dump($items[$lastitem]->level);//string
}
I am just struggling to get my head round this piece of code, more so both $item->deeper and $item->level seem to working as they should, but I have no understanding of what $lastitem]->shallower is doing. Any explanation would be most helpful.
regards
w9914420
The key is $lastitem, which is the index of the previous item created; it is set right after the code you pasted:
$lastitem = $i;
where $i is the key in the foreach loop above that iterates through all $items with the variable $item.
Thus, on the next iteration, $items[$lastitem] is the previous item created.
In order to determine if an item has subitems, it's sufficient to compare the current and previous elements levels. This is an efficient way to achieve this, as only one iteration through all the items is necessary to build the data structure and integrate the deeper/shallower fields.
Shallower is the opposite of deeper:
+ item
+-- item // this is deeper;
+-- item
+-- item
+ item // this is shallower;
+ item

Cat/SubCat product count incorrect in Drupal 7-Ubercart 3

I am working on Drupal 7.12 and Ubercart 3.0 for a store website. While working on Product Categories, I am getting wrong count of items in parent category as well as sub-parent or sub-sub-parent category like:
Cat A(5)
Cat A-1(3)
Item 1
Item 2
I think there is a bug either in Taxonomy module or uc_catalog module. I have searched over the net but didn't find any perfect solution. So anybody there having any workaround for this specific problem as I have to show the count of items in front of their respective category and total in parent category.
It appears that it is not counting only product items but it is also counting category along with product items.
Thanks for your time.
Regards
pls refer to this part of code of uc_catalog.module
$query->entityCondition('entity_type', 'node')
->entityCondition('bundle', $types)
->propertyCondition('status', 1) // Don't include unpublished products.
->propertyCondition('language', array($language->language, 'und'))
->fieldCondition('taxonomy_catalog', 'tid', $branch->tid)
->count();
$num = $query->execute();
the above is an example to count only the nodes with und(neutral language) and current language. This is the deficiency of the ubercart.

How can I stop the Enterprise Library caching block from persisting changes to data I've retrieved from it?

What an awkwardly worded question, you're thinking?
When my application loads, it goes to the database and gets several different lookup tables worth of data and creates .NET Lists for each one and puts them in cache. For example, "Status".
List at this point:
On,
Off
When I retrieve the List of Statuses from the cache, I add another item to the List, "Choose One" and the set it as the ItemsSource of a ComboBox. At no point do I put the new List, now containing "Choose One" in addition to the list of statuses back into the cache.
List<ContractStatus> contractStatuses = (List<ContractStatus>)this._cacheManager["CurrentContractStatuses"];
ContractStatus contractStatus = new ContractStatus
{
ContractStatusDescription = "Choose One", ContractStatusId = 0
};
contractStatuses.Insert(0, contractStatus);
List at this point:
Choose One,
On,
Off
Yet if I go to another screen and come back, the screen's load routine pulls the list of statuses from the cache, and Choose One is already in the list. So when the routine adds "Choose One" I wind up with:
Choose One,
Choose One,
On,
Off
Is this by design? How in the world do I tell it to quit?
The Cache Manager is returning a reference to your List<ContractStatus>. This reference points to the object in the cache. You are then inserting an item into the same List as is in the cache.
Is it possible to cache a version of the List that includes "Choose One" so that you are only reading the List from the cache? If so then that should avoid the "issue" you are seeing.
If you do need to manipulate the List from the cache without modifying the List in the cache then you should clone the List before manipulating it:
List<ContractStatus> contractStatuses =
(List<ContractStatus>)this._cacheManager["CurrentContractStatuses"];
// Clone the list (but not the items)
List<ContractStatus> newStatuses =
contractStatuses.ConvertAll<ContractStatuses>(item => item);
ContractStatus contractStatus = new ContractStatus
{
ContractStatusDescription = "Choose One", ContractStatusId = 0
};
newStatuses.Insert(0, contractStatus);

Resources