Jumat, 28 Desember 2007

File I/O - Delphi Examples

File I/O - Delphi Examples
There are 3 basic methods to perform File I/O
Use Pascal file variables
Use Windows API function wrappers
Use Windows API functions
The delphi help files suggest that you use the Pascal routines if you can.
Use of the non-native Pascal file variable handlers such as FileOpen is discouraged. These routines map to the Windows API functions and return file handles, not normal Pascal file variables. These are low-level file access routines. For normal file operations use the normal AssignFile, Rewrite, Reset operations instead of FileOpen.
(From the Delphi FileOpen help.)

File Manager Commands
File I/O Commands
File Search Commands
Testing for the Existance of a File
Testing for the Existance of a Directory
Opening and Reading a File
File Manager Commands
SysUtils/FileOpen and System/AssignFile have different commands for many of these

See SysUtils / File-management routines and System / I/O routines
Change Directory SetCurrentDir('c:\path')
Make Directory CreateDir('c:\path')
ForceDirectories('c:\path1\path2')
Remove Directory RemoveDir('c:\path')
RmDir(str)
Change Drive (no known function)
Rename a File RenameFile('test.txt', 'string.tst')
ChangeFileExt('test.txt', 'doc')
Delete a File DeleteFile('c:\*.tst') - Don't know if wildcards are allowed
Search for File t_str := FileSearch('readme.txt', 'c:\;c:\windows');
t_int := FindFirst ('c:\*.tst', attr, F) ;
Current Drirectory t_str := GetCurrentDir ;
Get File Attributes temp = FileGetAttr('c:\filename.tst')
Get File Mode TSearchRec.Attr (use with FindFirst or FindNext)
Set File Attributes FileSetAttr('c:\filename.tst', faReadOnly)
Get File Length TSearchRec.Size (use with FindFirst or FindNext)
FileSize(var F)
Get File Date/Time tempDate := FileGetDate(Handle) ;
Set File Date/Time FileSetDate(Handle, Age)
Test File existance if FileExists('c:\filename.tst') then
Test Directory existance if DirectoryExists('c:\temp') then


AdjustLinesBreaks(const S: string): string; - adjusts all line breaks in the string S to be true CR/LF

File I/O Commands
Open File for I/O FileOpen(const FileName: string; Mode: Integer): Integer;
AssignFile(F, OpenDialog1.FileName);
Rewrite(var F: File [; Recsize: Word ] );
Append(var F: Text);
Get File Mode F.Mode or (F as TFileRec).Mode
Write to File FileWrite(Handle: Integer; const Buffer; Count: Integer): Integer;
Write to TextFile Writeln, Write
Write to File BlockWrite()
Read From TextFile Read, Readln
Read From File BlockRead()
Set Current Location Seek(var F; N: Longint);
Get Current Location FilePos(var F)
Length of File FileSize(var F)
End of File while not Eof(F1) do
Close File FileClose(Handle: Integer)
CloseFile(F1);
Closes All Files Not available in Delphi


var
f1 : file;
f2 : text;
f3 : textfile; // from AssignFile hlp

(* File type declarations from Delphi file help *)
type
Person = record
FirstName: string[15];
LastName : string[25];
Address : string[35];
end;
PersonFile = file of Person;
NumberFile = file of Integer;
SwapFile = file;

TFileRec = record
Handle: Integer;
Mode: Integer;
RecSize: Cardinal;
Private: array[1..28] of Byte;
UserData: array[1..32] of Byte;
Name: array[0..259] of Char;
end;


File Search Commands
Files and directories may not have the same names. The more complicated FindFirst command must be used because FileExists does not find directories.
TSearchRec = record
Time: Integer;
Size: Integer;
Attr: Integer;
Name: TFileName;
ExcludeAttr: Integer;
FindHandle: THandle;
FindData: TWin32FindData;
end;

var
tempStr : string ;
FileFound : SmallInt ;
SearchRec : TSearchRec;
const
crlf = Chr(13) + Chr(10) ; // Carriage return & Linefeed
begin
FileFound := FindFirst('c:\temp', faAnyFile, SearchRec);
If FileFound = 0 then // a match was found
begin
If (SearchRec.Attr And faDirectory) <> 0 Then
tempStr := 'The following directory already exists.'
Else
tempStr := 'A file with the following name already exists.' ;
tempStr := tempStr + crlf + crlf + ' ' + 'c:\temp' ;
ShowMessage(tempStr)
end;
FindClose(SearchRec); // This is required to free memory
end;

