Home > Back-end >  The conditions of the simple select statement strange problems
The conditions of the simple select statement strange problems

Time:10-17

I array variable can save file, but read back the second, four groups of variables all of 0,
Procedure TForm1. Button1Click (Sender: TObject);
Var
MF: TStringList;
The begin
MF:=TStringList. Create;
Try
For I:=1 to 20 do
MF. The Add (inttostr (wjpx0 [I]));
For I:=1 to 20 do
MF. The Add (inttostr (xjpx0 [I]));
For I:=1 to 20 do
MF. The Add (inttostr (sjpx0 [I]));
For I:=1 to 6 do
MF. The Add (inttostr (dppx0 [I]));
MF. SaveToFile (' ABC '+'. TXT ");
The finally
MF. Free;
end;

Procedure TForm1. Button2Click (Sender: TObject);
Var
MF: TStrings;
The begin
If Opendialog1. Execute then begin
MF:=TStringList. Create;
Try
MF. LoadFromFile (opendialog1. Filename);
//icount:=MF. Count;
For I:=0 to 64 do begin
J:=strtoint (MF) strings [I]);
If I in 19] [0.. then
Wjpx0: [I + 1]=j
Else if I in [39] 20.. then
Xjpx0: [I + 1]=j
Else if I [40.. in 59] then
Sjpx0: [I + 1]=j
Else if I [60.. 64] then in
end;
The finally
MF. Free;
end; end;
end;

This statement used one thousand times, the question how to tracking can't find where the problem is?
Mystery, please help me to look at,

CodePudding user response:

Tracking found that should be assigned to a second set of array variable value is assigned to all of the third set of variables,
I changed computer test, the question remains, is not a system problem, should still code problem,

CodePudding user response:

Open file look not to know, in addition of array is how you define?

Save in the array subscript is 1.. 20
Behind the reading assignment, such as xjpx0, is 21.. 40, not crossing the line?

CodePudding user response:

On the top floor

CodePudding user response:

Var
Form1: TForm1;
Dppx0: array [6] 1.. of Integer;
Wjpx0 xjpx0, sjpx0: array [20] 1.. of Integer;
I, j, aa: integer;

CodePudding user response:

Sweat,, so you cross a line

CodePudding user response:

2 floor said is right, but I changed to
Procedure TForm1. Button2Click (Sender: TObject);
Var
MF: TStrings;
The begin
If Opendialog1. Execute then begin
MF:=TStringList. Create;
Try
MF. LoadFromFile (opendialog1. Filename);
//icount:=MF. Count;
For I:=0 to 64 do begin
J:=strtoint (MF) strings [I]);
If I in 19] [0.. then
Wjpx0: [I + 1]=j
Else if I in [39] 20.. then
Xjpx0 + 1-20] [I:=j
Else if I [40.. in 59] then
Sjpx0 + 1 to 40 [I] :=j
Else if I [60.. 64] then in
+ 1 to 60 sjpx0 [I] :=j
end;
The finally
MF. Free;
end; end;
end;
Also not line!

CodePudding user response:

Why you MF definition for TStrings use TStringList. Create?

CodePudding user response:

Back upstairs, TStrings has a virtual function, so use subclasses TStringList. Create

CodePudding user response:

The key part for this try,
For I:=0 to 64 do begin
J:=strtoint (MF) strings [I]);
In case of I
0.. 19: wjpx0: [I + 1]=j;
20.. 39: xjpx0 + 1-20] [I:=j;
40.. 59: sjpx0 + 1 to 40 [I] :=j;
60.. 64: dppx0 + 1 to 60 [I] :=j;
end;
end;

CodePudding user response:

Since you use TStringList. Create, as it directly to define a TStringList, and open the file you have seen? Data for really? The problem not only in the reading part

CodePudding user response:

9/f, form of expression is clear, much clearer,

To crossing the line, it is all the more, now that save on MF. SaveToFile (' ABC '+'. TXT "); Direct MF. When I was reading LoadFromFile (' ABC '+'. TXT '); Well, not to get dizzy, use the dialog to select file is wrong,

CodePudding user response:

LZ, you looked at the file

CodePudding user response:

Written to the file before, Numbers to add the separator, such as commas, Spaces, newlines,
Read back, through the separator to different data, and filter separator,

CodePudding user response:

Two Numbers, otherwise will be merged into one, you will lose data
  • Related