Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

config form

Status
Not open for further replies.

mkzw0ot4m0nk

Programmer
Jul 19, 2002
29
US
hey, i made a program that shows the current song that is being played on winamp and the song name uploads to my site. many of my friends want this program and i dont mind them using it but i have it configured for me. how can i make a configure form so they can enter there ftp stuff and click ok and it will then be configured for them? im using IdFTP heres the section of code for that.

IdFTP1.Host := 'ftp.myurl.com';
IdFTP1.User := 'myusername';
IdFTP1.Password := 'mypassword';
IdFTP1.Connect(true);
IdFTP1.ChangeDir('public_html/mystuff);
IdFTP1.Put('c:\currentsong.txt','currentsong.txt',false);
IdFTP1.Disconnect;

THANKS
 
Just create a form with fields for the user specific data you've listed there and use a TIniFile object to store it in a .ini file.
 
i did do help, but i cant fine the freakin object to put on the form? what section is it under?
 
No, you have to explcitly declare/instantiate it yourself.
eg.
Code:
var
ini: TIniFile;
...

ini := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'settings.ini');
 
Don't forget to free the Inifile after you finish with it. Something like this.


var
ini: TIniFile;
...

try
ini := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'settings.ini');
{...process ini here...}
finally
ini.free;
end; {try/finally}

This code assures that even if something goes wrong while processing, the program will still release the memory being used by ini.
 
ive been lookin everywhere for help with tinifile. can someone give me a example program? link? how to do it?
 
Fluke, constructors should be called outside try..finally/except blocks. Your example:
Code:
try
   ini := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'settings.ini');
   {...process ini here...}
finally
   ini.free;
end;
Here if TIniFile.Create fails ini.Free would give you an Access Violation.

mkzw0ot4m0nk if you have Delphi help then in your code (anywhere) type TIniFile, select it and press Ctrl+F1.
Don't forget to delete word TIniFile afterwards. If you don't have Delphi help, then get it! You can also find IniFiles.pas file somewhere in your Delphi directory open it, find declaration of TIniFile class and look at the public properties and methods of it. Their names will tell you a lot, trust me.

--- markus
 
On your application's startup do something like this to read the values from the file:
Code:
   ini := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'settings.ini');
   IdFTP1.User := ini.ReadString('Settings', 'Username', '');
   ...
   etc.
   ini.free;
And when you want to save config settings to the file just do something like:
Code:
   ini := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'settings.ini');
   ini.WriteString('Settings', 'Username', usernameEdit.Text);
   ...
   etc.
   ini.free;
The ini you're writing to/reading from will look something like

[Settings]
Username=Bob
Password=pwd

etc.
 
thanks a lot for helping me guys. just one more question, how can i have it try to attempt to connect if the configure window is open?
 
Are you asking how to test the connection settings?
Code:
try
   IdFTP1.Connect(true);
except
   //couldn't connect
end;
 
oops dangit, i meant...
how can i make it NOT try to attempt to connect when the configure page is open?
 
cuz my program was designed to connect on startup without them clicking connect.. how can i have it NOT connect when the Configure window is open?
 
Well surely you just need to disconnect when they open the configure window? Or are you saying that the config tool will be a separate application?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top