Soal CPNS, Lowongan CPNS, Lowongan Kerja

Tuesday, July 22, 2008

Running Flash animations with Delphi

Scenario

Suppose you are developing some kind of a Delphi application designed to display various graphics file formats. By default, Delphi lets you handle and show BMP, JPG, WMF and other "standard" picture file formats, and even animations. If you want to take you application to the next level, sooner or later, you'll want to include an option to play Flash animations. Macromedia Flash animations (*.swf) are those fancy movies you see everyday while surfing the Internet.

How to prepare for Flash animations
To display a Flash animation in a Delphi application, you'll need to import Macromedia Flash ActiveX control. The Flash ActiveX is titled 'SWFLASH.OCX' and it will probably be located somewhere inside the C:\Windows\System\Macromed\Flash folder.

First, let's see how to import the control into Delphi - of course, you only need to do this once:


  • Start Delphi and select Component | Import ActiveX Control... from the main menu
  • Select the Component palette location in which you want to place selected library. Maybe the best is to leave the ActiveX option selected.
  • Click on Install.
  • Select a package where the new component must be installed or create a new package for the control. By default, Delphi will propose the dclusr.dpk package.
  • Click on OK.
  • Delphi will prompt you whether you want to rebuild the modified/new package or not. Click on Yes.
  • After the package is compiled, you'll get a message saying that the new TShokwaveFlash component was registered and already available as part of the VCL.
  • Close the package detail window, allowing Delphi to save the changes to it.
  • The component is now available in the ActiveX tab (if you didn't change this setting in step 4)
How to play Flash animations with Delhi

You are now ready to create your fist Flash enabled Delphi application. Here's how:
  • Select the ActiveX tab on the Component palette.
  • Pick the TShokwaveFlash component.
  • Drop the component on a form.
  • Select the component you just dropped on a blank form.
  • Using the object inspector, set the Movie property to the name of an existing swf file on your system. Note that you must set it with the full path name.
  • Make sure that the Playing property is set to True.
  • Run the project, and here it is! A sample swf file is running below, though you do not see it running :)


Monday, July 21, 2008

use barcodes in Delphi (4-7)

You can use ActiveBarcode in Delphi like any other control (e.g. like a button). First you have to add the ActiveBarcode control into the Delphi development environment.

Add ActiveBarcode to the Delphi development environment
(The is also a description for older Delphi versions (4-7) available)

Select a package in which you would like to take up the Control or create a new package ("File" - "New" - "Package Delphi for Win32 "):

Save this package under an own name with the "Save as" function. For example as "ActiveBarcodePackage".

Now import the ActiveBarcode Control in the package. Launch the function "Component import" from the menu "Component".

The "Component dialog" appears:

Select "ActiveX control" and click "Continue". Now a list of the available contols will be shown:


Select "ActiveBarcode" from that list and click "Continue". A page for compontent setup will be shown:

You don't need to change something here. Click "Continue". A page for "Install" appears.

Select "Add unit to the project .." here and click on "Finish". Now ActiveBarcode is added as a component to the package. Now you must compile the package. Select the function " ActiveBarcodePackage create" from the menu "Project":



Use ActiveBarcode (Example)

Create a new project: "File" - "New" - "Form application VCL". To place ActiveBarcode now onto a form you select the ActiveBarcodeControl from the tool palette. You'll find this under "ActiveX" as a "TBarcode" component:

Select TBarcode and place the component on the form. In the object inspector you can customize the properties of the component. E.g. set the background color on white.


For this example add one more TEdit to the form. Now you form might look as follows:

Now we "link" the edit field directly with the control. Open the source code for the "textchange" event by double clicking the edit field. This event always is called, if the contents of the edit field are changed. Ideally for our example. We give this update immediately to the control.

That's it. Now launch the program:


Change the content of the edit field to change the barcode.

Programming:
Setting properties is very simple. Some examples:

Barcode1.Text := '123456789012';
Barcode1.BackColor := clWhite;
Barcode1.ForeColor := clBlack;
Using the Picture Property:
Copy the barcode to a image object:
Image1.Picture.Bitmap.Height := Barcode1.Height;
Image1.Picture.Bitmap.Width := Barcode1.Width;
Barcode1.Picture.PictureAdapter := nil; // delphi workaround
Image1.Picture.Bitmap.Canvas.Draw(0,0,Barcode1.Picture.graphic);
Clipboard:
Copy the current barcode to the clipboard. Metafile (WMF):
  Barcode1.CopyToClipboard;
