Recent

Author Topic: My ReturnDirContents Code.. need your help on this one guys...  (Read 7614 times)

captian jaster

  • Guest
I need help on Fixing he errors i get in this.
Heres the Record:
Code: [Select]
TRDirConREC = Record
 Count:LongInt;
 Info:TSearchREC;
 AllowWrite,FoundFiles:Boolean;
 WriteInfo,WriteCount:String;
 end;

Main Procedure:
Code: [Select]
Procedure ReturnDirContents;
BEGIN
  With RDirCon Do
   begin
     Count:=0;
     IF FindFirst('*',FAanyFile,FADirectory)=0Then
     begin
       Repeat
       INC(Count);
        With Info Do
        begin
          WriteInfo := Name:40,Size:15;
          IF(Attr AND FADirectory)= FADirectory Then
          IF(AllowWrite = True)Then
          Write('Dir:');
          Writeln(Name:40,Size:15);
        end;
       Until(FindNext(Info)<>0);
     end;
     FindClose(Info);
     WriteCount := Count;
     IF(Count <>0)Then FoundFiles := True Else FoundFiles := False;
     IF(AllowWrite = True)Then Writeln('Number Of Content in Folder:',WriteCount);
   end;
END;

Errors I get:
Quote
FFU.pas(53,44) Error: Call by var for arg no. 3 has to match exactly: Got "ShortInt" expected "TSearchRec"
Hint: Found declaration: FindFirst(const AnsiString, LongInt,out TSearchRec):LongInt;
FFU.pas(59,28) Fatal: Syntax error, ";" expected but ":" found
Help!

Zoran

  • Hero Member
  • *****
  • Posts: 1830
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: My ReturnDirContents Code.. need your help on this one guys...
« Reply #1 on: April 26, 2010, 07:12:13 pm »
Quote
FFU.pas(53,44) Error: Call by var for arg no. 3 has to match exactly: Got "ShortInt" expected "TSearchRec"
Hint: Found declaration: FindFirst(const AnsiString, LongInt,out TSearchRec):LongInt;

So, this line is wrong:
Code: [Select]
     IF FindFirst('*',FAanyFile,FADirectory)=0Then

it should probably be:
Code: [Select]
     IF FindFirst('*', FAanyFile or FADirectory, info)=0 Then


Quote
FFU.pas(59,28) Fatal: Syntax error, ";" expected but ":" found
Look at this line:
Code: [Select]
          WriteInfo := Name:40,Size:15;
You declared WriteInfo as string, so on the right side of assignment, you must provide a string. This should probably be (enclosed in quotes):
Code: [Select]
          WriteInfo := 'Name:40,Size:15';

captian jaster

  • Guest
Re: My ReturnDirContents Code.. need your help on this one guys...
« Reply #2 on: April 26, 2010, 07:22:59 pm »
Quote
FFU.pas(53,44) Error: Call by var for arg no. 3 has to match exactly: Got "ShortInt" expected "TSearchRec"
Hint: Found declaration: FindFirst(const AnsiString, LongInt,out TSearchRec):LongInt;

So, this line is wrong:
Code: [Select]
     IF FindFirst('*',FAanyFile,FADirectory)=0Then

it should probably be:
Code: [Select]
     IF FindFirst('*', FAanyFile or FADirectory, info)=0 Then


Quote
FFU.pas(59,28) Fatal: Syntax error, ";" expected but ":" found
Look at this line:
Code: [Select]
          WriteInfo := Name:40,Size:15;
You declared WriteInfo as string, so on the right side of assignment, you must provide a string. This should probably be (enclosed in quotes):
Code: [Select]
          WriteInfo := 'Name:40,Size:15';

WriteInfo is wrong. i know that, i just dont know what kinda of variable to set it to. Its not that im writing Name:40,Size:15
into the console. im trying to work with the FindClose Name And Size Vars... This Is Difficult... Heres What i worked off of..
http://www.freepascal.org/docs-html/rtl/sysutils/findfirst.html

That and i still get the some errors on compile... Its Not this thats wrong:
Code: [Select]
IF FindFirst('*',FAanyFile,FADirectory)=0ThenIts That it expected some thing from the Info TSearchREC; and i cant fix it. I Suspect its Cuz of my First With Declaration. got the compiler confused..
BART! Get TO IT!

Zoran

  • Hero Member
  • *****
  • Posts: 1830
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: My ReturnDirContents Code.. need your help on this one guys...
« Reply #3 on: April 26, 2010, 07:55:52 pm »
WriteInfo is wrong. i know that, i just dont know what kinda of variable to set it to.

Okay, surely I can't know that either... can I?

Its Not this thats wrong:
Code: [Select]
IF FindFirst('*',FAanyFile,FADirectory)=0ThenIts That it expected some thing from the Info TSearchREC; and i cant fix it.

I say it is.

I Suspect its Cuz of my First With Declaration. got the compiler confused..

You can try uncofusing the compiler by removing "with" and putting the prefix "RDirCon." everywhere where needed. I say it will still be confused.

Then you can try what I suggested.
Or wait for Bart.

captian jaster

  • Guest
Re: My ReturnDirContents Code.. need your help on this one guys...
« Reply #4 on: April 26, 2010, 09:45:43 pm »
Dood. i did change the
Code: [Select]
IF FindFirst('*',FAanyFile,FADirectory)=0Then to the way you said.. the same error came up....
If any one can help... What kind of variable can i set write info to?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9869
  • Debugger - SynEdit - and more
    • wiki
Re: My ReturnDirContents Code.. need your help on this one guys...
« Reply #5 on: April 26, 2010, 09:55:40 pm »
Quote
FFU.pas(59,28) Fatal: Syntax error, ";" expected but ":" found
Look at this line:
Code: [Select]
         WriteInfo := Name:40,Size:15;
You declared WriteInfo as string, so on the right side of assignment, you must provide a string. This should probably be (enclosed in quotes):
Code: [Select]
         WriteInfo := 'Name:40,Size:15';

WriteInfo is wrong. i know that, i just dont know what kinda of variable to set it to. Its not that im writing Name:40,Size:15
into the console. im trying to work with the FindClose Name And Size Vars... This Is Difficult... Heres What i worked off of..
http://www.freepascal.org/docs-html/rtl/sysutils/findfirst.html

"i just dont know what kinda of variable"

This statement sounds to me like you don't actually have any idea what
  Name:40,Size:15
in a writeln statement does?

You can find the explanation here:
  http://www.delphibasics.co.uk/RTL.asp?Name=WriteLn
I do highly recommend that page.

Once you have read that, I guess you will find that :40 does not make any sense in your case, since you want to store the data (so no alignment needed for multi line output).

As for the  answer of your question: 2 variables or 1 record (String and Integer)

« Last Edit: April 26, 2010, 09:57:16 pm by Martin_fr »

captian jaster

  • Guest
Re: My ReturnDirContents Code.. need your help on this one guys...
« Reply #6 on: April 26, 2010, 11:00:32 pm »
I praise for you for the explanation. Ill be re-writing it later..

 

TinyPortal © 2005-2018