Recent

Author Topic: ‘Absolute path’ and string path  (Read 3373 times)

stephanos

  • Jr. Member
  • **
  • Posts: 81
Re: ‘Absolute path’ and string path
« Reply #15 on: August 09, 2025, 08:54:04 pm »
a file

jamie

  • Hero Member
  • *****
  • Posts: 7829
Re: ‘Absolute path’ and string path
« Reply #16 on: August 09, 2025, 09:21:50 pm »
Well That is your problem.

You are extracting the complete list which has Line Feeds between the lines.

You only want a single like, even if that is the only one in the list.
Use FileName which is the one selected or if you want from the list

MyName := DlialogFiles[0];

 You should check also the count.
 If DialogFiles.Count <> 0 Then .....


Jamie
The only true wisdom is knowing you know nothing

stephanos

  • Jr. Member
  • **
  • Posts: 81
Re: ‘Absolute path’ and string path
« Reply #17 on: August 09, 2025, 09:29:43 pm »
3 of the 6 files

stephanos

  • Jr. Member
  • **
  • Posts: 81
Re: ‘Absolute path’ and string path
« Reply #18 on: August 09, 2025, 09:32:46 pm »
2 more files

stephanos

  • Jr. Member
  • **
  • Posts: 81
Re: ‘Absolute path’ and string path
« Reply #19 on: August 09, 2025, 09:33:33 pm »
the final file

cdbc

  • Hero Member
  • *****
  • Posts: 2856
    • http://www.cdbc.dk
Re: ‘Absolute path’ and string path
« Reply #20 on: August 09, 2025, 09:38:04 pm »
Hi
There is a #$0A character in your filename-string, I don't think that's any good... According to your debugger in th first pdf.
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

vangli

  • Jr. Member
  • **
  • Posts: 57
Re: ‘Absolute path’ and string path
« Reply #21 on: August 09, 2025, 09:58:53 pm »
Hi

Look at jamie's answer above.

Try
Code: Pascal  [Select][+][-]
  1. m3uPathFile := FileNameEdit.FileName;
or
Code: Pascal  [Select][+][-]
  1. m3uPathFile := FileNameEdit2.Strings[0];
The you should not get the LineFeed you are seeing.
Regards Bent

stephanos

  • Jr. Member
  • **
  • Posts: 81
Re: ‘Absolute path’ and string path
« Reply #22 on: August 09, 2025, 10:33:31 pm »
Dear All

Thanks

This has been a fantastic learning curve.  I can now debug.  I will be this more often.

In order to demonstrate the theory that I have additional chars in my string, I did this
   m3uPathFile := '[' + m3uPathFile + ']';
   Label3.Caption := m3uPathFile;

and the output is
[home/stephanos/PlayListV40-V2-TimeLimit-Cu
rrent-RunFromPC/ThePlayListFile.m3u
]

This appears to demonstrate that a newline char is included.  I will now correct the string.

The resolution
Code: Pascal  [Select][+][-]
  1. m3uPathFile := FileNameEdit2.DialogFiles[0];

And it is solved.  The if file exists is true

Thanks to all.  This is solved.

old_DOS_err

  • Jr. Member
  • **
  • Posts: 60
Re: ‘Absolute path’ and string path
« Reply #23 on: August 10, 2025, 12:56:05 pm »
Hi Staphanos,

Glad you got is sorted, those kind of bugs are really annoying, but also give great satisfaction when cracked.

A little tip, not just to you, but anyone else reading this. Seeing output when doing forms is difficult, apart from debugging, there is no simple way. In DOS, one can just use WriteLns (assume equivalent in unix). What I do when I need to see data when doing a form is a use a separate list, usually debug_list. Whenever I need to see anything, I add it to the list, which is basically just the equivalent of WriteLns.

