D E L P H I 's Search Engine : FunnyLogo.info : Personal Search Engine Maker of Style Yahoo

 

Web ImagesVideoNewsMapsBooks More»
 
 Advanced Search
 Preferences
 Language Tools


BookMark     Create your own Search Engine Now


FunnyLogo is not affiliated with Google Inc.
Trademarks remain trademarks of their respective companies.
© 2007 FunnyLogo

Sedo - Buy and Sell Domain Names and Websites project info: funnylogo.info Statistics for project funnylogo.info etracker® web controlling instead of log file analysis

Senin, 26 November 2007

Koneksi SQL Server via ADODB

Delphi 7 menyediakan beberapa cara untuk koneksi ke database SQL Server 7/2000. Salah satunya adalah menggunakan komponen ADODB yaitu ADOConnection.
Bagaimana cara mensetting dan menggunakan komponen tersebut ? Mari kita buat program sederhana berikut ini.


























Komponen ADOConnection1 bisa diambil di tab ADO pada Component Pallette.




Atur properti masing-masing object sbb:

frmKoneksi : BorderStyle=bsDialog | Caption=Koneksi SQL Server via ADODB | Position=poScreenCenter
txtServerName : Text=127.0.0.1
txtUserName : Text=sa
txtUserPass : Text= | PasswordChar=*
txtDatabase : Text=northwind
btnTes : Caption=Tes Koneksi
ADOConnection1 : LoginPrompt=false

Klik ganda btnTes dan ketik program berikut:















Selesai ! Mudah bukan ?? Coba run project tersebut lalu klik Tes Koneksi. Jika SQL Server sudah running, maka program menampilkan messagebox Koneksi berhasil, sebaliknya program akan menampilkan messagebox Koneksi gagal dengan kemungkinan penyebabnya:

- SQL Server belum running
- Nama server atau IP Address salah atau LAN terputus
- User Name dan/atau Password salah
- Nama database tidak ditemukan

Sekarang mari kita bahas tentang ADO khususnya komponen ADOConnection yang kita gunakan tadi. Sedikit cerita, ADO merupakan singkatan dari ActiveX Dataset Objects buatan Microsoft. ADO adalah sekumpulan library yang dapat digunakan untuk mengakses berbagai macam format basis data yang terkenal, mulai dari kelas file seperti dBase, Paradox hingga yang sekelas server seperti SQL Server dan Oracle. Karena berupa ActiveX maka komponen ADO netral terhadap bahasa pemrograman, artinya, apapun bahasa pemrograman yang Anda gunakan asalkan bahasa tersebut bisa memanggil ActiveX maka ADO bisa digunakan (jadi inget Teh Sosro). Otomatis, bahasa pemrograman visual terkini seperti Delphi, VB, Visual FoxPro, Visual C++,bisa menggunakan komponen ADO tersebut.

Delphi 7 menjajarkan komponen ADO pada tab ADO di Component Palette-nya. Disitu terdapat komponen ADOConnection, ADOCommand, ADODataSet, ADOTable, ADOQuery, ADOStoredProc dan RDSConnection.

Khusus untuk membuka koneksi ke database, gunakan komponen ADOConnection. Properti yang harus di-set adalah ConnectionString. ADOConnection membaca properti ini sebagai konfigurasi untuk membuka koneksi. ConnectionString terdiri dari beberapa parameter yang masing-masing dipisah dengan titik-koma. Untuk koneksi ke SQL Server, parameter-parameter tersebut adalah:

Provider=SQLOLEDB.1
Provider adalah nama driver yang akan digunakan oleh ADO untuk membuka koneksi. Nama driver SQL Server adalah SQLOLEDB.1
Persist Security Info=False
Jika parameter ini True, maka ADO akan menggunakan user account yang terdaftar pada sistem operasi server. Jika False, ADO menggunakan user account internal SQL Server. Parameter ini berkaitan erat dengan parameter User ID dan Password
User ID=
User ID yang digunakan untuk login ke SQL Server. Jika parameter Persist Security Info=True, user id yang diisi harus sesuai dengan user account sistem operasi, sebaliknya jika False, user id harus sesuai dengan user account internal SQL Server. Jika belum diganti, user id default SQL Server adalah sa
Password=
Password yang digunakan untuk login ke SQL Server. Parameter ini diberlakukan sama seperti halnya parameter User ID. Jika belum diganti, password ini kosong, artinya Anda bisa login tanpa menggunakan password dengan User ID sa tersebut. Untuk kasus sebenarnya, sebaiknya ganti password ini
Initial Catalog=
Isi parameter ini dengan nama database yang hendak dikoneksikan
Data Source=
ADO bisa membuka koneksi dengan mencari nama server ataupun IP addressnya. Sebaiknya gunakan nama server, karena nama server cenderung jarang diganti dibandingkan IP address. Jika SQL Server berada pada kompi yang sama dengan program aplikasi, nama server bisa menggunakan localhost atau IP 127.0.0.1

Kembali ke program kita, jika Nama Server diisi 127.0.0.1 , User Name Database diisi sa, Password Database dikosongkan, Nama Database diisi northwind lalu tombol Tes Koneksi diklik, maka program otomatis akan membentuk ConnectionString :

Provider=SQLOLEDB.1; Persist Security Info=False;User ID=sa;Password=;Initial Catalog=northwind;Data Source=127.0.0.1

Selanjutnya string tersebut diaplikasikan pada komponen ADOConnection1 dan membuka koneksi dengan memanggil method ADOConnection1.Open (lihat baris 46-55)

Sudah mendapat pencerahan ? Semoga tulisan ini cukup membantu…


Read more.....

Kamis, 15 November 2007

Mencegah aplikasi ditutup dengan Alt-F4

private
procedure AppMessage(var Msg: TMSG; var Handled: Boolean);
public
{ Public declarations }
end;


implementation


procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMessage := AppMessage;
end;


procedure TForm1.AppMessage(var Msg: TMSG; var Handled: Boolean);
begin
// meng-handle pesan
Handled := False;
case Msg.Message of
WM_SYSKEYDOWN:
if Msg.wParam = VK_F4 then
Handled := True; // cegah Alt-F4
end;
end;


Read more.....

Mengganti nama direktori

procedure TForm1.BtnSelectClick(Sender: TObject);
var DirTemp: string;
begin
DirTemp:=GetCurrentDir;
if SelectDirectory(DirTemp, [], 1000) then
begin
Panel1.Caption := DirTemp;
Edit1.Text := DirTemp;
end;
end;


procedure TForm1.BtnRenameClick(Sender: TObject);
begin
if DirectoryExists(Panel1.Caption) then
begin
RenameFile(Panel1.Caption, Edit1.Text);
Panel1.Caption := Edit1.Text;
end;
end;



Read more.....

Fungsi Terbilang pada Borland Delphi

Fungsi terbilang adalah suatu fungsi sederhana yang berguna untuk mengkonversikan dari angka ke dalam format huruf (terbilang) seperti halnya yang sering Anda lihat pada kuitansi.


Berikut ini adalah fungsi terbilang-nya.

function Terbilang(x:integer):string;
const
abil : array[0..11] of string[10]=('','satu','dua','tiga',
'empat','lima','enam','tujuh','delapan','sembilan',
'sepuluh','sebelas');

