为何我加入数据到TList之后读取出来是乱码,代码如下

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

Type
PL=^TL;
TL=record
str:string[20];
End;

type
TForm1 = class(TForm)
Button_OpenFile: TButton;
Memo_Text: TMemo;
OpenDialog1: TOpenDialog;
Button1: TButton;
Memo1: TMemo;
Button2: TButton;
procedure Button_OpenFileClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
CurrentDir:string;
List1:TList;
implementation

{$R *.dfm}

procedure TForm1.Button_OpenFileClick(Sender: TObject);
Var
F:Textfile;
str:string;
Filename:string;
p:PL;
begin
OpenDialog1.InitialDir:=CurrentDir;
OpenDialog1.Filter:='文本文件(*.txt)|*.txt';;
Memo_Text.Clear;

if OpenDialog1.Execute then { Display Open dialog box }
begin
AssignFile(F,OpenDialog1.FileName); { File selected in dialog box }
Reset(F);
while not eof(F) do
begin
Readln(F,str);
Memo_Text.Lines.Add(str);
new(p);
p.str:=str;
//showmessage(str);
List1.Add(p);
Dispose(p);
end;

//Memo_Text.Lines.LoadFromFile(OpenDialog1.FileName);
CloseFile(F);

end;
//str:-
showmessage(inttostr(List1.Count ));

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
CurrentDir:=GetCurrentDir();
List1:=TList.Create;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
List1.Clear;
List1.Free;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
i,j:integer;
str:string[20];
PL1,PL2:PL;
begin
Memo1.Clear;
for i:=0 to List1.Count-1 do
begin
str:='';
//new(PL1);
PL1:=List1.Items[i];

//showmessage(str);
for j:=i+1 to List1.Count-1 do
begin

  //new(PL2);
  PL2:=List1.Items[j];
  if PL2.str=PL1.str then
  begin
    str:=PL1.str+'*'+inttostr(i)+inttostr(j)+'*'+PL2.str;
    Memo1.Lines.Add(str);
    exit;
  end;

end;

end;

end;

end.

查看全部
fengche1915
fengche1915
2015/09/03 13:58
  • 代码
  • 乱码
  • 点赞
  • 收藏
  • 回答
    私信

1个回复