Friday 25 November 2011
Wednesday 23 November 2011
Tips and Trick Delphi
| November 23, 2011
I finally had a chance too for updates of this blog. This time I want to share about how to connect to the database (Ms. Access) at run-time information on Delphi programming. Run-time means when the program starts, not when the design (design time). The advantage that we make the program more dynamic and we can make changes to the connection when the program is running.
For example, create a database using Ms. Access course, and do not forget to add some sample data in it. To be more afdhol, add a password on that database. Then go to your Delphi and create a new palikasi. Make sure you keep a folder with the database program. To connect to the database, we will use ADO. Add the following components on your form. Are in parentheses is the name of the tab where the component is located.
ADOConnections (ADO)
ADOTable (ADO)
DataSource (Data Access)
DBGrid (Data Controls)
Property 'name' of each component do not need to be replaced, let alone the name of the default. Navigate property 'Connection' from ADOTable1 to 'ADOConnections1', then to select ADOTable1 DataSource1 component in the properties 'DataSet' and to DBGrid1 select DataSource1 on property 'DataSource'. Well now all components are connected to each other, but why the data has not yet appeared in DBGrid? Yes it is so because we do not connect to it with the database. The new connection will be made when the program starts. To this add the following script on the event 'onCreate' your form
TForm1.FormCreate procedure (Sender: TObject); const
namadb = 'data.mdb';
passdb ='';
table = 'tb_barang'; begin
ADOConnection1.ConnectionString: =
'Provider = Microsoft.Jet.OLEDB.4.0;' +
'Data Source =' + ExtractFilePath (application.ExeName) namadb + + ';' +
'Persist Security Info = False;' +
'Jet OLEDB: Database Password =' + passdb;
ADOConnection1.LoginPrompt: = false;
ADOConnection1.Connected: = True;
ADOTable1.TableName: = table;
ADOTable1.Active: = true; end;
Notice in the script above there are three constants each 'namadb' is the name of your database, 'passdb' is the password database, and 'table' is the name of the table in the database. So you need to change its value according to your database.
Because the location of the database is a folder with the program, then in the data source to add the function 'ExtractFilePath (application.ExeName)' to generate the path of the program exe file is located. That way the program is placed anywhere as long as it is a folder with the database then the connection will still point to that database.
Try running your program. If the existing data in the database appear in the DBGrid it works ...
For example, create a database using Ms. Access course, and do not forget to add some sample data in it. To be more afdhol, add a password on that database. Then go to your Delphi and create a new palikasi. Make sure you keep a folder with the database program. To connect to the database, we will use ADO. Add the following components on your form. Are in parentheses is the name of the tab where the component is located.
ADOConnections (ADO)
ADOTable (ADO)
DataSource (Data Access)
DBGrid (Data Controls)
Property 'name' of each component do not need to be replaced, let alone the name of the default. Navigate property 'Connection' from ADOTable1 to 'ADOConnections1', then to select ADOTable1 DataSource1 component in the properties 'DataSet' and to DBGrid1 select DataSource1 on property 'DataSource'. Well now all components are connected to each other, but why the data has not yet appeared in DBGrid? Yes it is so because we do not connect to it with the database. The new connection will be made when the program starts. To this add the following script on the event 'onCreate' your form
TForm1.FormCreate procedure (Sender: TObject); const
namadb = 'data.mdb';
passdb ='';
table = 'tb_barang'; begin
ADOConnection1.ConnectionString: =
'Provider = Microsoft.Jet.OLEDB.4.0;' +
'Data Source =' + ExtractFilePath (application.ExeName) namadb + + ';' +
'Persist Security Info = False;' +
'Jet OLEDB: Database Password =' + passdb;
ADOConnection1.LoginPrompt: = false;
ADOConnection1.Connected: = True;
ADOTable1.TableName: = table;
ADOTable1.Active: = true; end;
Notice in the script above there are three constants each 'namadb' is the name of your database, 'passdb' is the password database, and 'table' is the name of the table in the database. So you need to change its value according to your database.
Because the location of the database is a folder with the program, then in the data source to add the function 'ExtractFilePath (application.ExeName)' to generate the path of the program exe file is located. That way the program is placed anywhere as long as it is a folder with the database then the connection will still point to that database.
Try running your program. If the existing data in the database appear in the DBGrid it works ...
Friday 18 November 2011
Tips and Trick Delphi
| November 18, 2011
Combine multiple string and then split the string into several substrings based on delimiter in delphi 7
finally after so long it could be a bit of time to post a tutorial article. this time I'll make a tutorial for combining multiple string or word into a string. And then returns a string that has been split into several substrings join. possible in the merger we will not find a problem too because it is very easy with just a simple script. eg:
String:=''+string1+' '+string2+'';
but what if we want to separate 2 more strings that have been merged for data editing purposes or other purposes? It was a bit troublesome ..
this kind of thing I had just experienced. where usually I just use the DateTimePicker to present the data in the form of date. But yesterday, I was asked to present date in the form of 3 combobox. Just call each with cbhari, cbbulan, and cbtahun. user menginputkan with 3 combobox the last date the data is stored in a field named date (a string merger process) and if a time is needed to edit the data date, the date that had been deposited into a string should be split again into 3 substrings date. that is to day, month and year. example:
user input date: cbday= 7 cbmonth = April cbyears = 1999
then the data is stored into 7/April/1999. and edit if needed, then the string should be split again into 7/April/1999: cbday = 7 cbmonth = April cbyears= 1999
o yes, here used separator / delimiter sign '/' actual ,';', can also use spaces or other signs .
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
ComboBox3: TComboBox;
ComboBox4: TComboBox;
ComboBox5: TComboBox;
ComboBox6: TComboBox;
Button1: TButton;
Button4: TButton;
Button2: TButton;
procedure Button3Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button3Click(Sender: TObject);
begin
application.Terminate;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
edit1.Text:=”+combobox1.Text+’/'+combobox2.Text+’/'+combobox3.Text+”;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
application.terminate;
end;
procedure TForm1.Button4Click(Sender: TObject);
var
s: string;
sl: TStringList;
begin
sl := TStringList.Create;
s := edit1.Text;
sl.Delimiter := ‘/’;
sl.DelimitedText := s;
combobox4.Text:=sl[0];
combobox5.Text:=sl[1];
combobox6.Text:=sl[2];
//ShowMessage(sl[0]);
end;
end.
Tips and Trick Delphi
| November 18, 2011
How to Easily Create Text To Speech Application Language English (TTS Home) using Delphi
In previous articles have discussed how to actually make the application TextToSpeech English, but it turns out the way it is too difficult actually to make it we could use a more easy way longer and shorter code.
For info this application I created in Borland Delphi 7 and Operating System MS Windows XP SP 2 without installing any component.
Both are now open your Delphi and create a new project.
1. In unit 1 uses clause add ComObj; right under clause Implementation
2. Then make a global variable declarations SpVoice: Variant; on kalusa var or just above clause implementation
Here is a snippet of code header of Unit1
Tips and Trick Delphi
| November 18, 2011
Create a multi user login on Delphi 7
In building an application we are often confronted with cases where the user application consists of several circles or levels of data access. eg, for academic information systems for example, the system is later used by the school principal, teachers, students,. and of course, each job title has different data access, for example, teachers input grades, while students see the value of her on some subjects.
to deal with this case, the diperukan a system that has a multi-user login. so that it can be distinguished, as the admin user, students, teachers or others. The following is one example of a simple solution multi-user login.
with the specifications of the database using MS Access 2003, the second user is a guest and admin, and made use delpi7.
source for the login:
Tips and Trick Delphi
| November 18, 2011
How to Easily Create Text To Speech Application Language English (TTS Home) using Delphi
In previous articles have discussed how to actually make the application TextToSpeech English, but it turns out the way it is too difficult actually to make it we could use a more easy way longer and shorter code.
For info this application I created in Borland Delphi 7 and Operating System MS Windows XP SP 2 without installing any component.
Both are now open your Delphi and create a new project.
1. In unit 1 uses clause add ComObj; right under clause Implementation
2. Then make a global variable declarations SpVoice: Variant; on kalusa var or just above clause implementation
Here is a snippet of code header of Unit1
public
{Public declarations}
end;
var
Form1: TForm1;
SpVoice: Variant;
implementation
ComObj uses;
{$ R *. dfm}
Create a procedure OnCreate of the form (do double-click Form1 then you will be brought to the code editor window) until the complete code for this procedure as follows:
TForm1.FormCreate procedure (Sender: TObject);
begin
SpVoice: = CreateOleObject ('SAPI.SpVoice')
end;
Enter on Form Memo and Button components are located on the Component Palette tab standard
Then make the procedure onClick on the Button component (how to double click the Button then you will be brought to the code editor window) until the complete code for this procedure as follows:
procedure TForm1.Button1Click (Sender: TObject);
begin
SpVoice.Speak (memo1.Text)
end;
Then run it by pressing F9. Done.
Testing. Enter the text in English on memo1 and press Button1. then your application can talk. How much easier is not it?
If there is an easy to make trouble doing?
Tips and Trick Delphi
| November 18, 2011
Connection to the Database When Run-Time
I finally had a chance too for updates of this blog. This time I want to share about how to connect to the database (Ms. Access) at run-time information on Delphi programming. Run-time means when the program starts, not when the design (design time). The advantage that we make the program more dynamic and we can make changes to the connection when the program is running.
For example, create a database using Ms. Access course, and do not forget to add some sample data in it. To be more afdhol, add a password on that database. Then go to your Delphi and create a new palikasi. Make sure you keep a folder with the database program. To connect to the database, we will use ADO. Add the following components on your form. Are in parentheses is the name of the tab where the component is located.
ADOConnections (ADO)
ADOTable (ADO)
DataSource (Data Access)
DBGrid (Data Controls)
Property 'name' of each component do not need to be replaced, let alone the name of the default. Navigate property 'Connection' from ADOTable1 to 'ADOConnections1', then to select ADOTable1 DataSource1 component in the properties 'DataSet' and to DBGrid1 select DataSource1 on property 'DataSource'. Well now all components are connected to each other, but why the data has not yet appeared in DBGrid? Yes it is so because we do not connect to it with the database. The new connection will be made when the program starts. To this add the following script on the event 'onCreate' your form
TForm1.FormCreate procedure (Sender: TObject); const
db_name = 'data.mdb';
passdb ='';
table = 'tb_name'; begin
ADOConnection1.ConnectionString: =
'Provider = Microsoft.Jet.OLEDB.4.0;' +
'Data Source =' + ExtractFilePath (application.ExeName) +db_name + ';' +
'Persist Security Info = False;' +
'Jet OLEDB: Database Password =' + passdb;
ADOConnection1.LoginPrompt: = false;
ADOConnection1.Connected: = True;
ADOTable1.TableName: = table;
ADOTable1.Active: = true; end;
Notice in the script above there are three constants each 'namadb' is the name of your database, 'passdb' is the password database, and 'table' is the name of the table in the database. So you need to change its value according to your database.
Because the location of the database is a folder with the program, then in the data source to add the function 'ExtractFilePath (application.ExeName)' to generate the path of the program exe file is located. That way the program is placed anywhere as long as it is a folder with the database then the connection will still point to that database.
Try running your program. If the existing data in the database appear in the DBGrid it works ...
For example, create a database using Ms. Access course, and do not forget to add some sample data in it. To be more afdhol, add a password on that database. Then go to your Delphi and create a new palikasi. Make sure you keep a folder with the database program. To connect to the database, we will use ADO. Add the following components on your form. Are in parentheses is the name of the tab where the component is located.
ADOConnections (ADO)
ADOTable (ADO)
DataSource (Data Access)
DBGrid (Data Controls)
Property 'name' of each component do not need to be replaced, let alone the name of the default. Navigate property 'Connection' from ADOTable1 to 'ADOConnections1', then to select ADOTable1 DataSource1 component in the properties 'DataSet' and to DBGrid1 select DataSource1 on property 'DataSource'. Well now all components are connected to each other, but why the data has not yet appeared in DBGrid? Yes it is so because we do not connect to it with the database. The new connection will be made when the program starts. To this add the following script on the event 'onCreate' your form
TForm1.FormCreate procedure (Sender: TObject); const
db_name = 'data.mdb';
passdb ='';
table = 'tb_name'; begin
ADOConnection1.ConnectionString: =
'Provider = Microsoft.Jet.OLEDB.4.0;' +
'Data Source =' + ExtractFilePath (application.ExeName) +db_name + ';' +
'Persist Security Info = False;' +
'Jet OLEDB: Database Password =' + passdb;
ADOConnection1.LoginPrompt: = false;
ADOConnection1.Connected: = True;
ADOTable1.TableName: = table;
ADOTable1.Active: = true; end;
Notice in the script above there are three constants each 'namadb' is the name of your database, 'passdb' is the password database, and 'table' is the name of the table in the database. So you need to change its value according to your database.
Because the location of the database is a folder with the program, then in the data source to add the function 'ExtractFilePath (application.ExeName)' to generate the path of the program exe file is located. That way the program is placed anywhere as long as it is a folder with the database then the connection will still point to that database.
Try running your program. If the existing data in the database appear in the DBGrid it works ...
Tips and Trick Delphi
| November 18, 2011
Quick Input Validation in Delphi
Why do I have to say how fast, because this way we no longer need to type the script validation for each field. For more details, for example, we created a form with four Edit and a Button component therein. The fourth example of the field there are three fields are required. Change the property "tag" from the Edit these three components into one, and the others leave it 0. It aims to tell which fields are mandatory and which are not. After that type in the script below. This function will be used for input validation when submit button is clicked.
Notice in the above functions are parameter "frm" of type "TForm". Fill in the name of the form where the fields will be validation for this parameter. For example, add the following script on the event "onClick" your submit button.
procedure TForm1.Button1Click (Sender: TObject); begin
if inputblank (self) then begin
ShowMessage ('There's still an empty field');
exit;
end;
ShowMessage ('Data is stored'); end;
In the example above, the parameter "self" is used for validation on the form itself.
function inputBlank(frm:TForm):boolean; var i: integer; begin result:=false; with frm do begin for i:=0 to ComponentCount-1 do begin if (Components[i] is TEdit)and(Components[i].Tag = 1) then if TEdit(Components[i]).Text = '' then result:=true; end; end; end;
Notice in the above functions are parameter "frm" of type "TForm". Fill in the name of the form where the fields will be validation for this parameter. For example, add the following script on the event "onClick" your submit button.
procedure TForm1.Button1Click (Sender: TObject); begin
if inputblank (self) then begin
ShowMessage ('There's still an empty field');
exit;
end;
ShowMessage ('Data is stored'); end;
In the example above, the parameter "self" is used for validation on the form itself.
Wednesday 16 November 2011
Tips and Trick Delphi
| November 16, 2011
Calculating century - n by a certain date.
Function declaration:
centurycalculate function (const d: TDate): Word;
var
tg, bl, th: Word;
begin
DturecodeDate (D, th, bl, tg);
Result: = th p 100;
end;
Example of implementation:
procedure TForm1.Button1Click (Sender: TObject);
var
d: TDate;
begin
d: = DateTimePicker1.Date;
with Memo1.Lines do
begin
Clear;
Add ('Date' + DateToStr (d) + 'located in the century -' +
IntToStr (HitungAbad (d)));
end;
end;
centurycalculate function (const d: TDate): Word;
var
tg, bl, th: Word;
begin
DturecodeDate (D, th, bl, tg);
Result: = th p 100;
end;
Example of implementation:
procedure TForm1.Button1Click (Sender: TObject);
var
d: TDate;
begin
d: = DateTimePicker1.Date;
with Memo1.Lines do
begin
Clear;
Add ('Date' + DateToStr (d) + 'located in the century -' +
IntToStr (HitungAbad (d)));
end;
end;
Tuesday 15 November 2011
Tips and Trick Delphi
| November 15, 2011
Tricks to know the number of days in a given year.
Function declaration:
/ / Based on Value Year:
totalday function (const t: Word): Integer;
begin
if IsLeapYear (t) then Result: = 366
else Result: = 365;
end;
/ / Based on Date:
totalday Date function (const d: TDate): Integer;
var
tg, bl, th: Word;
begin
DecodeDate (d, th, bl, tg);
Result: = totalday (th);
end;
Example of implementation:
procedure TForm1.Button1Click (Sender: TObject);
begin
Edit1.Text: = IntToStr (totalday (2010));
{When Using Date Time Picker
Edit1.Text: = IntToStr (totalday Date (DateTimePicker1.Date));}
end;
Tips and Trick Delphi
| November 15, 2011
The trick to restart the explorer.exe process was active.
Declaration procedure:
RestartExplorer function: Boolean;
var
wHnd: hWnd;
PID: DWORD;
hProc: THandle;
Exc: DWORD;
begin
wHnd: = FindWindow ('Progman', 'Program Manager');
if wHnd <> 0 then
begin
GetWindowThreadProcessID (wHnd, PID);
hProc: = OpenProcess (PROCESS_QUERY_INFORMATION or PROCESS_TERMINATE, False, PID);
GetExitCodeProcess (hProc, exc);
Result: = TerminateProcess (hProc, exc);
{For some cases, the explorer will automatically execute
himself, but if it fails:
Add WinExec ('explorer', SW_SHOWNORMAL);}
CloseHandle (hProc);
end
else Result: = False;
end;
Example of implementation:
procedure TForm1.Button1Click (Sender: TObject);
begin
if RestartExplorer then ShowMessage ('OK') else ShowMessage ('FAIL');
end;
Binary to Decimal Converter Delphi
| November 15, 2011
Displays time in 24 hour format delphi
24 hours time |
Because the format of the time in our country use format instead of 12h 24h (AM-PM), then there is a good idea to use this format.
Function declaration:
FWaktu24H function (dt: TDateTime): String;
begin
Result: = formatDateTime ('hh: mm: ss', dt);
end;
Example of implementation:
TForm1.Timer1Timer procedure (Sender: TObject);
begin
Label1.Caption: = FWaktu24H (Now);
end;
Tips and Trick Delphi
| November 15, 2011
Simple trick how to prevent a user to input data from in-paste clipboard alias in TEdit and TMemo component.
Thus, the input should only be typed.
The trick is quite simple, you just change the PopupMenu property which is linked to the PopupMenu component is empty. If you do not understand how it can be seen on the page: No PopupMenu the Editor
This trick can also prevent the user to copy the data to the editor to the clipboard.
The trick is quite simple, you just change the PopupMenu property which is linked to the PopupMenu component is empty. If you do not understand how it can be seen on the page: No PopupMenu the Editor
This trick can also prevent the user to copy the data to the editor to the clipboard.
Tips and Trick Delphi
| November 15, 2011
Simple trick to check whether there is a TImage on the image or not (TImage = blank).
Function Declaration:
isTImageEmpty function (img: TImage): Boolean;
begin
if img.Picture.Graphic <> nil then Result: = False else
Result: = True;
end;
Example of implementation:
procedure TForm1.Button1Click (Sender: TObject);
begin
isTImageEmpty if (image1) then ShowMessage ('No image') else
ShowMessage ('There are picture');
end;
Tips and Trick Delphi
| November 15, 2011
Check whether the time is AM or PM by Delphi
Function declaration:
const
time_AM = 1;
time_PM = 2;
timeAMPMcheck function (d: TDateTime): Byte;
var
fd: Real;
begin
fd: = frac (d);
if fd> = 0.5 then Result: = timeWAKTU_PM else Result: = time_AM;
end;
Example of implementation:
procedure TForm1.Button1Click (Sender: TObject);
var
sAMPM: String;
begin
case timeAMPMcheck (Now) of
time_AM: sAMPM: = 'AM';
time_PM: sAMPM: = 'PM'
end;
ShowMessage (sAMPM);
end;
Tips and Trick Delphi
| November 15, 2011
Command how to clear (clear) image.
Give the command picture: = nil in TImage
example:
procedure TForm1.Button1Click (Sender: TObject);
begin
Image1.Picture: = nil;
end;
Example # 2:
procedure TForm1.Button1Click (Sender: TObject);
begin
if OpenDialog1.Execute then
begin
Image1.Picture.LoadFromFile (OpenDialog1.FileName);
end;
end;
procedure TForm1.Button2Click (Sender: TObject);
begin
Image1.Picture: = nil;
end;
Tips and Trick Delphi
| November 15, 2011
Prevent the user closes the form by pressing the Alt + F4.
Edit event OnCloseQuery:
TForm1.FormCloseQuery procedure (Sender: TObject; var CanClose: Boolean);
begin
CanClose: = False;
end;
Tips and Trick Delphi
| November 15, 2011
How to calculate the day on different dates.
Function declaration:
differencedate function (TglOld, TglNew: TDate): Integer;
begin
Result: = trunc (TglNew - TglOld);
end;
Example of implementation:
procedure TForm1.Button1Click (Sender: TObject);
begin
Edit1.Text: = IntToStr (differencedate (DateTimePicker1.Date, DateTimePicker2.Date));
end;
Tips and Trick Delphi
| November 15, 2011
The trick to limit the movement of a cursor on a specific window handle.
Declaration procedure:
LockCursorTo procedure (targetHwnd: hWnd);
var
r: TRect;
begin
if targetHwnd <> 0 then
begin
GetWindowRect (targetHwnd, r);
ClipCursor (@ r);
end
ClipCursor else (nil);
end;
Example of implementation:
procedure TForm1.Button1Click (Sender: TObject);
begin
LockCursorTo (Button2.Handle);
end;
To restore the cursor function kesediakala, targetHwnd parameter set to 0. example:
procedure TForm1.Button2Click (Sender: TObject);
begin
LockCursorTo (0);
end;
Tips and Trick Delphi
| November 15, 2011
Tricks MessageBox displays a message when the form on the close. This way when we give a close form, the message will be displayed.
Edit event on FormCloseQuery:
TForm1.FormCloseQuery procedure (Sender: TObject; var CanClose: Boolean);
begin
if MessageBox (Handle, 'Get out of the application?', 'Confirmation',
MB_ICONQUESTION MB_YESNO +) = idYes then
CanClose: = True
else
CanClose: = False;
end;
Tips and Trick Delphi
| November 15, 2011
Tricks to hide the main form when the application runs.
Edit the project source (Select the menu View - Project Source), add lines of code:
Application.ShowMainForm: = False;
Full as follows:
begin
Application.Initialize;
Application.ShowMainForm: = False;
Application.CreateForm (TForm1, Form1);
Application.Run;
end.
Tips and Trick Delphi
| November 15, 2011
Tricks to hide the cursor in our application. This technique is often used in making a screen saver.
To hide use the function:
ShowCursor (False);
Meanwhile, to display it again using the function:
ShowCursor (True);
Tips and Trick Delphi
| November 15, 2011
Default Printer Name Reading the default printer.
Function declaration:
PrinterDef function: string;
var
sStr: array [0 .. 255] of Char;
begin
GetProfileString ('Windows', 'device','', sStr, 255);
Result: = StrPas (sStr);
end;
Example of implementation:
procedure TForm1.Button1Click (Sender: TObject);
begin
Edit1.Text: = PrinterDef;
end;
default printer name delphi |
Tips and Trick Delphi
| November 15, 2011
The trick to take the separate (split) "date", "month" and "years" of the input type TDate.
Function declaration:
type
rDate = record
cdate: Byte;
cmonth: Byte;
cyears: Integer;
end;
function splitdate (Date: TDate): rDate;
var
date, month, year: Word;
begin
DecodeDate (date, year, month, date);
with Result do
begin
cdate = date;
cmonth: = month;
cyears: = yr;
end;
end;
Example of implementation:
procedure TForm1.Button1Click (Sender: TObject);
var
D: rDate;
begin
D: = splitdate(DateTimePicker1.Date);
with Memo1.Lines do
begin
Clear;
Add ('Date =' + IntToStr (D.cdate));
Add ('Month =' + IntToStr (D.cmonth));
Add ('Year =' + IntToStr (D.cyears));
end;
end;
Tips and Trick Delphi
| November 15, 2011
How to display the windows start menu, without clicking the start button.
Declaration procedure:
ShowStartMenu procedure;
var
hSMenu: HWND;
begin
hSMenu: = FindWindow ('DV2ControlHost', 'Start Menu');
ShowWindow (hSmenu, SW_RESTORE);
end;
Examples of Implementation:
Procedure TForm1.Button1Click (Sender: TObject);
begin
ShowStartMenu;
end;
Tips and Trick Delphi
| November 15, 2011
how to Reverse String in Delphi
Function to reverse a String, for example, the string "Delphi" will become "ihpleD".
Function Declaration:
Strback function (IVI: String): String;
var
l: Integer;
begin
for i: = Length (IVI) downto 1 do
begin
Result: = Result + IVI [l];
end;
end;
Examples of Implementation:
procedure TForm1.Button1Click (Sender: TObject);
begin
Edit2.Text: = Strback (Edit1.Text);
end;
Tips and Trick Delphi
| November 15, 2011
FreeReport : FreeReport is reporting tool component. It consists of report engine, designer and preview. Its capabilities comparable with in QuickReport 3, ReportBuilder 3.52.
Capabilities of this component :
- Band-oriented report generator.
- Build-in powerful designer, also available in run-time.
- Preview like in MS Word.
- Fast like QuickReport1.
- Compact code – w/o designer smaller than QR1.
- Unlimited number of pages in prepared report.
- Multi-page reports; composite reports; subreports; groups; multi-column reports; master-detail-detail reports; cross-tab reports; two-pass reports.
- Full control over printing process; support all paper sizes.
- Set of most useful components: Text, Line, Picture, Shape, OLE object,
- RichText, RX Rich 2.0, Chart, Barcode.
- TXT, RTF, CSV, HTML export.
- Text search in prepared report.
- Add-in component TfrDataStorage intended for creating tables and queries
- in run-time like QRDesigner does. Especially for end-user reports. Supports
- Interbase Express (IBX) and ActiveX Data Objects (ADO).
- Editing pages of prepared report.
- Build-in Pascal-like interpreter for handling of building process.
- Report form can store in DFM resources, external file, BLOb field of DB table, or in stream.
- Ability of expanding functionality by own report components, wizards,
- function libraries.
Author: Alexander Tzyganenko
Tips and Trick Delphi
| November 15, 2011
ZeosDBO: a database middleware components for Borland development tools, including Delphi, C++ Builder and Kylix. Direct access to SQL databases continues to be a vital technology even in today’s enterprise environment.
thousands of two-tier client server applications are developed and maintained in the international business community. Most of them are built off of specially designed application programming interfaces (APIs) to retrieve relational data and execute SQL statements.
Currently, there is several standardized and widely used APIs to access SQL databases, such as ODBC, JDBC, and ADO. Borland also released their proprietary database middleware interface for its development tools, called the Borland Database Engine (BDE). Despite being freely distributed with Borland’s popular line of application development tools, the BDE was unpopular because of complexities in installation and poor performance. As Delphi became one of the leading application development tools for the Windows platform, individuals and companies proposed alternative interfaces to the BDE. These “BDE Alternatives” optimized access to the database by directly using the native database driver, providing performance and feature advantages with respect to the BDE.
Realizing the limitations of the BDE, Borland proposed a new type of database interface called dbExpress. This interface was designed to broker access between Delphi and virtually any relational database through 3rd party drivers. Borland significantly improved the performance of dbExpress with respect to the BDE, but the implementation was buggy and supported only a limited subset of SQL that hampered functionality.
The Zeos Database Object component library (ZeosLib) is one of the best-known BDE alternatives. Originally the library was developed for MySQL and PostgreSQL databases, but support for other vendors was soon added. During the development process, certain limitations of the original design became more and more apparent. These limitations began to put a strain on the overall architecture and the development team decided a ground up rewrite was the best way to proceed. The new design was built to handle an extended feature list with several new requirements:
- Support for different compilers
- Versioning database driver system
- “Database Insensitive” design for cross-database development
- Support for multiple high level interfaces (TDataset, dbExpress, Midas)
- Extensible feature system for server specific support
The following compilers are supported:
- Delphi 5 – 7 and 9-11
- Lazarus (FreePascal)
- MSEide+MSEgui (FreePascal)
- C++ Builder 5 – 6
- Kylix 2 – 3
- MySQL 3.20 – 5.0
- PostgreSQL 6.5 – 8.1
- Firebird 1.0 – 2.0
- Interbase 5.0 – 7.5
- Microsoft SQL Server 7, 2000
- Sybase ASE 12.0, 12.5
- Oracle 9i
- SQLite 2.8, 3.5
- Platform independance. The ZeosDBO is highly generic. Applications written in ZeosDBO can be migrated across databases without major changes.
- ZeosDBO is open source, written for usability and extensibility.
- ZeosDBO leverages the amazing power of the Delphi development environment without relying on a performance killing middleware.
- ZeosDBO is an extremely thin abstraction layer, unlike ‘thick’ layered protocols like ADO and BDE.
- ZCore – Core classes and interfaces. Contains Java style objects and collections as well as compatibility types and functions.
- ZParseSql – SQL specific for syntax and lexical analysis.
- ZPlain – Native plain API to supported SQL servers.
- ZDbc – Port of Java Database Connectivity API (JDBC 2.0). DBC API acts as intermediate layer between Plain API and highlevel TDataset or DBExpress components
- ZComponent – visual components descended from TDataset.
- ZComponentDesign – design time components. This package is not available for all compilers. If present it’s only needed to install the components in the IDE.
- TZConnection: This component encapsulates the database connection and transaction management.
- TZReadOnlyQuery: TDataset component to execute SQL queries and process data in read-only mode.
- TZQuery: TDataset component which allows data modifications in regular and cached mode.
- TZUpdateSQL: Analog of standard TUpdateSQL component to explicite definition of Insert/Update/Delete SQL statements for TDataset modifications.
- TZStoredProc: The component to execute SQL stored procedures.
- TZSQLProcessor: The component to execute SQL scripts for different SQL and various delimiter types.
- TZSQLMonitor: The component to monitor all outgoing SQL queries and other logging information.
- TZSQLMetadata: Specialized TDataset component which provides an access to database metadata such as tables, columns, indices, etc.
Author : Zeos Development Group
Tips and Trick Delphi
| November 15, 2011
KSScheme by Evgeny A. Kryukov Scheme is an VCL library that allows you to dynamically change almost any aspect of the visual appearance your project’s forms or controls. In short, it provides you with full support for application skins.
Now your programs can have:
- dynamically resizable windows
- skins for window captions, frames, client and non-client areas
- skins support for buttons
- run-time skin change
- It’s even possible to make your program look like an application from any other OS, or create your own user WindowBlinds-like or NeoPlanet-like “skinned” interface.
- dynamically resizable windows
- skins for window captions, frames, client and non-client areas
- skins support for buttons
- run-time skin change
Tips and Trick Delphi
| November 15, 2011
Saving Graphic Files JPEG With Different Quality by Delphi
Example of storing graphics into JPEG files which is different from the original picture quality by using a TImage.
Declaration procedure:
SaveJPGWQ procedure (img: TImage; q: TJPEGQualityRange; FDest: TFileName);
var
iJPG: TJPEGImage;
iBMP: TBitmap;
begin
iJPG: = TJPEGImage.Create;
try
if img.Picture.Graphic <> nil then
begin
if img.Picture.Graphic is TBitmap then iJPG.Assign (img.Picture.Graphic)
else
begin
iBMP: = TBitmap.Create;
try
iBMP.Assign (img.Picture.Graphic);
iJPG.Assign (iBMP);
finally
iBMP.Free;
end;
end;
with iJPG do
begin
CompressionQuality: = q;
Compress;
SaveToFile (FDest);
end;
end;
finally
iJPG.Free;
end;
end;
To set the image quality, use the parameter q. Its scope is [1 .. 100] with the assumption that the greater value is given then the image quality of the original will remain intact and vice versa.
*) Add the clause uses the JPEG unit.
Example of implementation:
procedure TForm1.Button1Click (Sender: TObject);
begin
SaveJPGWQ (image1, 80, 'C: \ JPG1.JPG');
end;
Example implementations # 2 (using TTrackBar and TSaveDialog):
procedure TForm1.Button2Click (Sender: TObject);
begin
if Image1.Picture.Graphic <> nil then
begin
if SaveDialog1.Execute then
begin
SaveJPGWQ (image1, TrackBar1.Position, SaveDialog1.FileName);
end;
end;
end;
Tips and Trick Delphi
| November 15, 2011
XPMenu : Change the visual aspects of menus, toolbars and many other controls to nearly the same look and feel of MS Office XP.
XP Menu is a none-visual component that changes the visual aspects of menus, toolbars and many other controls to nearly the same look and feel of MS Office XP. No code required, you do not have to reconstruct menus or toolbars using controls other than those shipped with Delphi.
Author: Khaled Shagrouni
Tips and Trick Delphi
| November 15, 2011
Creating a Full Screen Form on Delphi
Trick display the form to be full screen, follow the width and height of the screen.
Edit the Form OnCreate event or onShow:
TForm1.FormCreate procedure (Sender: TObject);
begin
BorderStyle: = bsNone;
WindowState: = wsMaximized;
Width: = Screen.Width;
Height: = Screen.Height;
end;
Tips and Trick Delphi
| November 15, 2011
The "0" Auto number in front of Numbers
Numbering function by adding the number '0 'in front of the numbers. For example the maximum number is 1000, then you have the number 10, then the number 10 was going to set to 0010.
Function declaration:
autonumber_0 function (value, Maksvalue: Integer): String;
var
sNum: String;
begin
Result: = '0 ';
sNum: = IntToStr (value);
sNum: = StringOfChar ('0 ', Length (IntToStr (Maksvalue)) - Length (sNum)) + sNum;
Result: = sNum;
end;
Example of implementation:
procedure TForm1.Button1Click (Sender: TObject);
var
i, max: Integer;
begin
max: = 10;
for i: = 1 to max do
begin
ListBox1.Items.Add (autonumber_0 (i, max) + '. Numbers #' + IntToStr (i));
end;
end;
Tips and Trick Delphi
| November 15, 2011
How to Convert Graphic to File PNG
Converting existing image on a TImage (can be a TBitmap, TJPEG) into PNG format and then save them into PNG files.
Declaration procedure:
TImageToPNG procedure (Src: TImage; const Dst: String);
var
PNG: TPNGObject;
BMP: TBitmap;
begin
PNG: = TPNGObject.Create;
try
/ / If the TImage a TBitmap, directly converted to PNG
if Src.Picture.Graphic is TBitmap then
PNG.Assign (TBitmap (Src.Picture.Graphic))
else
begin
/ / If the TImage is not a TBitmap, the first convert to a TBitmap, and then to PNG
BMP: = TBitmap.Create;
try
BMP.Assign (Src.Picture.Graphic);
PNG.Assign (BMP);
finally
BMP.Free;
end;
end;
/ / Save a File
PNG.SaveToFile (Dst);
finally
PNG.Free;
end
end;
Make sure TPNGImage already integrated with your Delphi