begin
if (x < 12) then
Result := ' ' + abil[x]
else
if (x < 20) then
Result := Terbilang(x-10) + ' belas'
else
if (x < 100) then
Result := Terbilang(x div 10) + ' puluh' + Terbilang(x mod 10)
else
if (x < 200) then
Result := ' seratus' + Terbilang(x-100)
else
if (x < 1000) then
Result := Terbilang(x div 100) + ' ratus' + Terbilang(x mod 100)
else
if (x < 2000) then
Result := ' seribu' + Terbilang(x-1000)
else
if (x < 1000000) then
Result := Terbilang(x div 1000) + ' ribu' + Terbilang(x mod 1000)
else
if (x < 1000000000) then
Result := Terbilang(x div 1000000) + ' juta' + Terbilang(x mod 1000000);
end;

Silakan saja Anda coba fungsi di atas pada Borland Delphi. Penulis sudah mencobanya pada Delphi 6.0. Demikianlah tulisan singkat mengenai fungsi terbilang pada Borland Delphi. Semoga bermanfaat bagi Anda semua

Silakan download source code lengkap dari project di atas

Read more.....

Sabtu, 10 November 2007

Get Start Menu Directory

This function used to get start menu directory.

uses shlobj;

function GetStartMenu: String;
var
dir: PItemIDList;
startmenu : array[0..MAX_PATH] of Char;
begin
SHGetSpecialFolderLocation(Application.handle, CSIDL_STARTMENU, dir);
SHGetPathFromIDList(dir, startmenu);
result := strpas(startmenu);
end;


procedure TForm1.BitBtn1Click(Sender: TObject);
begin
Edit1.Text := GetStartMenu;
end;

Download: Source Code

Read more.....

Minimize all windows

You can minimize all windows with this code snippets.

procedure MinimizeAll;
var
h:HWnd;
begin
h:=handle;
while h > 0 do
begin
if IsWindowVisible(h) then
Postmessage(h,WM_SYSCOMMAND,SC_MINIMIZE,0);
h:=GetnextWindow(h,GW_HWNDNEXT);
end;
end;



Read more.....

Close all the open Internet Explorer windows

Use this to close all open Internet Explorer windows.

var
IExplorer: Thandle;
begin
IExplorer := FindWindow('’ IEFrame ‘’, nil);
if IExplorer <> 0 then
SendMessage(IExplorer, WM_SYSCOMMAND, SC_CLOSE, 0);

The FindWindow function retrieves the handle to the top-level window whose class name and window name match the specified strings. This function does not search child windows.

HWND FindWindow(

LPCTSTR lpClassName, // pointer to class name
LPCTSTR lpWindowName // pointer to window name
);


Parameters

lpClassName

Points to a null-terminated string that specifies the class name or is an atom that identifies the class-name string. If this parameter is an atom, it must be a global atom created by a previous call to the GlobalAddAtom function. The atom, a 16-bit value, must be placed in the low-order word of lpClassName; the high-order word must be zero.

lpWindowName

Points to a null-terminated string that specifies the window name (the window’s title). If this parameter is NULL, all window names match.

Return Values

If the function succeeds, the return value is the handle to the window that has the specified class name and window name.
If the function fails, the return value is NULL. To get extended error information, call GetLastError

Read more.....

Empty Recycle Bin

Procedure to empty recycle bin

Procedure EmptyRecycleBin ;
Const
SHERB_NOCONFIRMATION = $00000001 ;
SHERB_NOPROGRESSUI = $00000002 ;
SHERB_NOSOUND = $00000004 ;
Type
TSHEmptyRecycleBin = function (Wnd : HWND;
pszRootPath : PChar;
dwFlags : DWORD
) : HRESULT; stdcall ;
Var
SHEmptyRecycleBin : TSHEmptyRecycleBin;
LibHandle : THandle;
Begin { EmptyRecycleBin }
LibHandle := LoadLibrary(PChar(’Shell32.dll’)) ;
if LibHandle <> 0 then
@SHEmptyRecycleBin := GetProcAddress(LibHandle, ‘SHEmptyRecycleBinA’)
else
begin
MessageDlg(’Failed to load Shell32.dll.’, mtError, [mbOK], 0);
Exit;
end;


if @SHEmptyRecycleBin <> nil then
SHEmptyRecycleBin(Application.Handle,
nil,
SHERB_NOCONFIRMATION or SHERB_NOPROGRESSUI or SHERB_NOSOUND);
FreeLibrary(LibHandle);
@SHEmptyRecycleBin := nil ;
end; { EmptyRecycleBin }

Read more.....

Convert JPG to BMP

With this procedure below you can convert JPT to BMP.

Procedure ConvertJPGtoBMP;
var
jpeg: TJPEGImage;
bmp: TBitmap;
Begin
jpeg:= TJPEGImage.Create;
try
jpeg.LoadFromFile( filename );
bmp:= TBitmap.Create;
try
bmp.Assign( jpeg );
bmp.SaveTofile( ChangeFileExt( filename, ‘.BMP’ ));


finally
bmp.free
end;
finally
jpeg.free
end;
end;
Related Posts

Read more.....

Convert BMP to JPG

procedure ConvertBMPtoJPG;
var
bmp : TImage;
jpg : TJpegImage;
begin
bmp := TImage.Create(nil);
jpg := TJpegImage.Create;
bmp.picture.bitmap.LoadFromFile ( ‘c:\picture.bmp’ );
jpg.Assign( bmp.picture.bitmap );


// Here you can set the jpg object’s properties as compression, size and more
jpg.SaveToFile ( ‘c:\picture.jpg’ );
jpg.Free;
bmp.Free;
end;

Read more.....

How to make a desktop screenshot?

function GetDesktopScreenShot:TBitmap;
var
Desktop:HDC;
begin
Result:= TBitmap.Create;
Desktop:= GetDC(0);
try
try
Result.PixelFormat := pf32bit;
Result.Width := Screen.Width;
Result.Height := Screen.Height;
BitBlt(Result.Canvas.Handle,0,0, Result.Width, Result.Height, Desktop,0,0,SRCCOPY);
Result.Modified := True;
finally
ReleaseDC(0,Desktop);
end;
except
Result.Free;
Result:=nil;
end;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
Image1.Picture.Bitmap := GetDesktopScreenShot;
end;

Read more.....

Hide the window caption

If you want to prevent the user to move a window you have to hide the caption. This is done by changing the window attributes in the FormCreate event. Its also possible to set the property BorderStyle to ‘bsNone’, but than the window has no frame at all.
procedure TForm1.FormCreate(Sender: TObject);
begin
SetWindowLong(Handle, GWL_STYLE, GetWindowLong(Handle,GWL_STYLE) AND
NOT WS_CAPTION);
ClientHeight := Height;
Refresh;
end;


This code is disableing the flag WS_CAPTION in the window attributes.

The SetWindowLong function changes an attribute of the specified window. The function also sets a 32-bit (long) value at the specified offset into the extra window memory of a window.

LONG SetWindowLong(

HWND hWnd, // handle of window
int nIndex, // offset of value to set
LONG dwNewLong // new value
);

Read more.....

Hide the titlebar

Hide the titlebar.

Procedure TForm1.HideTitlebar;
var
Save : LongInt;
Begin
If BorderStyle=bsNone then Exit;
Save:=GetWindowLong(Handle,gwl_Style);
If (Save and ws_Caption)=ws_Caption then Begin
Case BorderStyle of
bsSingle,
bsSizeable : SetWindowLong(Handle,gwl_Style,Save and
(Not(ws_Caption)) or ws_border);
bsDialog : SetWindowLong(Handle,gwl_Style,Save and
(Not(ws_Caption)) or ds_modalframe or ws_dlgframe);
End;
Height:=Height-getSystemMetrics(sm_cyCaption);
Refresh;
End;
end;


And here is how we show it again:
Procedure TForm1.ShowTitlebar;
Var
Save : LongInt;
begin
If BorderStyle=bsNone then Exit;
Save:=GetWindowLong(Handle,gwl_Style);
If (Save and ws_Caption)<>ws_Caption then Begin
Case BorderStyle of
bsSingle,
bsSizeable : SetWindowLong(Handle,gwl_Style,Save or
ws_Caption or ws_border);
bsDialog : SetWindowLong(Handle,gwl_Style,Save or
ws_Caption or ds_modalframe or ws_dlgframe);
End;
Height:=Height+getSystemMetrics(sm_cyCaption);
Refresh;
End;
end;

Read more.....

How to Create a Gradient Filled Form

You can create a gradient filled form to make form that is more beautiful.

procedure TForm1.FormPaint(Sender: TObject);
var
Row, Ht: Word;
begin
Ht := (ClientHeight + 255) div 256;
for Row := 0 to 255 do
with Canvas do
begin
Brush.Color := RGB(Row, 100, 0);
FillRect(Rect(0, Row*Ht, ClientWidth, (Row+1) * Ht));
end;
end;

You can change the value of (Row, 100, 0) to suite your preferences.

Example:

(Row, 255, 0) or (Row, 100, 255)


Download: Source Code

Read more.....

How to Create Rounded Form

procedure TForm1.FormCreate(Sender: TObject);
var
f : HRGN;
begin
Form1.Borderstyle := bsNone;
f := CreateRoundRectRgn(
0, // x-coordinate of the region’s upper-left corner
0, // y-coordinate of the region’s upper-left corner
clientwidth, // x-coordinate of the region’s lower-right corner
clientheight, // y-coordinate of the region’s lower-right corner
40, // height of ellipse for rounded corners
40); // width of ellipse for rounded corners
SetWindowRgn(Handle,f,True);
end;

Download: Source Code

Read more.....

Extract an Icon From Application

procedure TForm1.Button1Click(Sender: TObject);
var
MyIcon : TIcon;
begin
if Opendialog1.Execute then
begin
MyIcon := TIcon.Create;
MyIcon.Handle := ExtractIcon(hInstance, PChar(Opendialog1.filename),0);
DrawIcon(Form1.Canvas.Handle, 10, 10,
MyIcon.Handle);
MyIcon.Free;
end;
end;

Read more.....

Get Windows Temporary Folder

If you need to get windows temporary folder for your application you need to follow this steps.

function GetTempDirectory: String;
var
TempDir: array[0..255] of Char;
begin
GetTempPath(255, @TempDir);
Result := StrPas(TempDir);
end;


procedure TForm1.BitBtn1Click(Sender: TObject);
begin
label1.Caption := gettempdirectory;
end;

Silahkan download aplikasinya

Read more.....

Borland Database Engine (BDE) Error List

Here Borland Database Engine (BDE) error list:

$0000 (0) = Successful completion.

$0021 (33) = System Error

$0022 (34) = Object of Interest Not Found

$0023 (35) = Physical Data Corruption

$0024 (36) = I/O Related Error

$0025 (37) = Resource or Limit Error

$0026 (38) = Data Integrity Violation

$0027 (39) = Invalid Request

$0028 (40) = Lock Violation

$0029 (41) = Access/Security Violation

$002A (42) = Invalid Context

$002B (43) = OS Error

$002C (44) = Network Error

$002D (45) = Optional Parameter

$002E (46) = Query Processor

$002F (47) = Version Mismatch

$0030 (48) = Capability Not Supported

$0031 (49) = System Configuration Error

$0032 (50) = Warning

$0033 (51) = Miscellaneous

$0034 (52) = Compatibility Error

$003E (62) = Driver Specific Error

$003F (63) = Internal Symbol

$2101 (8449) = Cannot open a system file.

$2102 (8450) = I/O error on a system file.

$2103 (8451) = Data structure corruption.

$2104 (8452) = Cannot find Engine configuration file.

$2105 (8453) = Cannot write to Engine configuration file.

$2106 (8454) = Cannot initialize with different configuration file.

$2107 (8455) = System has been illegally re-entered.

$2108 (8456) = Cannot locate IDAPI32 .DLL.

$2109 (8457) = Cannot load IDAPI32 .DLL.

$210A (8458) = Cannot load an IDAPI service library.

$210B (8459) = Cannot create or open temporary file.

$2201 (8705) = At beginning of table.

$2202 (8706) = At end of table.

$2203 (8707) = Record moved because key value changed.

$2204 (8708) = Record/Key deleted.

$2205 (8709) = No current record.

$2206 (8710) = Could not find record.

$2207 (8711) = End of BLOB.

$2208 (8712) = Could not find object.

$2209 (8713) = Could not find family member.

$220A (8714) = BLOB file is missing.

$220B (8715) = Could not find language driver.

$2301 (8961) = Corrupt table/index header.

$2302 (8962) = Corrupt file - other than header.

$2303 (8963) = Corrupt Memo/BLOB file.

$2305 (8965) = Corrupt index.

$2306 (8966) = Corrupt lock file.

$2307 (8967) = Corrupt family file.

$2308 (8968) = Corrupt or missing .VAL file.

$2309 (8969) = Foreign index file format.

$2401 (9217) = Read failure.

$2402 (9218) = Write failure.

$2403 (9219) = Cannot access directory.

$2404 (9220) = File Delete operation failed.

$2405 (9221) = Cannot access file.

$2406 (9222) = Access to table disabled because of previous error.

$2501 (9473) = Insufficient memory for this operation.

$2502 (9474) = Not enough file handles.

$2503 (9475) = Insufficient disk space.

$2504 (9476) = Temporary table resource limit.

$2505 (9477) = Record size is too big for table.

$2506 (9478) = Too many open cursors.

$2507 (9479) = Table is full.

$2508 (9480) = Too many sessions from this workstation.

$2509 (9481) = Serial number limit (Paradox).

$250A (9482) = Some internal limit (see context).

$250B (9483) = Too many open tables.

$250C (9484) = Too many cursors per table.

$250D (9485) = Too many record locks on table.

$250E (9486) = Too many clients.

$250F (9487) = Too many indexes on table.

$2510 (9488) = Too many sessions.

$2511 (9489) = Too many open databases.

$2512 (9490) = Too many passwords.

$2513 (9491) = Too many active drivers.

$2514 (9492) = Too many fields in Table Create.

$2515 (9493) = Too many table locks.

$2516 (9494) = Too many open BLOBs.

$2517 (9495) = Lock file has grown too large.

$2518 (9496) = Too many open queries.

$251A (9498) = Too many BLOBs.

$251B (9499) = File name is too long for a Paradox version 5.0 table.

$251C (9500) = Row fetch limit exceeded.

$251D (9501) = Long name not allowed for this tablelevel.

$2601 (9729) = Key violation.

$2602 (9730) = Minimum validity check failed.

$2603 (9731) = Maximum validity check failed.

$2604 (9732) = Field value required.

$2605 (9733) = Master record missing.

$2606 (9734) = Master has detail records. Cannot delete or modify.

$2607 (9735) = Master table level is incorrect.

$2608 (9736) = Field value out of lookup table range.

$2609 (9737) = Lookup Table Open operation failed.

$260A (9738) = Detail Table Open operation failed.

$260B (9739) = Master Table Open operation failed.

$260C (9740) = Field is blank.

$260D (9741) = Link to master table already defined.

$260E (9742) = Master table is open.

$260F (9743) = Detail table(s) exist.

$2610 (9744) = Master has detail records. Cannot empty it.

$2611 (9745) = Self referencing referential integrity must be entered one at a time with no other changes to the table

$2612 (9746) = Detail table is open.

$2613 (9747) = Cannot make this master a detail of another table if its details are not empty.

$2614 (9748) = Referential integrity fields must be indexed.

$2615 (9749) = A table linked by referential integrity requires password to open.

$2616 (9750) = Field(s) linked to more than one master.

$2617 (9751) = Expression validity check failed.

$2701 (9985) = Number is out of range.

$2702 (9986) = Invalid parameter.

$2703 (9987) = Invalid file name.

$2704 (9988) = File does not exist.

$2705 (9989) = Invalid option.

$2706 (9990) = Invalid handle to the function.

$2707 (9991) = Unknown table type.

$2708 (9992) = Cannot open file.

$2709 (9993) = Cannot redefine primary key.

$270A (9994) = Cannot change this RINTDesc.

$270B (9995) = Foreign and primary key do not match.

$270C (9996) = Invalid modify request.

$270D (9997) = Index does not exist.

$270E (9998) = Invalid offset into the BLOB.

$270F (9999) = Invalid descriptor number.

$2710 (10000) = Invalid field type.

$2711 (10001) = Invalid field descriptor.

$2712 (10002) = Invalid field transformation.

$2713 (10003) = Invalid record structure.

$2714 (10004) = Invalid descriptor.

$2715 (10005) = Invalid array of index descriptors.

$2716 (10006) = Invalid array of validity check descriptors.

$2717 (10007) = Invalid array of referential integrity descriptors.

$2718 (10008) = Invalid ordering of tables during restructure.

$2719 (10009) = Name not unique in this context.

$271A (10010) = Index name required.

$271B (10011) = Invalid session handle.

$271C (10012) = invalid restructure operation.

$271D (10013) = Driver not known to system.

$271E (10014) = Unknown database.

$271F (10015) = Invalid password given.

$2720 (10016) = No callback function.

$2721 (10017) = Invalid callback buffer length.

$2722 (10018) = Invalid directory.

$2723 (10019) = Translate Error. Value out of bounds.

$2724 (10020) = Cannot set cursor of one table to another.

$2725 (10021) = Bookmarks do not match table.

$2726 (10022) = Invalid index/tag name.

$2727 (10023) = Invalid index descriptor.

$2728 (10024) = Table does not exist.

$2729 (10025) = Table has too many users.

$272A (10026) = Cannot evaluate Key or Key does not pass filter condition.

$272B (10027) = Index already exists.

$272C (10028) = Index is open.

$272D (10029) = Invalid BLOB length.

$272E (10030) = Invalid BLOB handle in record buffer.

$272F (10031) = Table is open.

$2730 (10032) = Need to do (hard) restructure.

$2731 (10033) = Invalid mode.

$2732 (10034) = Cannot close index.

$2733 (10035) = Index is being used to order table.

$2734 (10036) = Unknown user name or password.

$2735 (10037) = Multi-level cascade is not supported.

$2736 (10038) = Invalid field name.

$2737 (10039) = Invalid table name.

$2738 (10040) = Invalid linked cursor expression.

$2739 (10041) = Name is reserved.

$273A (10042) = Invalid file extension.

$273B (10043) = Invalid language Driver.

$273C (10044) = Alias is not currently opened.

$273D (10045) = Incompatible record structures.

$273E (10046) = Name is reserved by DOS.

$273F (10047) = Destination must be indexed.

$2740 (10048) = Invalid index type

$2741 (10049) = Language Drivers of Table and Index do not match

$2742 (10050) = Filter handle is invalid

$2743 (10051) = Invalid Filter

$2744 (10052) = Invalid table create request

$2745 (10053) = Invalid table delete request

$2746 (10054) = Invalid index create request

$2747 (10055) = Invalid index delete request

$2748 (10056) = Invalid table specified

$274A (10058) = Invalid Time.

$274B (10059) = Invalid Date.

$274C (10060) = Invalid Datetime

$274D (10061) = Tables in different directories

$274E (10062) = Mismatch in the number of arguments

$274F (10063) = Function not found in service library.

$2750 (10064) = Must use baseorder for this operation.

$2751 (10065) = Invalid procedure name

$2752 (10066) = The field map is invalid.

$2801 (10241) = Record locked by another user.

$2802 (10242) = Unlock failed.

$2803 (10243) = Table is busy.

$2804 (10244) = Directory is busy.

$2805 (10245) = File is locked.

$2806 (10246) = Directory is locked.

$2807 (10247) = Record already locked by this session.

$2808 (10248) = Object not locked.

$2809 (10249) = Lock time out.

$280A (10250) = Key group is locked.

$280B (10251) = Table lock was lost.

$280C (10252) = Exclusive access was lost.

$280D (10253) = Table cannot be opened for exclusive use.

$280E (10254) = Conflicting record lock in this session.

$280F (10255) = A deadlock was detected.

$2810 (10256) = A user transaction is already in progress.

$2811 (10257) = No user transaction is currently in progress.

$2812 (10258) = Record lock failed.

$2813 (10259) = Couldn’t perform the edit because another user changed the record.

$2814 (10260) = Couldn’t perform the edit because another user deleted or moved the record.

$2901 (10497) = Insufficient field rights for operation.

$2902 (10498) = Insufficient table rights for operation. Password required.

$2903 (10499) = Insufficient family rights for operation.

$2904 (10500) = This directory is read only.

$2905 (10501) = Database is read only.

$2906 (10502) = Trying to modify read-only field.

$2907 (10503) = Encrypted dBASE tables not supported.

$2908 (10504) = Insufficient SQL rights for operation.

$2A01 (10753) = Field is not a BLOB.

$2A02 (10754) = BLOB already opened.

$2A03 (10755) = BLOB not opened.

$2A04 (10756) = Operation not applicable.

$2A05 (10757) = Table is not indexed.

$2A06 (10758) = Engine not initialized.

$2A07 (10759) = Attempt to re-initialize Engine.

$2A08 (10760) = Attempt to mix objects from different sessions.

$2A09 (10761) = Paradox driver not active.

$2A0A (10762) = Driver not loaded.

$2A0B (10763) = Table is read only.

$2A0C (10764) = No associated index.

$2A0D (10765) = Table(s) open. Cannot perform this operation.

$2A0E (10766) = Table does not support this operation.

$2A0F (10767) = Index is read only.

$2A10 (10768) = Table does not support this operation because it is not uniquely indexed.

$2A11 (10769) = Operation must be performed on the current session.

$2A12 (10770) = Invalid use of keyword.

$2A13 (10771) = Connection is in use by another statement.

$2A14 (10772) = Passthrough SQL connection must be shared

$2B01 (11009) = Invalid function number.

$2B02 (11010) = File or directory does not exist.

$2B03 (11011) = Path not found.

$2B04 (11012) = Too many open files. You may need to increase MAXFILEHANDLE limit in IDAPI configuration.

$2B05 (11013) = Permission denied.

$2B06 (11014) = Bad file number.

$2B07 (11015) = Memory blocks destroyed.

$2B08 (11016) = Not enough memory.

$2B09 (11017) = Invalid memory block address.

$2B0A (11018) = Invalid environment.

$2B0B (11019) = Invalid format.

$2B0C (11020) = Invalid access code.

$2B0D (11021) = Invalid data.

$2B0F (11023) = Device does not exist.

$2B10 (11024) = Attempt to remove current directory.

$2B11 (11025) = Not same device.

$2B12 (11026) = No more files.

$2B13 (11027) = Invalid argument.

$2B14 (11028) = Argument list is too long.

$2B15 (11029) = Execution format error.

$2B16 (11030) = Cross-device link.

$2B21 (11041) = Math argument.

$2B22 (11042) = Result is too large.

$2B23 (11043) = File already exists.

$2B27 (11047) = Unknown internal operating system error.

$2B32 (11058) = Share violation.

$2B33 (11059) = Lock violation.

$2B34 (11060) = Critical DOS Error.

$2B35 (11061) = Drive not ready.

$2B64 (11108) = Not exact read/write.

$2B65 (11109) = Operating system network error.

$2B66 (11110) = Error from NOVELL file server.

$2B67 (11111) = NOVELL server out of memory.

$2B68 (11112) = Record already locked by this workstation.

$2B69 (11113) = Record not locked.

$2C01 (11265) = Network initialization failed.

$2C02 (11266) = Network user limit exceeded.

$2C03 (11267) = Wrong .NET file version.

$2C04 (11268) = Cannot lock network file.

$2C05 (11269) = Directory is not private.

$2C06 (11270) = Directory is controlled by other .NET file.

$2C07 (11271) = Unknown network error.

$2C08 (11272) = Not initialized for accessing network files.

$2C09 (11273) = SHARE not loaded. It is required to share local files.

$2C0A (11274) = Not on a network. Not logged in or wrong network driver.

$2C0B (11275) = Lost communication with SQL server.

$2C0D (11277) = Cannot locate or connect to SQL server.

$2C0E (11278) = Cannot locate or connect to network server.

$2D01 (11521) = Optional parameter is required.

$2D02 (11522) = Invalid optional parameter.

$2E01 (11777) = obsolete

$2E02 (11778) = obsolete

$2E03 (11779) = Ambiguous use of ! (inclusion operator).

$2E04 (11780) = obsolete

$2E05 (11781) = obsolete

$2E06 (11782) = A SET operation cannot be included in its own grouping.

$2E07 (11783) = Only numeric and date/time fields can be averaged.

$2E08 (11784) = Invalid expression.

$2E09 (11785) = Invalid OR expression.

$2E0A (11786) = obsolete

$2E0B (11787) = bitmap

$2E0C (11788) = CALC expression cannot be used in INSERT, DELETE, CHANGETO and SET rows.

$2E0D (11789) = Type error in CALC expression.

$2E0E (11790) = CHANGETO can be used in only one query form at a time.

$2E0F (11791) = Cannot modify CHANGED table.

$2E10 (11792) = A field can contain only one CHANGETO expression.

$2E11 (11793) = A field cannot contain more than one expression to be inserted.

$2E12 (11794) = obsolete

$2E13 (11795) = CHANGETO must be followed by the new value for the field.

$2E14 (11796) = Checkmark or CALC expressions cannot be used in FIND queries.

$2E15 (11797) = Cannot perform operation on CHANGED table together with a CHANGETO query.

$2E16 (11798) = chunk

$2E17 (11799) = More than 255 fields in ANSWER table.

$2E18 (11800) = AS must be followed by the name for the field in the ANSWER table.

$2E19 (11801) = DELETE can be used in only one query form at a time.

$2E1A (11802) = Cannot perform operation on DELETED table together with a DELETE query.

$2E1B (11803) = Cannot delete from the DELETED table.

$2E1C (11804) = Example element is used in two fields with incompatible types or with a BLOB.

$2E1D (11805) = Cannot use example elements in an OR expression.

$2E1E (11806) = Expression in this field has the wrong type.

$2E1F (11807) = Extra comma found.

$2E20 (11808) = Extra OR found.

$2E21 (11809) = One or more query rows do not contribute to the ANSWER.

$2E22 (11810) = FIND can be used in only one query form at a time.

$2E23 (11811) = FIND cannot be used with the ANSWER table.

$2E24 (11812) = A row with GROUPBY must contain SET operations.

$2E25 (11813) = GROUPBY can be used only in SET rows.

$2E26 (11814) = Use only INSERT, DELETE, SET or FIND in leftmost column.

$2E27 (11815) = Use only one INSERT, DELETE, SET or FIND per line.

$2E28 (11816) = Syntax error in expression.

$2E29 (11817) = INSERT can be used in only one query form at a time.

$2E2A (11818) = Cannot perform operation on INSERTED table together with an INSERT query.

$2E2B (11819) = INSERT, DELETE, CHANGETO and SET rows may not be checked.

$2E2C (11820) = Field must contain an expression to insert (or be blank).

$2E2D (11821) = Cannot insert into the INSERTED table.

$2E2E (11822) = Variable is an array and cannot be accessed.

$2E2F (11823) = Label

$2E30 (11824) = Rows of example elements in CALC expression must be linked.

$2E31 (11825) = Variable name is too long.

$2E32 (11826) = Query may take a long time to process.

$2E33 (11827) = Reserved word or one that can’t be used as a variable name.

$2E34 (11828) = Missing comma.

$2E35 (11829) = Missing ).

