| View previous topic :: View next topic |
| Was this useful? |
| Yes |
|
25% |
[ 1 ] |
| No |
|
75% |
[ 3 ] |
|
| Total Votes : 4 |
|
| Author |
Message |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Wed Jul 11, 2007 7:58 am Post subject: Using a .dat in delphi[Tutorial] |
|
|
im gonna share what i just learned with some of you.
this file is a very useful file and will save you alot of trouble.
So you have a Memo, ListBox, w/e and you want the data to be saved use to use
Dont want to create a .txt file or database to save everything?
USE A DAT
Step 1. On the form Create Procedure do this
| Code: | procedure TForm1.FormCreate(Sender: TObject);
var
strm : TFileStream;
begin
if FileExists('List.dat') then begin
strm := TFileStream.Create('List.dat',fmOpenRead);
strm.ReadComponent(ListBox1);
strm.Free
end; |
Describing the code:
TFileStream is what allows you to stream a file for information.
| Code: | | if FileExists('List.dat') then begin |
This searchs to see if List.dat is there and if it is it will do the if block
| Code: | strm := TFileStream.Create('List.dat',fmOpenRead);
strm.ReadComponent(ListBox1);
strm.Free
|
TFileStream.Create is used to create the stream using List.dat and the function fmOpenRead
ReadComponent(ListBox1) is used to write the List.dat to the ListBox1. You can change it to w/e. Memo1. Edit1.
Free is used to free up the stream so you can access it in other files. If you DONT FREE IT you will get an access share violation
Now to actually CREATE the .dat
Step2. On FormClose do this
| Code: | procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
strm : TFileStream;
begin
strm := TFileStream.Create('List.dat', fmCreate);
strm.WriteComponent(ListBox1);
strm.Free;
end; |
Simple eh?
You know about TFileStream
TFileStream.Create is the function used to create the dat List.dat using fmCreate.
WriteComponent(ListBox1) is used to read ListBox1 and write it to the .dat
Remember to free up the stream
These 2 simple blocks will make your programming easier
_________________
|
|
| Back to top |
|
 |
Kevin Grandmaster Cheater Supreme
Reputation: 0
Joined: 07 Mar 2007 Posts: 1139 Location: Spiderman-World
|
Posted: Wed Jul 11, 2007 10:10 am Post subject: |
|
|
let me see if i got it right...
whatever you saves in the .dat file, is opened in your delphi application.
If you got a list of names, and you save it as a .dat file, then inside delphi, it will show the names in a memo ect ?
Thanks for taking time to write the tutorial, i love that there is getting more and more tutorials here, but then again i dont want the section to die becuase of lots of topics about the same (Kaspersky... no need to make 2-3 threads about how to make 1 trainer)
but thanks for taking time to write it!! it might become handy for some people. good work.
|
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Wed Jul 11, 2007 10:17 am Post subject: |
|
|
.dat can be any file
.dat(a) is an encrypted type of file so it is good for this work
when you save the .dat it saves the info like it would appear in the list box
i think its very handy, i like to do things that involve session to session memory so this is a good tool
_________________
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Wed Jul 11, 2007 4:27 pm Post subject: |
|
|
| You don't have to save as .dat, you can name it as .dykebeard or something if you felt so inclined and read it no problem since it's just plain text.
|
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Wed Jul 11, 2007 7:53 pm Post subject: |
|
|
| Code: | TPF0TListBoxListBox1Left Top Width。Heightチ
ItemHeight
TabOrderTabWidth |
yeah thats the code from the dat
not exactly plain text
You cant see it but it has encryption symbols that wont show on CEF...
_________________
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Wed Jul 11, 2007 7:59 pm Post subject: |
|
|
If you use special symbols like nextline and tab, it will show up wonky in notepad.
Also .dat files aren't used for anything specific, you can store whatever in them pretty much.
|
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Wed Jul 11, 2007 8:15 pm Post subject: |
|
|
yea i said you can use them for anything
and this is just one simple method so w/e
_________________
|
|
| Back to top |
|
 |
|