Compile Error on Assign for Search Files lazarus / 8-Other ---------------------------------------------------------------------- turunk · 2025-04-08 21:42 i wanted to search with files, but i got the error "Finderror1.lpr(20,18) Error: Can't determine which overloaded function to call" , 2 times assign had no given error but then he gave this error, see: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Program Finderror1;   Uses Dos;   Var F1,F2:Text;    F3:Text;    T1:String;  Find:SearchRec;    FA:Byte; Begin  AsSign(F1,'A.Txt');ReSet(F1);  ReadLn(F1,T1);  AsSign(F2,'B.Txt');ReWrite(F2);  FindFirst(T1,$3F,Find);  Repeat    If FA=0      Then Begin WriteLn(F2,'FA is 0');                 FindNext(Find);End      Else Begin AsSign(F3,Find.WinFindData.cFileName);                 ReSet(F3);                 Close(F3);    End;  Until Dos.DosError=18;  Close(F1);Close(F2);  FindClose(Find);End. ---------------------------------------------------------------------- speter · 2025-04-08 22:01 G'Day turunk, 1) Variable "FA" is not initialised. Did you mean to write: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i FA := FindFirst(T1,$3F,Find);2) With SearchRec type variables, I use find.filename for the matching filename...!? cheers S. ---------------------------------------------------------------------- cdbc · 2025-04-08 22:45 Hi These 2 DON'T MIX: "Find.WinFindData.cFileName" & "Find:SearchRec;" Instead you should use 'Find.Name'. Look in the FPC Wiki or documentation, for examples on how to do the search properly... Regards Benny ---------------------------------------------------------------------- turunk · 2025-04-09 05:49 no, the problem is the 3rd assign. fa has not to be initialized. if i compile he makes no problem at 1st and 2nd assign. Find.WinFindData.cFileName is for the long names. ---------------------------------------------------------------------- cdbc · 2025-04-09 06:15 Hi This compiles for me (on Linux):Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program find_errors;   Uses Dos;   Var F1,F2:Text;    F3:Text;    T1:String;  Find:SearchRec;    FA:Byte; begin  Assign(F1,'A.Txt'); Reset(F1);  ReadLn(F1,T1);  AsSign(F2,'B.Txt');ReWrite(F2);  FindFirst(T1,$3F,Find);  Repeat    If FA=0      Then Begin WriteLn(F2,'FA is 0');                 FindNext(Find);End      Else Begin AsSign(F3,Find.Name); //<-- ONLY CHANGE!                 ReSet(F3);                 Close(F3);    End;  Until Dos.DosError=18;  Close(F1);Close(F2);  FindClose(Find);end.Regards Benny ---------------------------------------------------------------------- turunk · 2025-04-14 18:02 but the compiler points to the A of assign. not the variable is the problem. ---------------------------------------------------------------------- cdbc · 2025-04-14 18:22 Hi Assign has many overloads, so we need to know the exact error-message and what type "Find.WinFindData.cFileName" is?!? Is it: - array[0..255] of char - pchar - pwidechar - shortstring - string (ansi / rawbytestring) - widestring - unicodestring Note: I have no winders to test against/on... so you're up. Regards Benny ---------------------------------------------------------------------- TRon · 2025-04-14 18:33 Quote from: cdbc on April 14, 2025, 08:22:59 pmAssign has many overloads, so we need to know the exact error-message and what type "Find.WinFindData.cFileName" is?!? Windows. Also note the usage of the absolete dos unit. This is not the way to search for files unless doing it for windows only and in which case all these pascal encapsulation is redundant and counterproductive. 2 cents. @turunk: Here (scroll down) is a short example of how it should look like doing it as intended. ---------------------------------------------------------------------- cdbc · 2025-04-14 18:58 Hi TRon Oddly enough, this works like a charm on Linux:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program find_errors;   Uses Dos;   Var F1,F2:Text;    F3:Text;    T1:String;  Find:SearchRec;    FA: SmallInt;    iores: word; begin  Assign(F1,'a.txt'); Reset(F1);  ReadLn(F1,T1);  AsSign(F2,'b.txt');ReWrite(F2);  FindFirst(T1,$3F,Find);  Repeat    FA:= DosError;    If FA = 0 Then Begin      writeln(f2,'FA is 0 - ',Find.Name);      FindNext(Find);    End Else Begin      AsSign(F3,Find.Name);      ReSet(F3);      Close(F3);    End;  Until Dos.DosError=18;  Close(F1);Close(F2);  FindClose(Find);end.  ...don't ask me to explain why  Regards Benny ---------------------------------------------------------------------- Thaddy · 2025-04-14 20:22 Well, he should not have used the dos unit. On Windows it is a bit like this, on Linux it is as you wrote:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program find_errors;{$H-}{$I-}uses sysutils;Var  F1,F2,F3:Text; T1:String; Find:TSearchRec; FA: SmallInt; begin  ExceptProc := nil;// disable SEH exceptions!!  Assign(F1,'a.txt'); Reset(F1);  ReadLn(F1,T1);  AsSign(F2,'b.txt');ReWrite(F2);  FindFirst(T1,$3F,Find);  Repeat    FA:= IOResult;    If FA = 0 Then Begin      writeln(f2,'FA is 0 - ',Find.Name);      FindNext(Find);  End Else Begin      AsSign(F3,Find.Name);      ReSet(F3);      Close(F3);    End;  Until IOResult = 0;// 18 is wrong  Close(F1);Close(F2);  FindClose(Find);end.   BTW that also compiles for linux... It is also quirky, since sysutils is drawn in exceptions are pulled in so for this code you could not use IOResult error handling. In the above code I simply disabled SEH exceptions. ---------------------------------------------------------------------- TRon · 2025-04-14 20:48 Hi cdbc, Quote from: cdbc on April 14, 2025, 08:58:49 pmOddly enough, this works like a charm on Linux: It does, this is just the most cringe code I've seen in ages. No idea what TS is trying to accomplish but... Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program finder; {$mode objfpc}{$h+} uses  classes, Sysutils; procedure Foo; begin end;procedure Bar; begin end; var  Filenames: TStringList;  Filename : string;begin  Filenames := TStringList.Create;  Filenames.LoadFromFile('a.txt');   for Filename in Filenames do    if FileExists(Filename)     then Foo      else Bar;  Filenames.Free;end.  fwiw it amazes me that TS was able to compile that code with not including a windows unit of some sorts. Apparently we like to fish (hint: no, we don't). edit: forgot to copy-paste the line that actually loads the list of filenames. Corrected now. ---------------------------------------------------------------------- Thaddy · 2025-04-14 20:53 I certainly could not get that original code to work on windows because here on win64 I get a file not found error for the dos unit. And if he is on linux the change from cdbc is correct:Find.WinFindData.cFileName does not exist. find.name does. (It seems old TP code) ---------------------------------------------------------------------- TRon · 2025-04-14 21:14 @Thaddy: Pretty sure it is old tp code but referring to undefined types in example code used to depict an error is simply a fishing expedition. Nice if you have the time for such otherwise .... ---------------------------------------------------------------------- Thaddy · 2025-04-15 07:20 Quote from: turunk on April 09, 2025, 07:49:53 amno, the problem is the 3rd assign. fa has not to be initialized. if i compile he makes no problem at 1st and 2nd assign. Find.WinFindData.cFileName is for the long names. The DOS searchrecord does not support long filenames. Never has. Either you use my code or you need to rewrite the application such that it uses the low level windows search API. Btw, that is the only place your effort errs, nothing to do with the file handles. To put it simple: the dos unit is not for windows and it is made invisible for windows. That old TP code may compile on windows but not with long filenames. For that, the more "modern" file search API is needed (well that is "only" 35 years old, 1990) as is implemented in sysutils. ---------------------------------------------------------------------- cdbc · 2025-04-15 08:26 Hi If I'd have to hazard a guess  ...It would put the original code from TS, in the pre-TP5.5 era, most likely 4.0    Just after the introduction of the 'Unit'-system. Pretty good memory for such an old fart, like me  Regards Benny ---------------------------------------------------------------------- Thaddy · 2025-04-15 11:13 Benny, you are a kid compared to me  :'( ---------------------------------------------------------------------- cdbc · 2025-04-15 11:17 Oooohhhh Thaddy, you make me feel all warm and fuzzy  Me likey, but I'm still snapping on your heels  Regards /ze youngsta/ ---------------------------------------------------------------------- H₂SO₄ · 2025-04-15 11:50 Quote from: cdbc on April 14, 2025, 08:58:49 pmCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i // [...]  End Else Begin    AsSign(F3,Find.Name);    ReSet(F3);    Close(F3);  End;// [...] 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i funCtION fOo(cONSt bAR: stRing): STRing;bEGin  rEsulT := aNsiupPERcASe(baR);eNd; ---------------------------------------------------------------------- cdbc · 2025-04-15 12:25 Hi @Khrys: I just rearranged TS code a bit, for readability, didn't do anything to the casing...  Regards Benny ---------------------------------------------------------------------- ASerge · 2025-04-16 00:58 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$mode objfpc}{$H+} uses SysUtils; var  FA, FB, FOther: TextFile;  SearchRec: TSearchRec;  WhereToSearch: string;begin  AssignFile(FA, 'A.txt');  Reset(FA);  try    Readln(FA, WhereToSearch);  finally    CloseFile(FA);  end;  AssignFile(FB, 'B.txt');  Rewrite(FB);  try    if FindFirst(WhereToSearch, faAnyFile, SearchRec) = 0 then    try    repeat         AssignFile(FOther, SearchRec.Name);         if (SearchRec.Attr and faDirectory) = 0 then         begin           Reset(FOther);           try             // Do something with FB and FOther           finally             CloseFile(FOther);           end;         end;      until FindNext(SearchRec) <> 0;    finally    FindClose(SearchRec);    end;  finally    CloseFile(FB);  end;end. ---------------------------------------------------------------------- turunk · 2025-04-19 14:19 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 · 2025-04-19 14:27 ASerge is as - almost - usual correct. ---------------------------------------------------------------------- marcov · 2025-04-20 13:10 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. ---------------------------------------------------------------------- turunk · 2025-04-25 12:30 i solved it so: stringtypeof-assign:=valueofothervariable; assign(f,stringtypeof-assign); ---------------------------------------------------------------------- turunk · 2025-05-03 23:20 i have found not at sysutils the findfirst. how findfirst with longnames and even path longer than 256 chars? ---------------------------------------------------------------------- Thaddy · 2025-05-04 08:21 On windows put the find strings in double brackets for long filenames. Fisrt single ' then ", so '"d:\somedir\a long filename"' ---------------------------------------------------------------------- bytebites · 2025-05-04 10:15 " is quotation mark not bracket. ---------------------------------------------------------------------- Thaddy · 2025-05-04 15:32 Yes I know. Tired. ---------------------------------------------------------------------- turunk · 2025-05-05 13:10 thaddy, no i meant, if findfirst is not in sysutils, where i can find this procedure, which searches longnames. and the question: how is searchrec.twinfinddata.cfilename with 256 chars and searchrec.name a string, if they are for 8.3