$2E36 (11830) = Missing right quote.

$2E37 (11831) = Cannot specify duplicate column names.

$2E38 (11832) = Query has no checked fields.

$2E39 (11833) = Example element has no defining occurrence.

$2E3A (11834) = No grouping is defined for SET operation.

$2E3B (11835) = Query makes no sense.

$2E3C (11836) = Cannot use patterns in this context.

$2E3D (11837) = Date does not exist.

$2E3E (11838) = Variable has not been assigned a value.

$2E3F (11839) = Invalid use of example element in summary expression.

$2E40 (11840) = Incomplete query statement. Query only contains a SET definition.

$2E41 (11841) = Example element with ! makes no sense in expression.

$2E42 (11842) = Example element cannot be used more than twice with a ! query.

$2E43 (11843) = Row cannot contain expression.

$2E44 (11844) = obsolete

$2E45 (11845) = obsolete

$2E46 (11846) = No permission to insert or delete records.

$2E47 (11847) = No permission to modify field.

$2E48 (11848) = Field not found in table.

$2E49 (11849) = Expecting a column separator in table header.

$2E4A (11850) = Expecting a column separator in table.

$2E4B (11851) = Expecting column name in table.

$2E4C (11852) = Expecting table name.

$2E4D (11853) = Expecting consistent number of columns in all rows of table.

$2E4E (11854) = Cannot open table.

$2E4F (11855) = Field appears more than once in table.

$2E50 (11856) = This DELETE, CHANGE or INSERT query has no ANSWER.

$2E51 (11857) = Query is not prepared. Properties unknown.

$2E52 (11858) = DELETE rows cannot contain quantifier expression.

$2E53 (11859) = Invalid expression in INSERT row.

$2E54 (11860) = Invalid expression in INSERT row.

$2E55 (11861) = Invalid expression in SET definition.

$2E56 (11862) = row use

$2E57 (11863) = SET keyword expected.

$2E58 (11864) = Ambiguous use of example element.

$2E59 (11865) = obsolete

$2E5A (11866) = obsolete

$2E5B (11867) = Only numeric fields can be summed.

$2E5C (11868) = Table is write protected.

$2E5D (11869) = Token not found.

$2E5E (11870) = Cannot use example element with ! more than once in a single row.

$2E5F (11871) = Type mismatch in expression.

$2E60 (11872) = Query appears to ask two unrelated questions.

$2E61 (11873) = Unused SET row.

$2E62 (11874) = INSERT, DELETE, FIND, and SET can be used only in the leftmost column.

$2E63 (11875) = CHANGETO cannot be used with INSERT, DELETE, SET or FIND.

