Recent

Author Topic: Compiler errors  (Read 1709 times)

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Compiler errors
« on: January 21, 2018, 06:46:28 pm »
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
    Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
type
    { TForm1 }
    TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
    private

    public

    end;

var
    Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
     var
      ListOfFiles: TStringList;
      ListOfFolders: TStringList;
      Attributes: Integer;
      Message: string;
      cbx1 : integer;
    begin
      cbx1 :=1;
      Attributes := faReadOnly;
      if cbx1 = 1 then
        Attributes := Attributes or faHidden;
      ListOfFiles := TStringList.Create;
      try
        FileUtil.FindAllFiles(ListOfFiles, edtDirectory.Text, '*', False, Attributes);
        ListOfFiles.Insert(0, Format('The directory contains %d file(s).', [ListOfFiles.Count]));
        Message := ListOfFiles.Text;
      finally
        ListOfFiles.Free;
      end;
      if cbx1 = 1 then
      begin
        ListOfFolders := TStringList.Create;
        try
          FileUtil.FindAllDirectories(ListOfFolders, edtDirectory.Text, False);
          ListOfFolders.Insert(0, Format('And %d folders(s).', [ListOfFolders.Count]));
          Message := Message + ListOfFolders.Text;
        finally
          ListOfFolders.Free;
        end;
      end;
      ShowMessage(Message)
end;

end.
Compile Project, Target: project1.exe: Exit code 1, Errors: 2, Warnings: 1
unit1.pas(44,45) Warning: Symbol "faHidden" is not portable
unit1.pas(47,44) Error: Identifier not found "edtDirectory"
unit1.pas(57,54) Error: Identifier not found "edtDirectory"

Can't find edtDirectory. Is this by any chance a listbox on the form named editDirectory?

The procedure was supplied by Aserge.
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Compiler errors
« Reply #1 on: January 21, 2018, 07:04:46 pm »
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2.      var
  3.       ListOfFiles: TStringList;
  4.       ListOfFolders: TStringList;
  5.       Attributes: Integer;
  6.       Message: string;
  7.       cbx1 : integer;
  8.     begin
  9.       cbx1 :=1;
  10.       Attributes := faReadOnly;
  11.       if cbx1 = 1 then
  12.         Attributes := Attributes or faHidden;
  13.       ListOfFiles := TStringList.Create;
  14.       try
  15.         FileUtil.FindAllFiles(ListOfFiles, edtDirectory.Text, '*', False, Attributes);
  16.         ListOfFiles.Insert(0, Format('The directory contains %d file(s).', [ListOfFiles.Count]));
  17.         Message := ListOfFiles.Text;
  18.       finally
  19.         ListOfFiles.Free;
  20.       end;
  21.       if cbx1 = 1 then
  22.       begin
  23.         ListOfFolders := TStringList.Create;
  24.         try
  25.           FileUtil.FindAllDirectories(ListOfFolders, edtDirectory.Text, False);
  26.           ListOfFolders.Insert(0, Format('And %d folders(s).', [ListOfFolders.Count]));
  27.           Message := Message + ListOfFolders.Text;
  28.         finally
  29.           ListOfFolders.Free;
  30.         end;
  31.       end;
  32.       ShowMessage(Message)
  33. end;
  34.  
Compile Project, Target: project1.exe: Exit code 1, Errors: 2, Warnings: 1
unit1.pas(44,45) Warning: Symbol "faHidden" is not portable
unit1.pas(47,44) Error: Identifier not found "edtDirectory"
unit1.pas(57,54) Error: Identifier not found "edtDirectory"

Can't find edtDirectory. Is this by any chance a listbox on the form named editDirectory?

The procedure was supplied by Aserge.
drop a simple edit control on the form and change its name to edtDirectory from the inspector. make sure it has an acceptable value before clicking that button.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Handoko

  • Hero Member
  • *****
  • Posts: 5151
  • My goal: build my own game engine using Lazarus
Re: Compiler errors
« Reply #2 on: January 21, 2018, 07:10:49 pm »
@JLWest

You don't need to start a new thread. I answered it on the 'original' thread:

https://forum.lazarus.freepascal.org/index.php/topic,39746.msg273829.html#msg273829

Handoko

  • Hero Member
  • *****
  • Posts: 5151
  • My goal: build my own game engine using Lazarus
Re: Compiler errors
« Reply #3 on: January 21, 2018, 07:26:32 pm »
Copy-pasting code usually won't work correctly on programming. You need to understand that code and make necessary adaptations. For example, to combine ASerge's code with mine, you still need to:

Remove cbx1 :=1; (on line #9 on taazz's post reply #1)

Change cbx1 with my cbxHidden. But because cbx1 is an Integer but cbxHidden is a TCheckBox, so you need to make necessary adaptation.

Wow, programming sounds difficult. :o
You push yourself too far, in less than a week, you tried to learn too much things. :D

 

TinyPortal © 2005-2018