Testing for the Existance of a File
The following is from the reset example.
function FileExists(FileName: string): Boolean;
{ Boolean function that returns True if the file exists; otherwise,
it returns False. Closes the file if it exists. }
var
F: file;
begin
{$I-}
AssignFile(F, FileName);
FileMode := 0; ( Set file access to read only }
Reset(F);
CloseFile(F);
{$I+}
FileExists := (IOResult = 0) and (FileName <> '');
end; { FileExists }
In Delphi 5, FileExists is built-in.

Testing for the Existance of a Directory

FileExists(tt) does not find directories. Can use stream objects which have handles

With Delphi 5, you can use
if DirectoryExists('c:\temp') then

Opening and Reading a File
The following is from the AssignFile example.
var
F: TextFile;
S: string;
begin
if OpenDialog1.Execute then { Display Open dialog box }
begin
AssignFile(F, OpenDialog1.FileName); { File selected in dialog box }
Reset(F);
Readln(F, S); { Read the first line out of the file }
Edit1.Text := S; { Put string in a TEdit control }
CloseFile(F);
end;
end;
File copy - from the Eof, Read, Write example. To use this, create a form with a button, a Dialogs / OpenDialog component and a Dialogs / SaveDialog component. Double click the button (to open the source code) and paste the following code. Be sure that the code begins with var and not begin.
procedure TForm1.CopyFile();
var
F1, F2: TextFile;
Ch: Char;
begin
if OpenDialog1.Execute then begin
AssignFile(F1, OpenDialog1.Filename);
Reset(F1);
if SaveDialog1.Execute then begin
AssignFile(F2, SaveDialog1.Filename);
Rewrite(F2);
while not Eof(F1) do
begin
Read(F1, Ch);
Write(F2, Ch);
end;
CloseFile(F2);
end;
CloseFile(F1);

end;
end; // of procedure TForm1.CopyFile()

Author: Robert Clemenzi - clemenzi@cpcug.org
URL: http:// cpcug.org / user / clemenzi / technical / Languages / Delphi / DelphiFileIO.htm

source : http://mc-computing.com/languages/Delphi/DelphiFileIO.htm#Open

Label:

Selasa, 18 Desember 2007

Situs hosting-upload & sharing file gratis

Mulai dari mengirim dokumen, file, lagu hingga back up data-data/file-file penting, tempat penyimpanan file gratis online adalah kunci segalanya untuk hal-hal tersebut. Sebenarnya selain tempat penyimpanan gratis ini, ada juga yang berbayar dengan banyak fitur bagus untuk penyimpanan file online seperti ini , tetapi untuk masyarakat kita saat ini tentu memberatkan untuk mengeluarkan biaya dan selama yang gratis ada, tentu lebih baik anda memanfaatkannya.

BackUp data Online

1. BlogBackupOnline
http://www.blogbackuponline.com/techrigy/
Buat anda yang memiliki blog dan tidak menginginkan terjadinya kehilangan blog tersebut, anda dapat memanfaatkan layanan ini untuk membantu anda mem-back up data penting di blog anda secara otomatis dan tentunya gratis dengan storage 50Mb.

2. ElephantDrive
http://www.elephantdrive.com/index.aspx
ElephantDrive ini menawarkan storage penyimpanan gratis sebesar 1GB dan hingga 1TB dengan mengisi formulir pengajuan.

3. File123
http://www.file123.com/default.aspx
File123 menawarkan space penyimpanan gratis sebesar 1GB

4. Mp3Tunes
http://www.mp3tunes.com
Mp3Tunes ini menyediakan tempat penyimpanan koleksi musik anda tidak terbatas dan gratis, anda juga dapat streaming/mendengarkan secara online lagu-lagu yang anda simpan disini darimanapun anda berada.

5. OmniDrive
http://www.omnidrive.com
Dengan OmniDrive ini, anda dapat mem-back up file apa saja yang anda miliki hingga 1GB. Disamping itu, back up anda bisa anda akses darimana saja atau anda gunakan sebagai hosting file untuk situs.

6. Steekr
http://www.steekr.com
Steekr ini menyediakan ruang penyimpanan online sebesar 1GB untuk media digital anda secara gratis. Selain itu anda dapat akses untuk mendengarkan musik yang anda simpan dimana saja dan juga berbagi/sharing file anda dengan orang lain.

