| View previous topic :: View next topic |
| Author |
Message |
Never Again I post too much
Reputation: 0
Joined: 13 Jan 2007 Posts: 2000 Location: New Mexico
|
Posted: Sat Jan 05, 2008 6:22 pm Post subject: [Delphi]Some Questions |
|
|
I was recently making a Universal Flash Trainer for personal use when I was in need for some good ideas for functions. I came across Blader, but he uses VB6, so he couldn't help me. The functions I was in need for were Loading and saving text strings in a .txt and loading it from the path that the project is in.
Thanks
|
|
| Back to top |
|
 |
Blader I post too much
Reputation: 2
Joined: 19 Jan 2007 Posts: 2049
|
Posted: Sat Jan 05, 2008 6:30 pm Post subject: |
|
|
The location for the project would be App.Path or Application.Path, something like that
_________________
|
|
| Back to top |
|
 |
Never Again I post too much
Reputation: 0
Joined: 13 Jan 2007 Posts: 2000 Location: New Mexico
|
Posted: Sat Jan 05, 2008 6:37 pm Post subject: |
|
|
| It's Application.Path, but I'm talking about loading the .txt onto the form.
|
|
| Back to top |
|
 |
smartz993 I post too much
Reputation: 2
Joined: 20 Jun 2006 Posts: 2013 Location: USA
|
Posted: Sat Jan 05, 2008 10:53 pm Post subject: |
|
|
Text onto a form? Like into an editbox?
Put this function anywhere, but make sure it's placed before the spot that you use it:
| Code: |
function LoadText(Path: string):string;
var
TxtFile : TextFile;
stringread : string;
begin
try
AssignFile(TxtFile,Path) ;
Reset(TxtFile) ;
ReadLn(TxtFile, stringread) ;
CloseFile(TxtFile);
result:=stringread;
except
ShowMessage('Could not find proper .txt file');
end;
|
Then if you'd like to use this function to..perhaps load text from a txt file and put it into an edit box..you could do this:
| Code: |
Edit1.text:=LoadText('C:\WHATEVER.txt');
|
And if the txt file is in the same directory as the .exe, you can do this:
| Code: |
Edit1.text:=LoadText(ExtractFilePath(Application.exename)+'WHATEVER.txt');
|
|
|
| Back to top |
|
 |
Never Again I post too much
Reputation: 0
Joined: 13 Jan 2007 Posts: 2000 Location: New Mexico
|
Posted: Sat Jan 05, 2008 10:59 pm Post subject: |
|
|
| Thank you. + Rep. How about saving the text into a .txt?
|
|
| Back to top |
|
 |
smartz993 I post too much
Reputation: 2
Joined: 20 Jun 2006 Posts: 2013 Location: USA
|
Posted: Sat Jan 05, 2008 11:00 pm Post subject: |
|
|
You can do the opposite of the read. h/o.
| Code: | function WriteText(WhatToWrite: string;Path:string):string;
var
TxtFile : TextFile;
begin
try
AssignFile(TxtFile,Path) ;
Rewrite(TxtFile) ;
WriteLn(TxtFile, WhatToWrite) ;
CloseFile(TxtFile);
except
ShowMessage('Could not find proper .txt file');
end; |
And to call this:
| Code: | | WriteText(edit1.text,'C:\WHATEVER.txt'); |
|
|
| Back to top |
|
 |
Never Again I post too much
Reputation: 0
Joined: 13 Jan 2007 Posts: 2000 Location: New Mexico
|
Posted: Sat Jan 05, 2008 11:18 pm Post subject: |
|
|
| How can I define which text file I'm looking for. I've searched.
|
|
| Back to top |
|
 |
rapion124 Grandmaster Cheater Supreme
Reputation: 0
Joined: 25 Mar 2007 Posts: 1095
|
Posted: Sun Jan 06, 2008 8:50 am Post subject: |
|
|
| Have an edit box and the user can type in the name of the file into the edit box. Or you can just use an open dialog.
|
|
| Back to top |
|
 |