$2E64 (11876) = Expression must be followed by an example element defined in a SET.

$2E65 (11877) = Lock failure.

$2E66 (11878) = Expression is too long.

$2E67 (11879) = Refresh exception during query.

$2E68 (11880) = Query canceled.

$2E69 (11881) = Unexpected Database Engine error.

$2E6A (11882) = Not enough memory to finish operation.

$2E6B (11883) = Unexpected exception.

$2E6C (11884) = Feature not implemented yet in query.

$2E6D (11885) = Query format is not supported.

$2E6E (11886) = Query string is empty.

$2E6F (11887) = Attempted to prepare an empty query.

$2E70 (11888) = Buffer too small to contain query string.

$2E71 (11889) = Query was not previously parsed or prepared.

$2E72 (11890) = Function called with bad query handle.

$2E73 (11891) = QBE syntax error.

$2E74 (11892) = Query extended syntax field count error.

$2E75 (11893) = Field name in sort or field clause not found.

$2E76 (11894) = Table name in sort or field clause not found.

$2E77 (11895) = Operation is not supported on BLOB fields.

$2E78 (11896) = General BLOB error.

$2E79 (11897) = Query must be restarted.

$2E7A (11898) = Unknown answer table type.

$2E96 (11926) = Blob cannot be used as grouping field.

$2E97 (11927) = Query properties have not been fetched.

$2E98 (11928) = Answer table is of unsuitable type.

$2E99 (11929) = Answer table is not yet supported under server alias.

$2E9A (11930) = Non-null blob field required. Can’t insert records

$2E9B (11931) = Unique index required to perform changeto

$2E9C (11932) = Unique index required to delete records

$2E9D (11933) = Update of table on the server failed.

$2E9E (11934) = Can’t process this query remotely.

$2E9F (11935) = Unexpected end of command.

$2EA0 (11936) = Parameter not set in query string.

$2EA1 (11937) = Query string is too long.

$2EAA (11946) = No such table or correlation name.

$2EAB (11947) = Expression has ambiguous data type.

$2EAC (11948) = Field in order by must be in result set.

$2EAD (11949) = General parsing error.

$2EAE (11950) = Record or field constraint failed.

$2EAF (11951) = When GROUP BY exists, every simple field in projectors must be in GROUP BY.

$2EB0 (11952) = User defined function is not defined.

$2EB1 (11953) = Unknown error from User defined function.

$2EB2 (11954) = Single row subquery produced more than one row.

$2EB3 (11955) = Expressions in group by are not supported.

$2EB4 (11956) = Queries on text or ascii tables is not supported.

$2EB5 (11957) = ANSI join keywords USING and NATURAL are not supported in this release.

$2EB6 (11958) = SELECT DISTINCT may not be used with UNION unless UNION ALL is used.

$2EB7 (11959) = GROUP BY is required when both aggregate and non-aggregate fields are used in result set.

$2EB8 (11960) = INSERT and UPDATE operations are not supported on autoincrement field type.

$2EB9 (11961) = UPDATE on Primary Key of a Master Table may modify more than one record.

$2EBA (11962) = Queries on MS ACCESS tables are not supported by local query engines.

$2EBB (11963) = Preparation of field-level constraint failed.

$2EBC (11964) = Preparation of field default failed.

$2EBD (11965) = Preparation of record-level constraint failed.

$2EC4 (11972) = Constraint Failed. Expression:

$2F01 (12033) = Interface mismatch. Engine version different.

$2F02 (12034) = Index is out of date.

$2F03 (12035) = Older version (see context).

$2F04 (12036) = .VAL file is out of date.

$2F05 (12037) = BLOB file version is too old.

$2F06 (12038) = Query and Engine DLLs are mismatched.

$2F07 (12039) = Server is incompatible version.

$2F08 (12040) = Higher table level required

$3001 (12289) = Capability not supported.

$3002 (12290) = Not implemented yet.

$3003 (12291) = SQL replicas not supported.

$3004 (12292) = Non-blob column in table required to perform operation.

$3005 (12293) = Multiple connections not supported.

$3006 (12294) = Full dBASE expressions not supported.

$3101 (12545) = Invalid database alias specification.

$3102 (12546) = Unknown database type.

$3103 (12547) = Corrupt system configuration file.

$3104 (12548) = Network type unknown.

$3105 (12549) = Not on the network.

$3106 (12550) = Invalid configuration parameter.

$3201 (12801) = Object implicitly dropped.

$3202 (12802) = Object may be truncated.

$3203 (12803) = Object implicitly modified.

$3204 (12804) = Should field constraints be checked?

$3205 (12805) = Validity check field modified.

$3206 (12806) = Table level changed.

$3207 (12807) = Copy linked tables?

$3209 (12809) = Object implicitly truncated.

$320A (12810) = Validity check will not be enforced.

$320B (12811) = Multiple records found, but only one was expected.

$320C (12812) = Field will be trimmed, cannot put master records into PROBLEM table.

$3301 (13057) = File already exists.

$3302 (13058) = BLOB has been modified.

$3303 (13059) = General SQL error.

$3304 (13060) = Table already exists.

$3305 (13061) = Paradox 1.0 tables are not supported.

$3306 (13062) = Update aborted.

$3401 (13313) = Different sort order.

$3402 (13314) = Directory in use by earlier version of Paradox.

$3403 (13315) = Needs Paradox 3.5-compatible language driver.

$3501 (13569) = Data Dictionary is corrupt

$3502 (13570) = Data Dictionary Info Blob corrupted

$3503 (13571) = Data Dictionary Schema is corrupt

$3504 (13572) = Attribute Type exists

$3505 (13573) = Invalid Object Type

$3506 (13574) = Invalid Relation Type

$3507 (13575) = View already exists

$3508 (13576) = No such View exists

$3509 (13577) = Invalid Record Constraint

$350A (13578) = Object is in a Logical DB

$350B (13579) = Dictionary already exists

$350C (13580) = Dictionary does not exist

$350D (13581) = Dictionary database does not exist

$350E (13582) = Dictionary info is out of date - needs Refresh

$3510 (13584) = Invalid Dictionary Name

$3511 (13585) = Dependent Objects exist

$3512 (13586) = Too many Relationships for this Object Type

$3513 (13587) = Relationships to the Object exist

$3514 (13588) = Dictionary Exchange File is corrupt

$3515 (13589) = Dictionary Exchange File Version mismatch

$3516 (13590) = Dictionary Object Type Mismatch

$3517 (13591) = Object exists in Target Dictionary

$3518 (13592) = Cannot access Data Dictionary

$3519 (13593) = Cannot create Data Dictionary

$351A (13594) = Cannot open Database

$3E01 (15873) = Wrong driver name.

$3E02 (15874) = Wrong system version.

$3E03 (15875) = Wrong driver version.

$3E04 (15876) = Wrong driver type.

$3E05 (15877) = Cannot load driver.

$3E06 (15878) = Cannot load language driver.

$3E07 (15879) = Vendor initialization failed.

$3E08 (15880) = Your application is not enabled for use with this driver.

$3F01 (16129) = Query By Example

$3F02 (16130) = SQL Generator

$3F03 (16131) = IDAPI

$3F04 (16132) = Lock Manager

$3F05 (16133) = SQL Driver

$3F06 (16134) = IDAPI Services

$3F07 (16135) = dBASE Driver

$3F08 (16136) = Dictionary Manager

$3F0B (16139) = Token

$3F0D (16141) = Table

$3F0E (16142) = Field

$3F0F (16143) = Image

$3F10 (16144) = User

$3F11 (16145) = File

