Recent

Author Topic: Remember selected directory path.  (Read 5593 times)

Zath

  • Sr. Member
  • ****
  • Posts: 391
Remember selected directory path.
« on: July 23, 2014, 11:40:04 am »
How do I store a directory path for reuse once selected with SelectdirectoryDialog ?
I found Tinifile after searching here but can only find TIniPropStorage in my components.
The path is stored as drName.
I tried Edit1.text.Savetofile ('drName\myfile.ini');
I tried with a memo and used memo.lines.savetofile ..

Does the file need to exist first or can I create ini or txt files on the fly ?

Thanks for any guidance.


« Last Edit: July 23, 2014, 11:52:56 am by Zath »

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Remember selected directory path.
« Reply #1 on: July 23, 2014, 12:08:04 pm »
Code: [Select]
uses inifiles, ......
procedure savetoini(const aFileName:string);
var
  vIni : TIniFile;
begin
  vInit := Tinifile.Create(aFilename);
  try
    vini.writestring('Main','CurrentPath',MySelectedPathVar);
  finally
    vini.free;
  end;
end;
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Zath

  • Sr. Member
  • ****
  • Posts: 391
Re: Remember selected directory path.
« Reply #2 on: July 23, 2014, 01:07:48 pm »
Thanks Taazz, that'll help me move on.

So the savetofile method was the wrong route to take ?

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Remember selected directory path.
« Reply #3 on: July 23, 2014, 01:13:44 pm »
not all components have a savetofile method and those that they do they support some specific format ee the memo saves everything to a text file. There is no component that will save to an ini format directly that I'm aware of.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Zath

  • Sr. Member
  • ****
  • Posts: 391
Re: Remember selected directory path.
« Reply #4 on: July 23, 2014, 01:24:58 pm »
There's no real reason it has to be an ini file I suppose, a text file would work I presume.
I went the ini route as it seemed the correct option.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Remember selected directory path.
« Reply #5 on: July 23, 2014, 01:33:23 pm »
Tinifile has a format of varname=varvalue a plain text file does not give you that information with out extra coding and if you are going to code the above behavior any way why not use the ini files from the start
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Zath

  • Sr. Member
  • ****
  • Posts: 391
Re: Remember selected directory path.
« Reply #6 on: July 23, 2014, 01:40:01 pm »
Tinifile has a format of varname=varvalue a plain text file does not give you that information with out extra coding and if you are going to code the above behavior any way why not use the ini files from the start

Sounds good to me.

Ok, thanks for your help.

Zath

  • Sr. Member
  • ****
  • Posts: 391
Re: Remember selected directory path.
« Reply #7 on: July 23, 2014, 07:13:41 pm »
A little more info please.

Do I use this line when I want to read in from the file too ?
TInifile.Create(aFilename)

There's no TInifile.Open I presume.

Thanks

eric

  • Sr. Member
  • ****
  • Posts: 267

Zath

  • Sr. Member
  • ****
  • Posts: 391
Re: Remember selected directory path.
« Reply #9 on: July 23, 2014, 07:43:56 pm »
http://wiki.freepascal.org/Using_INI_Files

Yes, I'm on that now but still struggling to reopen the ini and get the info back.
Currently setting the readstring on my Form Oncreate event but not quite there yet.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Remember selected directory path.
« Reply #10 on: July 23, 2014, 07:54:25 pm »
A little more info please.

Do I use this line when I want to read in from the file too ?
TInifile.Create(aFilename)

There's no TInifile.Open I presume.

Thanks

Yes the code should be used as it is for reading too just change the writeSTring method call to readString and be aware that the last value is the default value that will be returned in case that the VarNAme is not found in the Main section in the ini file.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: Remember selected directory path.
« Reply #11 on: July 24, 2014, 08:30:58 am »
Are there more values written into the ini file?
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

Zath

  • Sr. Member
  • ****
  • Posts: 391
Re: Remember selected directory path.
« Reply #12 on: July 24, 2014, 10:30:27 am »
Are there more values written into the ini file?
Eventually there will be.
I'll be adding multiple headings and data lines.

 

TinyPortal © 2005-2018