Bitmap:
Image1.Picture.Bitmap.Height := Barcode1.Height;
Image1.Picture.Bitmap.Width := Barcode1.Width;
Barcode1.Picture.PictureAdapter := nil; // delphi workaround
Image1.Picture.Bitmap.Canvas.Draw(0,0,Barcode1.Picture.graphic);
Clipboard.Assign(Image1.Picture.Bitmap);

Twain and Delphi

Acquire images from scanners, cameras and image capture devices using Delphi. See how to import (and wrap in a component) an image scan control within Delphi.

Technology Without An Interesting Name


TWAIN is a program that lets you scan an image (using a scanner) directly into the application (such as PhotoShop, Photo Paint) where you want to work with the image. Without TWAIN, you would have to close an application that was open, open a special application to receive the image, and then move the image to the application where you wanted to work with it.

Within Delphi

Even though you could use some of the third-party components below, you already might have everything you need to scan an image from a Delphi application. The setup program for Imaging (tool that ships with Windows > 98) installs the Image Scan control (OCX) and the 32-bit TWAIN DLLs. All you have to do is to import this ActiveX control in Delphi and generate a component wrapper:

I'll give you a code snippet on accessing the TImgScan component. Drop one on a form and provide an OnClick event handler for a Button control.

if ImgScan1.ScannerAvailable then
try
ImgScan1.OpenScanner;
ImgScan1.ScanTo := 2;
ImgScan1.Image:='c:\MyPicture.gif';
ImgScan1.StartScan ;
Application.ProcessMessages;
finally
ImgScan1.CloseScanner ;
end;

The rest of the code is yours to explore - there is an imgocxd.hlp help on the Kodak Imaging site.

Import an ActiveX Control in Delphi

