Recent

Author Topic: Compile Error on Assign for Search Files  (Read 1216 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 16805
  • Ceterum censeo Trump esse delendam
Re: Compile Error on Assign for Search Files
« Reply #15 on: April 15, 2025, 01:13:31 pm »
Benny, you are a kid compared to me  :'(
Changing servers. thaddy.com may be temporary unreachable but restored when the domain name transfer is done.

cdbc

  • Hero Member
  • *****
  • Posts: 2100
    • http://www.cdbc.dk
Re: Compile Error on Assign for Search Files
« Reply #16 on: April 15, 2025, 01:17:08 pm »
Oooohhhh Thaddy, you make me feel all warm and fuzzy  :D
Me likey, but I'm still snapping on your heels  ;D
Regards /ze youngsta/
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

Khrys

  • Full Member
  • ***
  • Posts: 215
Re: Compile Error on Assign for Search Files
« Reply #17 on: April 15, 2025, 01:50:18 pm »
Code: Pascal  [Select][+][-]
  1. // [...]
  2.   End Else Begin
  3.     AsSign(F3,Find.Name);
  4.     ReSet(F3);
  5.     Close(F3);
  6.   End;
  7. // [...]

It's been a while since the word boundary between ad- and signō disappeared (around 2000 years, give or take) - are you an ancient Roman by any chance?  ;)

Kidding aside, case insensitivity is my least favourite thing about Pascal. I really wish the following wouldn't compile:

Code: Pascal  [Select][+][-]
  1. funCtION fOo(cONSt bAR: stRing): STRing;
  2. bEGin
  3.   rEsulT := aNsiupPERcASe(baR);
  4. eNd;

cdbc

  • Hero Member
  • *****
  • Posts: 2100
    • http://www.cdbc.dk
Re: Compile Error on Assign for Search Files
« Reply #18 on: April 15, 2025, 02:25:47 pm »
Hi
@Khrys: I just rearranged TS code a bit, for readability, didn't do anything to the casing...  %)
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

ASerge

  • Hero Member
  • *****
  • Posts: 2404
Re: Compile Error on Assign for Search Files
« Reply #19 on: April 16, 2025, 02:58:48 am »
If we ignore the fact that the code is meaningless, then in my opinion, in order to be correct, the code should be like this:
Code: Pascal  [Select][+][-]
  1. {$mode objfpc}{$H+}
  2.  
  3. uses SysUtils;
  4.  
  5. var
  6.   FA, FB, FOther: TextFile;
  7.   SearchRec: TSearchRec;
  8.   WhereToSearch: string;
  9. begin
  10.   AssignFile(FA, 'A.txt');
  11.   Reset(FA);
  12.   try
  13.     Readln(FA, WhereToSearch);
  14.   finally
  15.     CloseFile(FA);
  16.   end;
  17.   AssignFile(FB, 'B.txt');
  18.   Rewrite(FB);
  19.   try
  20.     if FindFirst(WhereToSearch, faAnyFile, SearchRec) = 0 then
  21.     try
  22.       repeat
  23.          AssignFile(FOther, SearchRec.Name);
  24.          if (SearchRec.Attr and faDirectory) = 0 then
  25.          begin
  26.            Reset(FOther);
  27.            try
  28.              // Do something with FB and FOther
  29.            finally
  30.              CloseFile(FOther);
  31.            end;
  32.          end;
  33.       until FindNext(SearchRec) <> 0;
  34.     finally
  35.       FindClose(SearchRec);
  36.     end;
  37.   finally
  38.     CloseFile(FB);
  39.   end;
  40. end.

turunk

  • New Member
  • *
  • Posts: 16
Re: Compile Error on Assign for Search Files
« Reply #20 on: April 19, 2025, 04:19:49 pm »
i use lazarus 3.8 and the dos unit seems as windows version and take longnames.
cFileName: array[0..MAX_PATH-1] of Char;
if i write 3.assign(F3,'C.txt'); it will success, but i need a variable variable set by reading.

Thaddy

  • Hero Member
  • *****
  • Posts: 16805
  • Ceterum censeo Trump esse delendam
Re: Compile Error on Assign for Search Files
« Reply #21 on: April 19, 2025, 04:27:02 pm »
ASerge is as - almost - usual correct.
Changing servers. thaddy.com may be temporary unreachable but restored when the domain name transfer is done.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12153
  • FPC developer.
Re: Compile Error on Assign for Search Files
« Reply #22 on: April 20, 2025, 03:10:08 pm »
In general avoid unit Dos, and use unit sysutils. I haven't used unit Dos in decades, other than the odd INTR() call when I still did (some) dos.

 

TinyPortal © 2005-2018