Einzelnen Beitrag anzeigen

JimmyB

Registriert seit: 20. Mär 2022
26 Beiträge
 
#6

AW: Text in Checkbox oder Label anzeigen

  Alt 25. Sep 2022, 09:39
Hallo Uwe,

dein Code ist ja bestechend kurz.
Ich habe diesen ausprobiert, allerdings scheint die Schleife nicht zu laufen.
Es wird nur die letzte Zeile aus der Textdatei in der Caption der ersten Checkbox angezeigt.



procedure TForm1.Button1Click(Sender: TObject);

// Step 1: Declare Varibales
var myfile : textfile;
sLine : string;
i : integer;
begin
//Check if the file exists
if not FileExists ('Fragen.txt') then
begin
showmessage ('Die Datei mit den Fragen kann nicht gefunden werden!');
Exit;
end;

//Step 3: Assign file to our variable
AssignFile( myfile, 'Fragen.txt');
i := 1;
//Step 4: Put the pointer at the top the textfile
reset (myfile);

//Step 5: Loop through our textfile
//Hint: Must use BEGIN and END

while NOT eof (myfile) do
begin
//Step 6: Get each line of text file into string variable
readln (myfile, sLine);

// work with sLine

(FindComponent('Checkbox' + IntToStr(i)) as TCheckBox).Caption := sLine;
Inc(i);
redDisplay.Lines.Add( sLine);
end; // end of while loop

//Step 7: Close our association
Closefile ( myfile);

end;

end.

vg JimmyB
  Mit Zitat antworten Zitat