Here's How:
  1. Start Delphi and select Component | Import ActiveX Control...
  2. Look for an ActiveX control you wish to import (dialog displays the ActiveX controls registered on your system). I will call this control: SomeActiveX
  3. Select the Component palette location in which you want to place selected library.
  4. Maybe the best is to leave the ActiveX option selected.
  5. Click on Install.
  6. Select a package where the new component must be installed or
  7. Create a new package for the new TSomeActiveX control.
  8. Click on OK.
  9. Delphi will prompt you whether you want to rebuild the modified/new package or not.
  10. Click on Yes.
  11. After the package is compiled, Delphi will show you a message saying that the new TSomeActiveX component was registered and already available as part of the VCL.
  12. Close the package detail window, allowing Delphi to save the changes to it.
  13. The component is now available in the ActiveX tab (if you didn't change this setting in step 4)
  14. Drop the component on a form, and simply: use it.

Tips:

  • In step 3, selecting the component palette for new TSomeActiveX component allows you to group controls by function or vendor, for example.
  • The component wrapper is linked into the application executable file (or a runtime package), but the .OCX file for the component also needs to be deployed with the application.
  • ActiveX controls need to be registered on the deployment computer before use. Installation programs such as InstallShield Express automate this registration process.

Sunday, July 20, 2008

Delphi and the Registry

by Christian Feichtner

0. DISCLAIMER :

This article reflects my personal experiences with the registry and Delphi. I had no 'real' documentation on this, except what shipped with Delphi. I will not take any responsibility that occurs from the usage of the procedures described in this article. The same applies to the usage of the accompanying REGDLL.DLL and its interface. USE AT YOUR OWN RISK.

y-database as an 'INI file'. Especially with the advent of Windows 95 every 'good' windows application should use the registry database to store its information.

Note that the described API routines are from the 16bit API. They work well with the registry of Windows 95, but are not capable of using the special new features of Windows 95.

1. What is the registry ?

The registry is a heirarchical database, which is used to store information for the whole system. OLE-apps made frequent use of the registry in Win31. In Windows 95 the registry has grown to more than that. It not only stores system information but has become a total replacement for the old-style INI files. The INI files are only supported to maintain compatibility for 'old' 16bit Apps.

2. What does the registry look like ?

As mentioned above, the registry is a heirarchical database. It is organized as a tree. The most interesting key (and the only one accessable from Delphi with the 16bit version) is the HKEY_CLASSES_ROOT.

This key can be used to store application settings. (Thus, I think there is another key for Windows 95 apps. Since Delphi can only access this key, you can use it until Delphi-32 becomes avaliable).

Example:

 + HKEY_CLASSES_ROOT  This is what a key could look like. Assume an
| application named Information Manager (which I'm
+--+-.IFM currently developing) which saves its files with the
| extension .IFM. Under Win95 the shell, open, command
+--+-shell and ShellNew keys are of special interest. (Yes they
| can be used with Delphi as well.)
+--+-open
| |
| +---command
|
+-ShellNew

.IFM\shell\open\command defines the command to be executed when the user double clicks on the file (or under Win95 hits the right mouse button and selects open).

The keys alone won't do the job. Normally there are values assigned to the keys. Under Win31 these can only be strings. Win95 defines a kind of binary and a DWORD as well.

The shell\open\command normally has a value like:

                            Name          Value
+ HKEY_CLASSES_ROOT
|
+--+-.IFM
|
+--+-shell
|
+--+-open
| |
| +---command (default) "H:\PROJECT\INFOMAN\IFM.EXE %1"
|
+-ShellNew

The selected filename will be substituted for '%1' and passed along as a command-line parameter to the application. Your Delphi app can use PARAMSTR(x) to get the x-th command line parameter. x=0 returns the full path and name of the application itself.

If you are using the preview of Win95 and want your application to have an entry in the 'New' popup menu (something like 'Information Manager 1.0 file'), you have to do the following:

Add a new (text) value for the ShellNew key, named NullFile, with a value of "". Also name the extension (.IFM) equal to the entry of your app in the registry. If the application has an entry named 'InfoMan', then name .IFM as InfoMan.

Example:

                            Name          Value
+ HKEY_CLASSES_ROOT
|
+--+-.IFM (default) "InfoMan"
|
+--+-shell
|
+--+-open
| |
| +---command (default) "H:\PROJECT\INFOMAN\IFM.EXE %1"
|
+-ShellNew NullFile ""

Now for the key for the application itself. (I assume the application is still Information Manager (short: InfoMan)).

The whole tree looks like this:

                            Name          Value
+ HKEY_CLASSES_ROOT
|
+--+-InfoMan (default) "Information Manager 1.0 File"
|
+--+-Misc
|
+--+-Options
| |
| +---Saving
| |
| +---Directories
|
+--+-shell
|
+--+-open
|
+---command (default) "H:\PROJECT\INFOMAN\IFM.EXE %1"

The Options key contains several other subkeys, which store the application- specific settings like the window position, delete confirmations, and others.

3. How to read and write data to the registry

Delphi offers the following API-routines for accessing the registry:

  • RegCreateKey()
  • RegOpenKey()
  • RegDeleteKey()
  • RegCloseKey()
  • RegEnumKey()
  • RegQueryValue()
  • RegSetValue()

NOTE: These functions are from the Win31 API. These functions can only read and write string (PChar) values and can not set the name of a key.

Before a key can be accessed, it must be opened. The open functions return a handle (HKEY), which is used to access the subkeys.

3.1 RegCreateKey()

Opens a key and if the key does not exist, it will be created.

function RegCreateKey(Key: HKey; SubKey: PChar; var Result: HKey): Longint;
Key:
The handle of the key which should be accessed. To write directly under the root, you can use HKEY_CLASSES_ROOT.
SubKey:
The subkey to be accessed.
Result:
The resulting key-handle.
Returns:
ERROR_SUCCESS, if the function was successful, otherwise it will be an error value.

3.2 RegOpenKey()

Opens an existing key. Unlike RegCreateKey, a non existing key returns an error and wi

Thursday, July 17, 2008

Display Like Office 2007 With Delphi

Makes application program with form which is beautiful is a hobby,if you successfully creates beautiful display it is of course will make you to satisfy. Latter the developer is each other race makes application with interface which is beautiful, like microsoft with the one products like the presents a real interface, hardly differing from its former version. Display for office 2007 far prettier. For which has not known possible of you will think how to make it.

In Delphi programming language a lot of components which able to in adding either paying and also free. to make display within reason office 2007 you can apply a component from your devexpress can visit it in www.devexpress.com the component so called Rebbon UI which is tidy one packages with ExpressBars Suite.

If component have been installed will emerge in component pallet

For which has not can do installation of component is better if reads reference Delphi Component Instalation in this blog.

To start it :

  • Open your delphi, here I apply delphi 7
  • input successively dxBarManager, dxBarApplicationMenu, dxRibbon, dxRibbonStatusBar from pallet

display which you obtains :

  • Then double click in component dxBarManager, at tab Toolsbar click new hence will go out dialogue tolbar name contents of for examplely File then click OK then close. Hence will emerge dxBarManager1Bar1 for name can be altered likes it.
  • At windows Objek TreeView searching dxRibbon1 > dxRibbon1Tab1 > Groups, right click at Grroups select chooses add item, hence will emerge TdxRibbon TabGroup.
  • Click at TdxRibbon TabGroup, filled properties ToolBar with dxBarManager1Bar1 which is the had been made, result of its tab will emerge group file.
  • Right click at group new file is made will emerge many items to select, choose at will, here I would will add TdxBarLargeButon from additem.
  • propertis can be changed at will, I will only change propertis caption = setting, Largeglyph with picture . bmp measure 32×32 pixel
  • repeats step of addition of item as in wishs, in example of I will only add TdxBarLargeButon2 with caption = koneksi

result obtained :

  • Adds Menu, create toolBar again like way is upper to names playing or any kind of
  • at propertis aplication Button, menu contents of with dxBarApplicationMenu1
  • at propertis QuickAksesToolBar,ToolBar in contents of with dxBarManager1Bar2 which had been made the.
  • head menu will emerge, beside adds item equal to step of adding above menu item.

Display yielded :

  • To add coding remains double click at items which has been made.

for example :

procedure TForm1.dxBarLargeButton1Click(Sender: TObject);
begin
Form1.Show;
end;

  • Safe tries.






Delphi MySQL Connection With Mydac

In database programming, Connection to a dtabase is a compulsion. in election of database also we given on to some choices. Many the databases with each excellence and weakness. Ok is not necessarily be elaborate here I only study Conection between delphi with database MySQL for excess and lacking of MySQL I will not study here.
  • component install, it is of course you must look for formerly

if it is installed will emerge at panel

this of I apply component MyDAC v510, its the step :

For which has not can do installation of component is better if reads reference Delphi Component Instalation in this blog.

  • Create test database with tables tb_employ field nip, name , adress
  • Open Delphi, enters component MyConnection, MyQuery, DataSource, DBGrid, DBNAVIGATOR.
  • Double click at MyConnection, will emerge dialogue then contents of for example

  • Press Button connect
  • At MyQuery contents of propertis connection with MyConnection1
  • Double click at MyQuery, create Query according to desire for example

  • Changes propertis Active at MyQuery with True
  • At Datasource1 contents of propertis dataset with MyQuery1
  • To interfac to DBGrid and DBNavigator at propertis datasource each component is filled with DataSet1
  • If had incircuit is obtained display
  • Execute program, tries content and saves

result :

  • Good Luck

Delphi Component Installation

One of excess of Delphi is the many visual components and also visual xenon of which we able to obtain in free and also not free. For a who have been skilled it is of course do not become problem but for the newbies of course difficulty would how to install component which we have got. component which we obtain something there are the instaler we ready to click then next until finis, there is also still in the form of package complete with source. therefore I will give input atu tips for installation of component in the form of package.

step of installation :

  • points library path to source component which would in install, its way at menu Tools>Environment Options select, chooses tab library, Button compress right side at library path, enters directori source component which would in installing compress add then OK.
  • steps into component directory which will be installed file searching *. dpk matching with fersi delphi used then double click

  • Depressed compils if success of install compress direct. When install compress sometimes emerges error message expressing component is not designtime which must be done is compress opptions changes Usage options from runtime only becomes Designtime and runtime then OK, compress Instal again.

  • Problem that is often happened between one components with other component is each other related, we meng sequentially install must, if happened the component errors has not there we must install the component beforehand so further.