Arsip: Cara backup dan restore data di program delphi

 
user image
more 12 years ago

wati

Para master delphi disini... gimana caranya bikin program backup dan restore data dari program delphi ya? database bisa aja firebird,paradox,mysql.....thanks
user image
more 12 years ago

cartrun

kalau kamu pake paradox file"nya tuh jadi banyak. nah kamu simpan dalam satu folder, kemudian ikuti langkah-langkahnya yah. 1. Tambakan 2 Edit, 2 SpeedButton, 1 Button. 2. Tambahkan => uses ShellAPI, FileCtrl; {disimpan dibawah implementation} 3. Tambahkan varibel global => fdir, tdir: string; 4. Tambahkan code berikut. function GetDirectory: string; begin if not SelectDirectory(Result,[sdAllowCreate, sdPerformCreate, sdPrompt],0) then Result:= EmptyStr; end; procedure CopyDirectoryTree(AHandle: THandle; const AFromDirectory, AToDirectory: string); var SHFileOpStruct: TSHFileOpStruct; FromDir: PChar; ToDir: PChar; begin GetMem(FromDir, Length(AFromDirectory)+2); try GetMem(ToDir, Length(AToDirectory)+2); try FillChar(FromDir^, Length(AFromDirectory)+2,0); FillChar(ToDir^, Length(AToDirectory)+2,0); StrCopy(FromDir, PChar(AFromDirectory)); StrCopy(ToDir, PChar(AToDirectory)); with SHFileOpStruct do begin Wnd:= AHandle; WFunc:= FO_COPY; pFrom:= FromDir; pTo:= ToDir; fFlags:= FOF_SILENT OR FOF_RENAMEONCOLLISION; fAnyOperationsAborted:= False; hNameMappings:= Nil; lpszProgressTitle:= Nil; if SHFileOperation(SHFileOpStruct) <> 0 then RaiseLastWin32Error; end; finally FreeMem(ToDir, Length(AToDirectory)+2); end; finally FreeMem(FromDir, Length(AFromDIrectory)+2); end; end; //ini untuk SpeedButton1 procedure TFBackup.SpeedButton1Click(Sender: TObject); begin fdir:= 'C:'; if SelectDirectory(fdir, , 0) then Edit1.Text:= fdir; end; //ini untuk SpeedButton2 procedure TFBackup.SpeedButton1Click(Sender: TObject); begin tdir:= 'D:'; if SelectDirectory(tdir, , 0) then Edit2.Text:= tdir; end; //ini code untuk Button. procedure TFBackup.Button1Click(Sender: TObject); begin CopyDirectoryTree(Handle, fdir, tdir); Application.MessageBox('Database berhasil di Backup!','Information',MB_OK Or MB_ICONINFORMATION); end; kalau untuk restorenya saya gx tau. hehehe. kalau kamu pake Ms. Acces kan filenya cuma 1 yaitu *.mdb jadi gx repot kaya di atas, contoh untuk backup database nya kaya gini. 1. Tambakan 2 Edit, 2 SpeedButton, 1 Button, 1 OpenDialog. 2. Tambahkan => uses FileCtrl; {disimpan dibawah implementation} 4. Tambahkan code berikut. //ini untuk SpeedButton1 procedure TForm1.SpeedButton1Click(Sender: TObject); begin if OpenDialog1.Execute then begin Edit1.Text:= OpenDialog1.FileName; Edit2.Text:= Edit1.Text; end; //ini untuk SpeedButton2 procedure TForm1.SpeedButton2Click(Sender: TObject); var t: string; begin t:='D:'; if SelectDirectory(St, , 0) then Edit2.Text:=t+''+ExtractFileName(Edit1.Text); end; //ini untuk Button procedure TForm1.Button1Click(Sender: TObject); begin if (Edit1.Text<>'') and (Edit2.Text<>'') then if CopyFile(PChar(Edit1.Text), PChar(Edit2.Text), False) then ShowMessage('Database Di Backup'); end; kalau untuk Restore di Button1 km udh jadi gini procedure TForm1.Button1Click(Sender: TObject); begin DeleteFile(OpenDialog1.FileName); if (Edit1.Text<>'') and (Edit2.Text<>'') then if CopyFile(PChar(Edit2.Text), PChar(Edit1.Text), False) then {Edit1 dan Edit2 dibalik} ShowMessage('Database Di Restore'); end; moga membantu.
user image
more 12 years ago

wati

thanks mas...apakah ga ada component free yg lebih cepet ?hahaha...
user image
more 12 years ago

cartrun

@wati: thanks mas...apakah ga ada component free yg lebih cepet ?hahaha...
oke sma". maksudnya komponen free sperti apa mba.? kan SpeedButton ada pada komponen pallete Additional, Edit sama Button ada pada komponen pallete Standar. itu semua kn udh satu paket sma delphi jadi udh komponen free. ehm coba dulu z deh mba oke. :lol:
user image
more 12 years ago

halimanh

Kalo pake postgres db, ada artikel tentang backup yg bagus nih. http://jokorb.wordpress.com/2010/12/31/postgresql-autobackup-tool/ Kalaupun nggak pake postgres, bisa liat screen shotnya, bagus juga designnya.
user image
more 12 years ago

wati

kalo pake firebird backup nya gimana bro?thx
user image
more 12 years ago

cartrun

@wati: kalo pake firebird backup nya gimana bro?thx
waduh kalau firebird gx tau saya bro coz gx prnah nyobain bkin program pake database firebird. hehe
user image
more 12 years ago

halimanh

Kalo firebird, http://www.firebirdfaq.org/faq141/ http://www.destructor.de/firebird/gbak.htm
user image
more 12 years ago

halimanh

Kalo firebird, http://www.firebirdfaq.org/faq141/ http://www.destructor.de/firebird/gbak.htm
more ...
  • Pages:
  • 1
Share to

AI Forward

🚀 We're thrilled to partner with Alibaba Cloud for "AI Forward - Alibaba Cloud Global Developer Summit 2025" in Jakarta! Join us and explore the future of AI. Register now: https://int.alibabacloud.com/m/1000400772/
#AlibabaCloud #DeveloperSummit #Jakarta #AIFORWARD

Random Topic

Local Business Directory, Search Engine Submission & SEO Tools FreeWebSubmission.com SonicRun.com