Recent

Author Topic: Need help with project managment  (Read 1664 times)

lazarusprogrammer

  • New Member
  • *
  • Posts: 10
Need help with project managment
« on: March 10, 2026, 04:23:13 pm »
hi, Look.

I am trying to organize project in a better way but facing this problem. I need access to files in root folder from unit that sits in sub folder.

for example :

folder1/folder2/unit2.pas
folder1/*.ini


So i need access to *.ini file from unit2.pas. Is it even possible or i am doing something stupid?



cdbc

  • Hero Member
  • *****
  • Posts: 2715
    • http://www.cdbc.dk
Re: Need help with project managment
« Reply #1 on: March 10, 2026, 05:16:55 pm »
Hi
Yes it is possible in a lot of ways...
In Lazarus -> 'Project' -> 'Project Options' -> 'Paths' -> 'Other unit files(-Fu)'
You have to enter the paths to your different files, then they're visible inside your application...

Another approach to get your 'root' dir:
Code: Pascal  [Select][+][-]
  1. fRootDir:= ExtractFilePath(ParamStr(0)); /// or
  2. fRootDir:= Application.Location;
  3. /// e.g.:
  4. fYourIniFile:= TInifile.Create(fRootDir+'project1.ini');
If you have your /ini-stuff/ in a separate unit, you can reach it from all over the place, just ref' it in uses...  8)
If you have some code, then show us -- makes it a lot easier to understand exactly what you want and help you  ;)
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

lazarusprogrammer

  • New Member
  • *
  • Posts: 10
Re: Need help with project managment
« Reply #2 on: March 10, 2026, 06:09:03 pm »
Quote
If you have some code, then show us -- makes it a lot easier to understand exactly what you want and help you  ;)
Regards Benny
I am just messing around so i can give the whole project but i don't think it's necessary.

I better explain. I have main app in root folder and i made sub folder for another form that will be spawned from main app but i need access to at least that ini file from main app folder. This other form is like settings form for main application. So it's like separate app. So i guess ExtractFilePath wouldn't give me root of main app. But i can pass this ExtractFilePath from main app to setting app as a string and it probably gonna be root path of main app. Seems messy but i will try.

cdbc

  • Hero Member
  • *****
  • Posts: 2715
    • http://www.cdbc.dk
Re: Need help with project managment
« Reply #3 on: March 10, 2026, 06:36:19 pm »
Hi
This:
Code: Pascal  [Select][+][-]
  1. fRootDir:= ExtractFilePath(ParamStr(0));
should work in _any_ of your units, as long as you include 'SysUtils' in the uses clause...
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

dseligo

  • Hero Member
  • *****
  • Posts: 1678
Re: Need help with project managment
« Reply #4 on: March 10, 2026, 07:15:04 pm »
So i need access to *.ini file from unit2.pas. Is it even possible or i am doing something stupid?

Do you need to access ini file at design time or runtime? Because, if it is at runtime, then location of ini file is only important from location of exe file, not where your units are located (they are all compiled in one exe).

mas steindorff

  • Hero Member
  • *****
  • Posts: 568
Re: Need help with project managment
« Reply #5 on: March 10, 2026, 07:25:29 pm »
FYI: sounds a lot like your main could use something like a TFrame.  This "component" is a separate unit and form you build that can live on a something like a tpanel on the main form. You can program this mini panel with it's own buttons and fields and have it pass a result back to your main form to work with or give your Frame the ability to send and receive directly, read to save to file, (...) .
I started using them years ago and enjoy the power of just dropping them where ever I need them. I keep mine simple so they are mostly self contained and have calls from the parent form for initial settings and result handling.
I keep these units in a '../common' folder apart from the main project (at the same level). then use cdbc path trick to include into the project.  you can still use the .ini in Main for position, size, color, font, paths,...  and pass a subset of them to the Tframe (font, color, path...). there are some tricks to using them but I think they have all been called out in this forum.
windows 10 &11, Ubuntu 21+ IDE 3.4 general releases

bobihot

  • New Member
  • *
  • Posts: 47
Re: Need help with project managment
« Reply #6 on: March 11, 2026, 08:44:13 am »
fRootIni:= '..\*.ini';

lazarusprogrammer

  • New Member
  • *
  • Posts: 10
Re: Need help with project managment
« Reply #7 on: March 11, 2026, 11:03:23 am »
Thanks for answers guys thanks a lot.

BUT

This is not exactly what i need.

Quote
fRootDir:= ExtractFilePath(ParamStr(0));
Quote
fRootIni:= '..\*.ini';

I am just a couple month old programmer and i am most likely doing things in a wrong way. But i am trying to figure the way to do stuff that fits lest say my style.

I don't like it when it's a lot of files in one folder. I don't like it when i have lots of tabs opened in my project. So in attempt to make my life easier i've made separate settings application for the main application that will be included in main app when it will be compiled. But i am working on this settings app separately from main app.

I mean you are right your methods are working when i am compiling main app. But when i am working separately with settings app i can't get ini file from root folder of main app because settings app are located in sub folder of main app. bobihot suggestions to use "..\*.ini" seems like a good trick but not working for some reason. And cdbc's ExtractFilePath(ParamStr(0)); making me a new ini file inside settings app folder and not using ini that located in root folder of main app.


Probably the best and the only way is to put settings Tform in a root folder to have easy access to ini file but keep all the Tframes in a sub folder to make root folder less messy as steindorff suggested.

I understand my explanations is not the best so if you are really curious look for attachment. Whole project some sort of fpc ide i am making for no particular reason rather then messing around and learning.

cdbc

  • Hero Member
  • *****
  • Posts: 2715
    • http://www.cdbc.dk
Re: Need help with project managment
« Reply #8 on: March 11, 2026, 11:54:44 am »
Hi
Okidoki - got it  ;D
1.st):
Code: Pascal  [Select][+][-]
  1. function BackUpOneDir(const aPath: string): string;
  2. var li: integer;
  3. begin
  4.   if aPath = '' then exit(aPath); /// well duh!
  5.   { user entered just a directory name, no path -> return it without 'pathdelim', on *nix return slash }
  6.   if pos(PathDelim,aPath) = 0 then Result:= {$ifdef unix}PathDelim{$else}aPath{$endif}
  7.   else begin { find the last 'pathdelim' in string & copy last part to result }
  8.     li:= Length(aPath);
  9.     if aPath[li] = PathDelim then dec(li); /// could end in a 'pathdelim', skip that
  10.     while ((li > 0) and (aPath[li] <> PathDelim)) do dec(li); /// scan backwards
  11.     { from start to idx (incl.) }
  12.     if li > 0 then Result:= copy(aPath,1,li)
  13.     else Result:= PathDelim; /// it has to be a valid path, ergo '/'
  14.   end;
  15. end;
2.nd):
Code: Pascal  [Select][+][-]
  1. fMainRootDir:= BackUpOneDir(ExtractFilePath(ParamStr(0)));
Will now serve you the "Main" application's /root-dir/, from the 'Settings'-app -- provided it resides in the first sub-dir-level  8-)
HTH & Have fun  :D
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

dseligo

  • Hero Member
  • *****
  • Posts: 1678
Re: Need help with project managment
« Reply #9 on: March 11, 2026, 12:12:04 pm »
Hi
Okidoki - got it  ;D
1.st):
Code: Pascal  [Select][+][-]
  1. function BackUpOneDir(const aPath: string): string;
  2. var li: integer;
  3. begin
  4.   if aPath = '' then exit(aPath); /// well duh!
  5.   { user entered just a directory name, no path -> return it without 'pathdelim', on *nix return slash }
  6.   if pos(PathDelim,aPath) = 0 then Result:= {$ifdef unix}PathDelim{$else}aPath{$endif}
  7.   else begin { find the last 'pathdelim' in string & copy last part to result }
  8.     li:= Length(aPath);
  9.     if aPath[li] = PathDelim then dec(li); /// could end in a 'pathdelim', skip that
  10.     while ((li > 0) and (aPath[li] <> PathDelim)) do dec(li); /// scan backwards
  11.     { from start to idx (incl.) }
  12.     if li > 0 then Result:= copy(aPath,1,li)
  13.     else Result:= PathDelim; /// it has to be a valid path, ergo '/'
  14.   end;
  15. end;
2.nd):
Code: Pascal  [Select][+][-]
  1. fMainRootDir:= BackUpOneDir(ExtractFilePath(ParamStr(0)));
Will now serve you the "Main" application's /root-dir/, from the 'Settings'-app -- provided it resides in the first sub-dir-level  8-)
HTH & Have fun  :D
Regards Benny

Simpler:
Code: Pascal  [Select][+][-]
  1. fMainRootDir:= ExtractFileDir(ExtractFileDir(ParamStr(0))) + PathDelim;

@lazarusprogramer: you have to make sure that your settings application is always in subdirectory of settings file.
You could also instruct Lazarus to put your settings application and your main application in some 3rd directory - that way you can organize sources as you want and still have executables together.
Another option is that you can have one more ini file. This file is in the same place as settings application. In that ini file you write path to main application ini file. That way your settings application can be anywhere.

But, the best solution is to use GetAppConfigDir function (https://www.freepascal.org/docs-html/rtl/sysutils/getappconfigdir.html). That way settings are not with your executable (which could be in read-only place).

 

TinyPortal © 2005-2018