Einzelnen Beitrag anzeigen

Benutzerbild von FriedrichAT
FriedrichAT

Registriert seit: 25. Mai 2019
Ort: Wien
29 Beiträge
 
Delphi 11 Alexandria
 
#4

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

  Alt 17. Apr 2022, 23:20
Hallo
Zitat:
Habe ich Knöpfe auf den Augen - Please help
Copy -> Paste und nicht lesen bzw. -> F9 ist dein Freund

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
  TForm1 = class(TForm)
    Button1: TButton;
    RichEdit1: TRichEdit;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private { Private-Deklarationen }
  public { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

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

begin
  // Step 2 - check if filename exist
  if not FileExists( 'teams.txt' ) then
  begin
    ShowMessage('Datei nicht gefunden') ;
    exit;
  end
  else
    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);
    RichEdit1.Lines.Add( sLine) ;
  end; //end of our while loop

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

// oder...
procedure TForm1.Button2Click(Sender: TObject);
var SL: TStrings;
begin
  if not FileExists( 'teams.txt' ) then
  begin
    ShowMessage('Datei nicht gefunden') ;
    exit;
  end
  else
  begin
    ShowMessage('Die Datei ist vorhanden') ;
    SL:= TStringList.Create;
    try
      SL.LoadFromFile('teams.txt');
      RichEdit1.Text:= SL.Text;
    finally
      SL.Free;
    end;
  end;
end;

initialization
  ReportMemoryLeaksOnShutdown:= True;
end.
Friedrich
  Mit Zitat antworten Zitat