fengche1915 2015-09-03 13:58 采纳率: 0%
浏览 1383

为何我加入数据到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.

  • 写回答

1条回答 默认 最新

  • threenewbee 2015-09-03 14:04
    关注

    和tlist没有关系,应该是你的
    Readln(F,str);
    str = Utf8ToAnsi(str); //加上
    Memo_Text.Lines.Add(str);
    没有指定正确的编码

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器