Load many pictures in a form - delphi

I was asked to develop a game called "Flag Quiz" in which the player have to guess the correct name of the flag that appears in the middle of the screen.
Of course I have a lot of pictures (221 flags) and I have to put them inside the program because, when the button Play is pressed, the program has to pick randomly 10 of these flags.
Problem
I was thinking to use an ImageList but the flags are 480x311 and so Delphi asks me to separate the picutre in 30 different bitmaps. Can I do anything about this?
My idea, to avoid that problem, was the following (although I think that it's not very good): create 221 TPicture components (invisible to the user of course) and load in each of them a picture of a flag.
I'd prefer not using the last idea I had. Do you know any improvement?

This sort of problem is simply not suited to the form designer. You want to store 221 images, and managing that in the IDE will be horrible. Once you've got them all in you won't be able to see them readily because they will be base 16 encoded in a .dfm file. Under revision control it will be a mess because you won't be able to change individual images in a manageable and traceable manner.
The accepted way to do this is to use resources. If it were me, I'd arrange for my images to have predicatable names. For instance, flag1, flag2, etc. I'd generate a resource script (.rc) that listed all the flags. I'd compile that resource script to a compiled resource (.res) which is linked to the executable. I'd have the resource script and the image files committed to revision control.
Then at runtime you have a single TImage control to display the flag. Every time you need a new image you load it with TResourceStream, and push it into the TImage control.

Devexpress has a Componnect named cximagecolletion that you can put your images on it and save and load images from/to file
or you can save all flags in small access db and load it when you need using tadodataset
there is no doubt that if you put your images direct on your form your dfm grow very high and so you Get Into trouble

Personally I would store each file as an image in a dedicated subdirectory, using the country as a file name. Then I would read the subdirectory file names on entry to the program (so I have a list of countries that I can randomly choose from) and use TImage.LoadFromFile to display the flag. This is far easier to extend than using a resource file (IMHO).

Related

MacOS Automator: Select different files from Folder structure and move to folder

I have a bunch (roughly 10.000) of Images named "XXXXX.psd", where X is a number. Sometimes the name string is shorter (XXX.psd).
I also have a List which tells me which of these images I need, roughly 180 images every two weeks or so. I'd like to make an automation that takes said list and then automatically copies the needed images into a separate folder.
Any help is appreciated, I kno nothing about applescript or javascript, but am willing to try it :P
PS: The images are in separate folders. The list is a pdf but i managed to extract it into an xlsx/table, and could also just have it in plain txt.

How to use ImageMagick with Alfresco?

I know Alfresco uses imagemagick for preview of images however I want to use imagemagick when uploading images to ALfresco. So that only compressed images are stored in repository.
Any idea how can I achieve this either my manipulating configurations of Alfresco or I need to do it with some programming?
Thanks
You have a few options. First, you could write a rule which would be triggered when objects of a certain mimetype are added to a folder. Your custom rule code could then invoke a transformation to compress the image and then delete the source file. One drawback to this approach is that the original file does exist in the repo for a time. The second drawback is that you'd have to configure it on every folder. This tutorial explains how to write a custom rule action.
The second option would be to implement a behavior. Your custom behavior code can look for a node creation event and take action when it sees one happen. When it sees an image it could then invoke a transformation and replace the original. This tutorial explains how to write custom behaviors.
The third option would be to do a much lower level extension of the node service, so that the original object never actually gets created but is first compressed. That would be much more involved than either of the options above.

How to save multiple files at once through delphi save dialog

I'm not able to save multiple files at a time in delphi save dialog box. Multiple files means I want save files without mentioning anything(or only asterisk) at "filename" field in delphi TsaveDialog. Please let me know how to achieve that.
Of course not, because that is not what it is intended for. You CANNOT obtain multiple filenames from a single save dialog. It only provides one filename at a time. That is by design.
I suspect what you really want is to prompt the user for just a folder path instead. Use the SelectDirectory() function (or the Win32 SHBrowseForFolder() function directly) for that, then you can create whatever files you need in that folder.
The save dialog doesn't save files. It allows the user to select file names. The save dialog doesn't support multiple selection so if you want to have a file dialog that allows multiple selections you need an open dialog. But an open dialog typically is used to select names of existing files, whereas a save dialog can specify a name of a file that does not yet exist.
Wildcards when entered into file dialogs are used to filter the displayed list of files. The file dialog won't return file names containing wildcards.
You imagine using wildcards, but how would you be able to do that and create new files? Wildcards are used to pattern match against existing files.
Maybe what you need is a folder selection dialog. Or perhaps you should ask the user for the name of the "master" file and then you generate the names of the "auxiliary" files using the master file name as a stem. I'm guessing because you've not told us any specifics behind your question.
My advice is to reconsider carefully what you are attempting to achieve. Think of all possible corner cases. Explore what UI idioms are used by other programs. Make sure you understand fully the capability of the file dialog controls. And then design your UI to fit with all of these constraints.

Download Directory and Contents

Is it possible to persuade the stream result to download an entire directory and it's contents? And if so, how? I've no problem getting it to download individual files, but I have a need to download a series of files that must be in a specific directory structure.
I don't think so.
Stream result allow you to download ONE content, with its MIME type, its name, etc.
This makes it impossible to work with a lot of files, with different names and content type.
What you can do is:
Render in a JSP the list of files (in anchor tags for example), everyone targeting the Action that will download that single file;
Call multiple Actions via scripting opening multiple pages (target="_blank") for every file you have (dangerous, annoying, almost useless...);
Create a zip with Java in server side, containing all your files and directories, then output the zip with Stream result.
I think you may consider the third option.

How to migrate my files from one folder location to another with full user visibility

For years I've put my application data files in c:\MyCompany\MyDataFileFolder\App where 'App' is my application name. I made this choice in the early days of Wild-West-Windows when Microsoft seemed to keep changing its own mind (My Documents, Documents, Program Data etc). As I've learnt more about how to do things correctly, and as Windows has now 'settled down' and is more picky about permissions I'd like to move my files. Users have got used to where they are though, and what I'd really like to do is to implement something like Windows does with 'special folders' where there are several synonymous names, thus in my legacy folder I'd like to put something in (or change a folder to) an alias for the real location which will now be something descended from Program Data. This way, the files are in a good place with the correct permissions and if we run a utility expecting or modifying files in the 'old' place this gets changed transparently to the 'new' place (thus a simple shortcut wont work).
Is this possible? Is there are recognised technique for this? I'm using Delphi XE2.
What you are looking for is either a Symbolic Link or a Reparse Point.

Resources