$3F12 (16146) = Index

$3F13 (16147) = Directory

$3F14 (16148) = Key

$3F15 (16149) = Alias

$3F16 (16150) = Drive

$3F17 (16151) = Server error

$3F18 (16152) = Server message

$3F19 (16153) = Line Number

$3F1A (16154) = Capability

$3F1B (16155) = Dictionary

$3F1D (16157) = Object

$3F1E (16158) = Limit

$3F1F (16159) = Expression

$3F70 (16240) = WORK

$3F71 (16241) = PRIV

$3F72 (16242) = Records copied

$3F73 (16243) = Records appended

$3F74 (16244) = LineNo

$3F75 (16245) = Line

$3F76 (16246) = Reason



Read more.....

How to make transparent DBGrid

procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
var
Text: string;
Rct: TRect;
begin
Text := Field.AsString;
Rct:= Rect;

BitBlt(DBGrid1.Canvas.handle,
Rct.left,
Rct.top,
Rct.right - Rct.left,
Rct.bottom - Rct.top,
Image1.Canvas.Handle,
Rct.left + DBGrid1.Left + Panel1.Left,
Rct.Top + DBGrid1.Top + Panel1.Top,
SRCCOPY);


SetBkModE(DBGrid1.Canvas.Handle, TRANSPARENT);
DBGrid1.Canvas.Font.Style := [fsBold];
DrawtextEx(DBGrid1.Canvas.Handle,
PChar(Text),
Length(Text),
Rct,
DT_WORDBREAK,
nil);
end;

procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
ReleaseCapture;
Panel1.Perform(WM_SYSCOMMAND, $F012, SC_MOVE);
Application.ProcessMessages ;

BitBlt(GetDc(Panel1.Handle),
0,
0,
Panel1.Width,
Panel1.Height,
Image1.Canvas.Handle ,
Panel1.Left, Panel1.Top,
SRCAND);

DBGrid1.refresh;
end;

contoh aplikasinya sebagai berikut :

Read more.....

Rabu, 07 November 2007

GetLastDateOfMonth

function GetLastDateOfMonth(aYear, aMonth: Integer): TDateTime;
begin
Result := EncodeDate(aYear, aMonth, GetLastDayOfMonth(aYear, aMonth));
end;



Read more.....

AddMonthsToDate

function AddMonthsToDate(aDate: TDateTime; aNrMonths: Integer): TDateTime;
begin
Result := IncMonth(aDate, aNrMonths);
end;



Read more.....

MonthsPassed

function MonthsPassed(aFrom, anUntil: TDateTime): Integer;
begin
Result := 12 * (YearFromDate(anUntil) -
YearFromDate(aFrom)) +
MonthFromDate(anUntil) -
MonthFromDate(aFrom);
end;



Read more.....

Insert, Update, Delete dg SQL