Code: Pascal  [Select][+][-]
  1. // in either top level class or as a separate global var, so all of the program can see it
  2. debug_list : TStringList;  // zzz - if you look at my programs you will zzz a lot, it's an easy marker when add in test code or to do reminder
  3.     // Shift Control F is also very useful when doing a project as it searches all files (I usually just have set for open files)
  4. // ...
  5. debug_list := TStringList.Create;
  6. // then whever I need to see something the program is doing, I add to debug_list
  7. // say I have a method get_file_name which I have the string f, the filename,
  8. // which is not doing what I expect
  9.  
  10. Function a_class.get_file_name( Const i : DWord ) : Boolean;  // file op methods should be boolean, as numerous things can go wrong
  11. // <some code in which f is assigned the filename>
  12.   debug_list.Add( 'In method: get_file_name, checking var f' );  // so when you look at the debug file you know what the following line refers to
  13.   debug_list.Add( 'i = ' + i.ToString + ',  f = ' + f );  // Add only takes 1 string, so have to use + instead of ,
  14.       // and all parts must be strings, the .ToString is very useful, can be used as a very easy number to string converter anywhere (not purist tho)
  15.   debug_list.Add ( '' );  // just adds a blank line, us humans don't do well with solid blocks
  16. //...
  17.  
  18. // now at the end of the program, just before the final close up
  19.   debug_list.SaveToFile( 'debug_file.txt' );  // use any extension for an easy modern text editor
  20.     // most modern text editors will take UTF8 or unicode, so non standard chars will show up
  21.     // if control chars, such as linefeed, were embedded they will show up, see demo below
  22.    FreeAndNil( debug_list );  // remember to free up, now have sent to file can close
  23.  

This demo shows that a string with an embedded linefeed can be seen in the output file:

Code: Pascal  [Select][+][-]
  1. Procedure test_embed;
  2. {
  3.   When this is run it can be seen that the file has a blank line after "A string", this would not be there without the added linefeed.
  4.   So this little demo illustrates that pascal, correctly, does not check the contents of the string, either when added to the list or
  5.   sent to the file.
  6.  
  7.   These types of little demos are invaluable when you just want to check the way a command works.
  8. }
  9.   Var
  10.     temp_list : TStringList;
  11.     s : String;
  12.  
  13.   Begin
  14.     temp_list := TStringList.Create;
  15.  
  16.     s := 'A string' + #13 + #10;  // this is DOS & Windows end of line, unix as I understand it has just one char, but still the same
  17.     temp_list.Add( 'start line' );
  18.     temp_list.Add( s );
  19.     temp_list.Add( 'end line' );
  20.     temp_list.SaveToFile( 'demo.npp' );  // npp is just my extension for Notepad++, use txt for notepad or any other extension
  21.       // pascal adds end of line after each string, but as can be seen, does not check what it is in the string
  22.     FreeAndNil( temp_list );
  23.   End;
  24.  

In my old age, my testing is often better than my actual code.

Phil
« Last Edit: August 10, 2025, 04:09:02 pm by old_DOS_err »

wp

  • Hero Member
  • *****
  • Posts: 13625
Re: ‘Absolute path’ and string path
« Reply #24 on: August 10, 2025, 02:32:39 pm »
Logging capabilities are already built into Lazarus: https://wiki.freepascal.org/LazLogger.

Add unit "LazLoggerBase" to the unit(s) to be debugged, and in one of the project units add unit "LazLogger" to the uses clause. Then, instead of Writeln(some_message1, some_message2, ...) add "DebugLn([some_message, some_message2, ...])" instructions to the code wherever needed (note the square brackets). There are several overloads of the DebugLn instruction, but the one with the square brackets allows to add an arbitrary number of arguments of any printable type. Finally, when the program runs, every DebugLn line will be written to the console (if it exists; in Windows uncheck the "Win32 gui application (-WG)" option in "compiler options" > "config and targets". Or when the application is started with the commandline argument "--debug-log=name_of_the_logfile" the output will be written to the specified logfile.

old_DOS_err

  • Jr. Member
  • **
  • Posts: 60
Re: ‘Absolute path’ and string path
« Reply #25 on: August 10, 2025, 02:55:56 pm »
Thank you for that info WP, I didn't know that (I haven't really upgraded my knowledge since Turbo Pascal and hardly use any of the Free Pascal tools, leading to reinventing the wheel very often).

It seems a matter of choice. With the list method, getting it do the file seems a tad easier, as done totally in the program. Also there is a tiny issue with Array Of Const, in the V types there is no entry for DWord (unless that has been fixed very recently), I usually convert DWord to string.

I'll check that debug feature when I next write something worthy of debugging (poor record of late) :D

Phil

stephanos

  • Jr. Member
  • **
  • Posts: 81
Re: ‘Absolute path’ and string path
« Reply #26 on: August 10, 2025, 03:22:57 pm »
Thanks guys, all interesting tips

 

TinyPortal © 2005-2018