Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

TStringList

Posted on 2003-11-07
6
Medium Priority
?
1,265 Views
Last Modified: 2008-02-01
I am trying to read two lines from a text file into separate Edit fields  on a form with one button, so that when i click the button the lines are loaded into the fields.  So for example the contents of the text files are  

Green
Black

When i press the button i would like "green" to be loaded to the first Edit box and Black to be loaded into the second Edit Box. I have written the following code which i could not get to work, i get many compiler errors so i am guessing it is not very correct

implementation

{$R *.xfm}

procedure ReadFromFile(Edit1 :TEdit);

TForm1.ButtonLoadClick(Sender :TObject);

var
sl: TStringList;
begin
sl :=TStringList.Create;
sl.LoadFromFile('/home/user/test.txt');
Edit1.Text := sl[0]
Edit2.Text := sl[1]
sl.Destroy;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
ReadFromFile(Edit1.Text);
ReadFromFile(Edit2.Text);
end;

end.
0
Comment
Question by:itektas
  • 3
  • 3
6 Comments
 
LVL 12

Expert Comment

by:andrewjb
ID: 9702860
OK.

Get rid of the line TForm1.ButtonLoadClick( Sender : TObject )

in the 'uses' bit

where it says something like

TMyForm = class(TForm)
private:
 

add :

procedure ReadFromFile;

then change the implementation bit to:


procedure ReadFromFile;
var
sl: TStringList;
begin
sl :=TStringList.Create;
sl.LoadFromFile('/home/user/test.txt');
Edit1.Text := sl[0]
Edit2.Text := sl[1]
sl.Free;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
ReadFromFile;
end;

I think.
0
 

Author Comment

by:itektas
ID: 9703041
ok i have changed to the following but it doesnt seem to work yet, when compiling it says there are many errors, such as

[Error] Unit1.pas(34): Undeclared identifier: 'Edit1'
[Error] Unit1.pas(34): '(' expected but ':=' found
[Error] Unit1.pas(35): Missing operator or semicolon
[Error] Unit1.pas(35): '(' expected but ':=' found
[Error] Unit1.pas(36): Missing operator or semicolon
[Error] Unit1.pas(37): '.' expected but ';' found
[Error] Unit1.pas(14): Unsatisfied forward or external declaration: 'TForm1.ReadFromFile'

  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Button1: TButton;
    procedure ReadFromFile;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.xfm}

var
sl: TStringList;
begin
sl :=TStringList.Create;
sl.LoadFromFile('/home/user/test.txt');
Edit1.Text := sl[0]
Edit2.Text := sl[1]
sl.Free;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
ReadFromFile;
end;
end.


0
 

Author Comment

by:itektas
ID: 9703052
I forgot to include it in my previous comment but i did actually include "procedure ReadFromFile;" in the beginning of the implementation; thanks
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 12

Expert Comment

by:andrewjb
ID: 9703084
Needs to be

procedure TForm1.ReadFromFile;

within the implementation section

The function is part of the 'TForm1' class
0
 
LVL 12

Accepted Solution

by:
andrewjb earned 80 total points
ID: 9703089
and you need a ; after s[0] and s[1]
0
 

Author Comment

by:itektas
ID: 9703137
Excellent! Compiles fine now , thanks a lot
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question