7. Textive
http://www.textive.com
Layanan yang disediakan textive ini adalah back up dokumen anda secara online dan gratis dengan tanpa batasan bandwith dan ruang.

8. YunTaa
http://www.yuntaa.com/
Anda dapat mensinkronisasikan hard disk anda dengan storage online yang disediakan YunTaa ini. Layanan ini juga bisa anda manfaatkan untuk sharing file anda. Versi gratis yang disediakan YunTaa adalah storage dengan ruang 1GB.

Layanan Pengiriman File

9. Arunalabs
http://send.arunalabs.com
Anda bisa mengirim file-file berukuran besar dengan siapapun secara online dengan layanan ini.

10. BigFilez
http://www.bigfilez.com
Dengan bigfilez ini anda dapat mengirim file dengan ukuran besar hingga 500MB ke banyak tujuan.

11. BoxCloud
http://www.boxcloud.com
Dengan boxcloud ini, anda dapat mengirim file gratis hingga ukuran 1GB.

12. DriveWay
http://www.driveway.com
Anda dapat mengirim file dengan jumlah tak terbatas dengan masing-masing ukuran hingga 500MB maksimal.

13. DropSend
http://www.dropsend.com
Dengan dropsend ini, anda dapat mengirim email file dengan ukuran hingga 250MB.

14. JagBox
http://www.jagbox.com
Dengan jagbox ini, anda dapat mengupload file hingga ukuran 100MB, anda dapat meletakkan link downloadnya dimana saja dan mengatur sendiri waktu kadaluarsa link tersebut.

15. SendSpace
http://www.sendspace.com
Dengan sendspace ini, anda dapat mengirim/upload file hingga ukuran 300MB kemudian meletakkan/mengirimkan link downloadnya dengan bandwith tidak terbatas (unlimited)

16. Sharebee
http://www.sharebee.com/
Anda dapat meng-upload file, share/meletakkan link download dimana saja. Tidak disebutkan berapa batasan untuk upload file.

Layanan Penyimpanan dan Sharing File

17. 4Shared
http://www.4shared.com
Layanan 4shared ini adalah sharing file atau seluruh isi folder dengan gratis hingga ukuran 1GB.

18. Badongo
http://www.badongo.com
Badongo menawarkan tempat penyimpanan file tak terbatas, tetapi file-file yang tidak aktif akan dihapus setelah 45 hari untuk anggota gratis.

19. BigFileBox
http://www.bigfilebox.com
BigFileBox ini menyediakan tempat penyimpanan gratis hingga 100MB.

20. BooMP3
http://boomp3.com
Fitur yang ditawarkan BooMp3 ini adalah storage tidak terbatas file-file audio, selain itu anda juga dapat sharing file-file anda ini dengan orang lain.

21. BOXSTr
http://boxstr.com
10GB ruang storage file ditawarkan oleh layanan ini, dengan ukuran masing-masing hingga 250MB dan dengan batas bandwith 10 GB.

22. DivShare
http://upload.divshare.com
Dengan divshare ini anda dapat mengupload file untuk disimpan selamanya dan juga dapat sharing file tersebut dengan orang lain.

23. EweDrive
https://ewedrive.com
Dengan ewedrive ini, anda dapat menyimpan file hingga batas penyimpanan 1GB.

24. FileHo
http://fileho.com
FileHo menawarkan ruang penyimpanan file tidak terbatas dan anda dapat memilih untuk sharing file-file tersebut atau membiarkannya privat/hanya bisa diakses anda sendiri.

25. JumboDir
http://www.jumbodir.com/
Jika anda meng-upload file disini, anda dapat melakukannya tanpa registrasi atau subskripsi yang merepotkan dengan ruang penyimpanan hingga 2GB. Namun, jika anda melakukan registrasi, anda dapat menyimpan file anda selamanya.

26. MyDataBus
http://www.mydatabus.com
MyDataBus ini menawarkan upload gratis hingga 5GB, anda juga dapat sharing file-file anda atau mengintegrasikan dengan FaceBook.

27. XDrive
http://www.xdrive.com
Dengan XDrive ini anda dapat menyimpan file dengan batas ruang storage penyimpanan 5GB yang anda bisa akses dari mana saja dan sharing file anda agar bisa di-download oleh teman atau siapa saja.

28. zUpload
http://www.zupload.com
Layanan yang ditawarkan zUpload ini sangat menarik karena menawarkan sharing file hingga ukuran 500MB per file tanpa batasan bandwith download dan ruang storage.

Source : http://sumber-sumber.blogspot.com