smartz993 I post too much
Reputation: 2
Joined: 20 Jun 2006 Posts: 2013 Location: USA
|
Posted: Sun Jan 06, 2008 10:17 am Post subject: |
|
|
| The parameter in the functions called Path is where you put the path to the txt file. And yes, you could have an editbox that lets the user type in the path, and you can just use edit.text.
|
|
| Back to top |
|
 |
Never Again I post too much
Reputation: 0
Joined: 13 Jan 2007 Posts: 2000 Location: New Mexico
|
Posted: Sun Jan 06, 2008 10:37 am Post subject: |
|
|
So I'd use something like :
| Code: | function LoadText(Path: string):string;
var
TxtFile : TextFile;
stringread : string;
begin
try
AssignFile(TxtFile, Path.Application '\Resource\Text.txt') ;
Reset(TxtFile) ;
ReadLn(TxtFile, stringread) ;
CloseFile(TxtFile);
result:=stringread;
except
ShowMessage('Could not find proper .txt file');
end; |
I'm confused with the "Stringread" part. What would I put there?
|
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Sun Jan 06, 2008 2:06 pm Post subject: |
|
|
To be honest, i'd like to help you but i'm not going to read your small fonts like this, hurts my eyes.
until you use regular fonts i'll help (I'm not threating or anything, i'm just saying that the font and color you're using are hurting my eyes, so i don't wanna acquire my eyes)
|
|
| Back to top |
|
 |
Never Again I post too much
Reputation: 0
Joined: 13 Jan 2007 Posts: 2000 Location: New Mexico
|
Posted: Sun Jan 06, 2008 3:10 pm Post subject: |
|
|
So I'd use something like
| Code: | function LoadText(Path: string):string;
var
TxtFile : TextFile;
stringread : string;
begin
try
AssignFile(TxtFile, Path.Application '\Resource\Text.txt') ;
Reset(TxtFile) ;
ReadLn(TxtFile, stringread) ;
CloseFile(TxtFile);
result:=stringread;
except
ShowMessage('Could not find proper .txt file');
end; |
I'm confused with the "Stringread" part. What would I put there?
|
|
| Back to top |
|
 |
smartz993 I post too much
Reputation: 2
Joined: 20 Jun 2006 Posts: 2013 Location: USA
|
Posted: Sun Jan 06, 2008 5:44 pm Post subject: |
|
|
Don't change my function at all. All you have to do is:
| Code: |
Edit1.Text:=LoadText(YOURPATHHERE);
|
|
|
| Back to top |
|
 |
Never Again I post too much
Reputation: 0
Joined: 13 Jan 2007 Posts: 2000 Location: New Mexico
|
Posted: Sun Jan 06, 2008 5:56 pm Post subject: |
|
|
| smartz993 wrote: | Don't change my function at all. All you have to do is:
| Code: |
Edit1.Text:=LoadText(YOURPATHHERE);
|
|
What if other people had downloaded the project, and the .txt was in the folder. Wouldn't the path be different?
|
|
| Back to top |
|
 |
sponge I'm a spammer
Reputation: 1
Joined: 07 Nov 2006 Posts: 6009
|
Posted: Sun Jan 06, 2008 6:09 pm Post subject: |
|
|
The way they find files is if there is not "header" for the file path, and it is like say /Resource/asdf.txt it will search for the resource folder in the same one your application was executed in and then look for asdf.txt.
it you just do /asdf.txt it will search the same folder for asdf.txt
| Kaspersky wrote: | To be honest, i'd like to help you but i'm not going to read your small fonts like this, hurts my eyes.
until you use regular fonts i'll help (I'm not threating or anything, i'm just saying that the font and color you're using are hurting my eyes, so i don't wanna acquire my eyes) |
Meaning you don't have eyes? That clears up a lot of stuff.
_________________
|
|
| Back to top |
|
 |
|