Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Algorithmen, Datenstrukturen und Klassendesign (https://www.delphipraxis.net/78-algorithmen-datenstrukturen-und-klassendesign/)
-   -   Habe ich Knöpfe auf den Augen - Please help (https://www.delphipraxis.net/210391-habe-ich-knoepfe-auf-den-augen-please-help.html)

JimmyB 17. Apr 2022 21:42

Habe ich Knöpfe auf den Augen - Please help
 
Hallo Leute,

ich werde wahnsinnig. Ein einfacher Code, aber bekomme einen Fehler und weiß nicht woran es liegt. Beim Starten kommt die Meldung bei 10.4
[dcc32 Fehler] Unit3.pas(53): E2003 Undeklarierter Bezeichner: 'redDisplay'
[dcc32 Fehler] Unit3.pas(53): E2066 Operator oder Semikolon fehlt
[dcc32 Fataler Fehler] Project2.dpr(5): F2063 Verwendete Unit 'Unit3.pas' kann nicht compiliert werden
Misslungen
Verstrichene Zeit: 00:00:00.5

vg JimmyB


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.

Andreas13 17. Apr 2022 22:08

AW: Habe ich Knöpfe auf den Augen - Please help
 
Hallo JimmyB,
Du kannst Deinen Quellcode etwas übersichtlicher formatieren, wenn Du das Delphi-Symbol (= gelber Helm mit dem roten Kamm) vom Menü direkt über dem Editorfenster benutzt. Alternaiv dazu kannst Du den Quellcode zwischen [DELPHI] und [/DELPHI] setzt.

Oder für neutrale Fälle als einfachen Code mit dem Symbol gleich links daneben (= auf weißem Blatt blaue eckige Klammern <>). Das geht übrigens auch nachträglich, wenn Du Deinen ersten Beitrag editierst.

Dann ist es auch für uns einfacher, Dir gezielt zu helfen. :-D

Gruß, Andreas

blawen 17. Apr 2022 22:20

AW: Habe ich Knöpfe auf den Augen - Please help
 
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
Delphi-Quellcode:
RichEdit1.Lines.Add(sLine)
stehen sollte.

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

Statt
Delphi-Quellcode:
if FileExists( 'teams.txt' ) = FALSE
solltest Du
Delphi-Quellcode:
 if NOT FileExists( 'teams.txt' )
verwenden.

Zitat:

Zitat von JimmyB (Beitrag 1504696)
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.


FriedrichAT 17. Apr 2022 23:20

AW: Habe ich Knöpfe auf den Augen - Please help
 
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.

JimmyB 18. Apr 2022 17:35

AW: Habe ich Knöpfe auf den Augen - Please help
 
Hallo FriedrichAT, hallo blawen,

@FriedrichAT
Ich kenne mich in der Delphi Umgebung wenig aus und habe auch die Delphi Tags bis jetzt noch nicht gefunden.
Sorry wenn es unübersichtlich lesbar war.
Insgesamt bin ich davon augegangen, dass der Code so einfach ist, dass es machbar ist.

@blawen,
Du hast die richtige Frage gestellt. Was ist denn diese Komponente "redDisplay"? Da bin ich einem Youtube Video gefolgt, die hier die Richtext Komponente mit anderem Namen versehen hatte.
Das Programm läuft jetzt!

Vielen Dank euch beiden und wirklich sorry, wenn meine Fragen und Material zur Beantwortung nicht gut waren. Ich bin echt am Anfang und schaue, dass ich mit den vielen Tipps so langsam in die, wie ich finde, klasse Delphi Umgebung reinkomme.

Beste Grüße und schönen restlichen sonnigen Ostermontag
JimmyB

mytbo 18. Apr 2022 19:21

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

Zitat von JimmyB (Beitrag 1504718)
Ich kenne mich in der Delphi Umgebung wenig aus und habe auch die Delphi Tags bis jetzt noch nicht gefunden.

Gemeint war hier der Forum Editor. Die Tags werden eingefügt, wenn du den Button mit dem Helm Icon drückst, oder die Tags direkt in den Editor schreibst:
Code:
[DELPHI]
... Delphi Quelltext
[/DELPHI]
Bis bald...
Thomas


Alle Zeitangaben in WEZ +1. Es ist jetzt 00:13 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz