如何把一个文本列表添加到 TListBox 并避免重复项 - 回复 "xnlxw" 的问题


unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    procedure FormCreate(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
const
  FilePath = 'c:\temp\Test.txt';
var
  List: TStringList;
begin
  List := TStringList.Create;
  List.Sorted := True;
  List.Duplicates := dupIgnore;
  List.LoadFromFile(FilePath);
  ListBox1.Items.Assign(List);
  List.Free;
end;

end.

 
 
 
 
 

 

 
  

你可能感兴趣的:(如何把一个文本列表添加到 TListBox 并避免重复项 - 回复 "xnlxw" 的问题)