Einzelnen Beitrag anzeigen

Benutzerbild von blawen
blawen

Registriert seit: 30. Nov 2003
Ort: Luterbach (CH)
654 Beiträge
 
Delphi 12 Athens
 
#3

AW: Habe ich Knöpfe auf den Augen - Please help

  Alt 17. Apr 2022, 22:20
Wie Andreas schon geschrieben hat, wird Dein Quellcode mit den Delphi-Tags deutlich lesbarer.

Du Rufst "RedDisplay" auf, aber diese ist nicht deklariert.
Was für eine Komponente ist dies?

Ich vermute mal, dass hier RichEdit1.Lines.Add(sLine) stehen sollte.

Willst Du die Datei "teams.txt" wirklich ohne Pfadangabe suchen/auslesen lassen?
Hier ist der Ärger vorprogrammiert.

Statt if FileExists( 'teams.txt' ) = FALSE solltest Du
 if NOT FileExists( 'teams.txt' ) verwenden.

Delphi-Quellcode:
unit Unit3;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ComCtrls;

type
  TForm3 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    RichEdit1: TRichEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form3: TForm3;

implementation

{$R *.dfm}

procedure TForm3.Button1Click(Sender: TObject);
  // Step 1 - Declare Variables
var
  myfile : textfile;
  sLine : string;

begin
  // Step 2 - check if filename exist
  if FileExists( 'teams.txt' ) = FALSE
  then begin
    showmessage('Datei nicht gefunden') ;
    exit;
  end;
  
  showmessage('Die Datei ist vorhanden') ;
  // Step 3 - Assign File to our variable
  AssignFile( myfile, 'teams.txt');

  //Step 4: Put the pointer to the top of the textfile
  Reset( myfile );

  //Step 5: Loop through our textfile
  //You must use BEGIN and END
  while NOT eof(myfile) do
  begin
    //Step 6: Get each line of text file into string varibale
    readln(myfile , sLine);
    redDisplay.Lines.Add( sLine) ;

  end; //end of our while loop

  //Step 7: Close the association with the text file
  closefile (myfile);
end;

end.
Roland

Geändert von blawen (17. Apr 2022 um 22:28 Uhr)
  Mit Zitat antworten Zitat