// Insert record
procedure TForm1.Button1Click(Sender: TObject);
begin
with Query1 do
begin
Active:=False;
SQL.Clear;
SQL.Add('Insert into country(NAME,CAPITAL,CONTINENT,AREA,POPULATION)
values(
''A_My_Country'',
''A_My_Capital'',
''A_My_Continent'',
1,
1)');
ExecSQL;
end;
Table1.Refresh;
end;


// Delete record
procedure TForm1.Button2Click(Sender: TObject);
begin
with Query1 do
begin
Active:=False;
SQL.Clear;
SQL.Add('Delete from country where name=''A_My_Country''');
ExecSQL;
end;
Table1.Refresh;
end;

//Update record
procedure TForm1.Button3Click(Sender: TObject);
begin
with Query1 do
begin
Active:=False;
SQL.Clear;
SQL.Add('Update country set name=''A_Your_Country''
where name=''A_My_Country''');
ExecSQL;
end;
Table1.Refresh;
end;

Read more.....

Koneksi SQL Server dg ADO

procedure TForm1.Button1Click(Sender: TObject);
begin
if ADOConnection1.Connected then
begin
ADOConnection1.Close;
ADOConnection1.ConnectionString :=”;
end;
ADOConnection1.ConnectionString :=‘Provider=SQLOLEDB.1;’ +
‘Persist Security Info=false;’ +
‘User ID=’ + Edit1.Text + ‘;’ + // user Name
‘Password=’ + Edit2.Text + ‘;’ + // Password
‘Initial Catalog=’ + Edit3.Text + ‘;’ + // Database
‘Data Source=’ + Edit4.Text; //Nama komputer / server
Screen.Cursor := crHourGlass;


try
ADOConnection1.Open;
Screen.Cursor := crDefault;
MessageDlg(‘Koneksi berhasil !’, mtInformation, [mbOK],0);
except
on E:Exception do
begin
Screen.Cursor := crDefault;
ADOConnection1.Close;
MessageDlg(‘Koneksi Gagal !’+#13#13+‘Exception:’+#13+E.Message, mtError, [mbOK],0);
end;
end;
end;

Read more.....

RETRIEVE ALL DATABASE TABLES WITH ADO

// ******************************************************************
// RETRIEVE ALL DATABASE TABLES WITH ADO
// Category : ADO
// Author : Carlo Pasolini, Riccione
// Author Email : ccpasolini@libero.it
// Author Web :
// Tips Website : Swiss Delphi Center
// Tips Website URL: http://www.swissdelphicenter.ch
// ******************************************************************

//How to retrieve all database tables with ADO

unit dbTables;

interface

uses ADODb;

type
TTableType = (ttTable, ttView, ttSynonym, ttSystemTable, ttAccessTable);

type
TTableTypes = set of TTableType;

type
TTableItem = record
ItemName: string;
ItemType: string;
end;

type
TTableItems = array of TTableItem;

function addFilter(string1, string2: string): string;
function ADODbTables(ADOConnection: TADOConnection; types: TTableTypes): TTableItems;

implementation

function addFilter(string1, string2: string): string;
begin
if string1 <> ” then
Result := string1 + ‘ or ‘ + string2
else
Result := string2;
end;


unction ADODbTables(ADOConnection: TADOConnection; types: TTableTypes): TTableItems;
var
ADODataSet: TADODataSet;
i: integer;
begin
ADODataSet := TADODataSet.Create(nil);
ADODataSet.Connection := ADOConnection;
ADOConnection.OpenSchema(siTables, EmptyParam, EmptyParam, ADODataSet);

if (ttTable in types) then
ADODataSet.Filter := addFilter(ADODataSet.Filter, ‘(TABLE_TYPE = ”TABLE”)’);

if (ttView in types) then
ADODataSet.Filter := addFilter(ADODataSet.Filter, ‘(TABLE_TYPE = ”VIEW”)’);

if (ttSynonym in types) then
ADODataSet.Filter := addFilter(ADODataSet.Filter, ‘(TABLE_TYPE = ”SYNONYM”)’);

if (ttSystemTable in types) then
ADODataSet.Filter := addFilter(ADODataSet.Filter, ‘(TABLE_TYPE = ”SYSTEM TABLE”)’);

if (ttAccessTable in types) then
ADODataSet.Filter := addFilter(ADODataSet.Filter, ‘(TABLE_TYPE = ”ACCESS TABLE”)’);

ADODataSet.Filtered := True;

SetLength(Result, ADODataSet.RecordCount);

i := 0;
with ADODataSet do
begin
First;
while not EOF do
begin
with Result[i] do
begin
ItemName := FieldByName(’TABLE_NAME’).AsString;
ItemType := FieldByName(’TABLE_TYPE’).AsString;
end;
Inc(i);
Next;
end;
end;

ADODataSet.Free;
end;

end.

{
Example: create a new project and add a TADOConnection (ADOConnection1),
a TButton (Button1) and a TMemo (Memo1); assign a ConnectionString to the
TADOConnection component and set “ADOConnection1.Active := True”
}

procedure TForm1.Button1Click(Sender: TObject);
var
output: ttableitems;
i: integer;
begin
output := ADODbTables(ADOConnection1, [ttTable, ttView, ttSynonym]);
// output := ADODbTables(ADOConnection1, [ttSystemTable, ttAccessTable]);
for i := Low(output) to High(output) do
begin
Memo1.Lines.Add(output[i].ItemName + ‘—’ + output[i].ItemType);
end;
output := nil;
end;

Read more.....

WRITE TO AN ACCESS DB USING ADO / SQL

// ******************************************************************
// WRITE TO AN ACCESS DB USING ADO / SQL
// Category : ADO
// Author : Michael Casse
// Author Email : michaelc@netspace.net.au
// Author Web :
// Tips Website : Swiss Delphi Center
// Tips Website URL: http://www.swissdelphicenter.ch
// ******************************************************************

// Read an MS-ACCESS Database using ADO
// Verify if it is an ACCESS MDB File
// Write a Record to MS-ACCESS Database
// Components Needed on the Application Form are:-
// TADOtable,TDataSource,TOpenDialog,TDBGrid,
// TBitBtn,TTimer,TEditTextBox
// Date : 22/01/2002
// Author: Michael Casse.

program ADOdemo;

uses
Forms,
uMain in ‘uMain.pas’ {frmMain};

{$R *.RES}

begin
Application.Initialize;
Application.CreateForm(TfrmMain, frmMain);
Application.Run;
end.
///////////////////////////////////////////////////////////////////
unit uMain;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Db, DBTables, ADODB, Grids, DBGrids, ExtCtrls, DBCtrls, StdCtrls, Buttons,
ComObj;

type
TfrmMain = class(TForm)
DBGridUsers: TDBGrid;
BitBtnClose: TBitBtn;
DSource1: TDataSource;
EditTextBox: TEdit;
BitBtnAdd: TBitBtn;
TUsers: TADOTable;
BitBtnRefresh: TBitBtn;
Timer1: TTimer;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure ConnectToAccessDB(lDBPathName, lsDBPassword: string);
procedure ConnectToMSAccessDB(lsDBName, lsDBPassword: string);
procedure AddRecordToMSAccessDB;
function CheckIfAccessDB(lDBPathName: string): Boolean;
function GetDBPath(lsDBName: string): string;
procedure BitBtnAddClick(Sender: TObject);
procedure BitBtnRefreshClick(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
function GetADOVersion: Double;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
frmMain: TfrmMain;
Global_DBConnection_String: string;
const
ERRORMESSAGE_1 = ‘No Database Selected’;
ERRORMESSAGE_2 = ‘Invalid Access Database’;

implementation

{$R *.DFM}

procedure TfrmMain.FormCreate(Sender: TObject);
begin
ConnectToMSAccessDB(’ADODemo.MDB’, ‘123′); // DBName,DBPassword
end;



procedure TfrmMain.ConnectToMSAccessDB(lsDBName, lsDBPassword: string);
var
lDBpathName: string;
begin
lDBpathName := GetDBPath(lsDBName);
if (Trim(lDBPathName) <> ”) then
begin
if CheckIfAccessDB(lDBPathName) then
ConnectToAccessDB(lDBPathName, lsDBPassword);
end
else
MessageDlg(ERRORMESSAGE_1, mtInformation, [mbOK], 0);
end;

function TfrmMain.GetDBPath(lsDBName: string): string;
var
lOpenDialog: TOpenDialog;
begin
lOpenDialog := TOpenDialog.Create(nil);
if FileExists(ExtractFileDir(Application.ExeName) + ‘\’ + lsDBName) then
Result := ExtractFileDir(Application.ExeName) + ‘\’ + lsDBName
else
begin
lOpenDialog.Filter := ‘MS Access DB|’ + lsDBName;
if lOpenDialog.Execute then
Result := lOpenDialog.FileName;
end;
end;

procedure TfrmMain.ConnectToAccessDB(lDBPathName, lsDBPassword: string);
begin
Global_DBConnection_String :=
‘Provider=Microsoft.Jet.OLEDB.4.0;’ +
‘Data Source=’ + lDBPathName + ‘;’ +
‘Persist Security Info=False;’ +
‘Jet OLEDB:Database Password=’ + lsDBPassword;

with TUsers do
begin
ConnectionString := Global_DBConnection_String;
TableName := ‘Users’;
Active := True;
end;
end;

// Check if it is a valid ACCESS DB File Before opening it.

function TfrmMain.CheckIfAccessDB(lDBPathName: string): Boolean;
var
UnTypedFile: file of Byte;
Buffer: array[0..19] of Byte;
NumRecsRead: Integer;
i: Integer;
MyString: string;
begin
AssignFile(UnTypedFile, lDBPathName);
reset(UnTypedFile,1);
BlockRead(UnTypedFile, Buffer, 19, NumRecsRead);
CloseFile(UnTypedFile);
for i := 1 to 19 do MyString := MyString + Trim(Chr(Ord(Buffer[i])));
Result := False;
if Mystring = ‘StandardJetDB’ then
Result := True;
if Result = False then
MessageDlg(ERRORMESSAGE_2, mtInformation, [mbOK], 0);
end;

procedure TfrmMain.BitBtnAddClick(Sender: TObject);
begin
AddRecordToMSAccessDB;
end;

procedure TfrmMain.AddRecordToMSAccessDB;
var
lADOQuery: TADOQuery;
lUniqueNumber: Integer;
begin
if Trim(EditTextBox.Text) <> ” then
begin
lADOQuery := TADOQuery.Create(nil);
with lADOQuery do
begin
ConnectionString := Global_DBConnection_String;
SQL.Text :=
‘SELECT Number from Users’;
Open;
Last;
// Generate Unique Number (AutoNumber in Access)
lUniqueNumber := 1 + StrToInt(FieldByName(’Number’).AsString);
Close;
// Insert Record into MSAccess DB using SQL
SQL.Text :=
‘INSERT INTO Users Values (’ +
IntToStr(lUniqueNumber) + ‘,’ +
QuotedStr(UpperCase(EditTextBox.Text)) + ‘,’ +
QuotedStr(IntToStr(lUniqueNumber)) + ‘)’;
ExecSQL;
Close;
// This Refreshes the Grid Automatically
Timer1.Interval := 5000;
Timer1.Enabled := True;
end;
end;
end;

procedure TfrmMain.BitBtnRefreshClick(Sender: TObject);
begin
Tusers.Active := False;
Tusers.Active := True;
end;

procedure TfrmMain.Timer1Timer(Sender: TObject);
begin
Tusers.Active := False;
Tusers.Active := True;
Timer1.Enabled := False;
end;

function TfrmMain.GetADOVersion: Double;
var
ADO: OLEVariant;
begin
try
ADO := CreateOLEObject(’adodb.connection’);
Result := StrToFloat(ADO.Version);
ADO := Null;
except
Result := 0.0;
end;
end;

procedure TfrmMain.Button1Click(Sender: TObject);
begin
ShowMessage(Format(’ADO Version = %n’, [GetADOVersion]));
end;

end.

Read more.....

Selamat Datang


Selamat Datang di blog Tutorial Delphi yang memuat Tips N Trik serta E-book. Di blog ini juga disediakan aplikasi beserta source code.

Read more.....