January 5th, 2014, 04:32 AM
Loose fileds values
I have an application where user selects different files and then I have to loads values stored in those files in different windows.
I tried to clone then window where I have to show values as many times as the number of files and then to load values.
This is what happens.
The user select two files. I show a new window and load values from the first file. Then I clone the window and load values from the second file.
As I move the first active window I see the values of one file in both two windows. If I select the second window the values of the second file are loaded. The problem is when I come back to the first window. Both windows shows values of the second file.
I also tried to not clone window at runtime but to duplicate the window before building application so I have to different windows to use to loads values. I have the same problem when focusing windows.
How could I solve this problem?
January 6th, 2014, 02:30 PM
What do you mean when you say you clone the window?
Simply "create" a form for every file you want to read values from. You can define a new constructor for the form, passing it the filepath and filename you want to read from.
so if the form that you want to create to read the values from the file is called "ReadValuesForm" then after you define the form, add a new constructor and a private string field to hold the path/filename
then write your new constructor
TReadValuesForm = class(TForm)
constructor CreateWithFileName(AOwner: TComponent; const File_Name: String);
Now, choose the appropriate method for your form, where you can read the file that is identified by the form's variable FileName.
constructor TReadValuesForm.CreateWithFileName(AOwner: TComponent; const File_Name: String);
FileName := File_Name;
then from the calling form, where you select the files, create the form with your constructor, passing it the file name (also, add the above's unit to the uses clause).
procedure TReadValuesForm.<YourSelectedMethod>(Sender: TObject);
//Read in the file from file named FileName
//if the file is a text file, you can read it into a Stringlist.
SL := TStringList.Create;
for I := 0 to SL.Count - 1 do
//process your file line by line.
//Current Line is SL[I];
uses ..., <ReadFromValuesUnitName>;
for I := 0 to <NumberOfFilesSelected - 1> do
ReadValuesForm:= TReadValuesForm.CreateWithFileName(Self, <TheFileName>);
January 9th, 2014, 03:51 AM
It was my fault. I was using OnActivate event to load values.
This way every time I clicked on a form, the procedure was called loading the last file.
I never used constructor but it seems to me your solution is better than mine. I'll try to use it.
January 9th, 2014, 08:27 AM
Just one more note, remember to remove this 2nd form from the Auto Create List - With the project loaded in the IDE, select Project|Options menu item, select Forms from the Left pane, and move the form from the Auto Create Forms List to the Available Forms List.
Originally Posted by Petabyt3